Daniel Spencer
Published © GPL3+

Workshop Remote Power Control

Remote switch for workshop power, with indicator, workshop temp monitoring, and automatic shutdown. Graphing through Google Docs.

IntermediateFull instructions provided2 hours740
Workshop Remote Power Control

Things used in this project

Hardware components

Photon
Particle Photon
×2
DHT22 Temperature Sensor
DHT22 Temperature Sensor
×1
Photo resistor
Photo resistor
×1
3 mm LED: Yellow
3 mm LED: Yellow
×2
RGB Diffused Common Cathode
RGB Diffused Common Cathode
×1
3 mm LED: Green
3 mm LED: Green
×2
IOT Switching Relay Power Strip
OpenBuilds IOT Switching Relay Power Strip
×1
Pushbutton Switch, Pushbutton
Pushbutton Switch, Pushbutton
×2
Jumper wires (generic)
Jumper wires (generic)
×1
Resistor 10k ohm
Resistor 10k ohm
×1
Resistor 330 ohm
Resistor 330 ohm
×3
Resistor 220 ohm
Resistor 220 ohm
×2

Software apps and online services

Maker service
IFTTT Maker service
Used to push notifications when workshop powers on and off.
Fritzing
Used to create
Google Sheets
Google Sheets
Used to chart data.

Hand tools and fabrication machines

Wire Stripper & Cutter, 32-20 AWG / 0.05-0.5mm² Solid & Stranded Wires
Wire Stripper & Cutter, 32-20 AWG / 0.05-0.5mm² Solid & Stranded Wires
Used to trim resistor and LED legs for neater breadboard, as well as jumpers.

Story

Read more

Schematics

Remote Controller

The Remote Control Circuit.

Workshop Controller

The circuit diagram for the workshop controller

Code

Remote Controller Code

Arduino
This publishes an event when the button is pressed to turn the workshop on or off remotely. It also displays the current workshop temperature.

NOTE: Replace "bwswitch", "DanielWorkshopTemperature", and "DanielWorkshopPower" with unique event names to ensure functionality.
#include "application.h"

int buttonState;

const int red=A1;//RGB LED Red pin
const int blue=A2;//RGB LED Blue Pin
const int green=D2;//Green LED
const int yellow=D3;//Yellow Workshop Power LED
const int buttonpin=D1;//Button

void wlight(const char *event, const char *data);
void wtemp(const char *event, const char *data);

void setup() {
    pinMode(red, OUTPUT);
    pinMode(blue, OUTPUT);
    pinMode(green, OUTPUT);
    pinMode(yellow, OUTPUT);
    pinMode(buttonpin, INPUT_PULLUP);
    
    Particle.subscribe("DanielWorkshopPower", wlight, ALL_DEVICES);
    Particle.subscribe("DanielWorkshopTemperature", wtemp, ALL_DEVICES);
}


void loop() {
    
    buttonState = digitalRead(buttonpin);
    
    if(buttonState == LOW){
        
        Particle.publish("bwswitch", "Press", 0, PUBLIC);
        delay(1000);
        
    }else{
        
    }
}

void wlight(const char *event, const char *data){
    
    if (strcmp(data,"On")==0) {
        digitalWrite(yellow, HIGH);
        delay(10);
    }
    else if (strcmp(data,"Off")==0) {
        digitalWrite(yellow, LOW);
        delay(10);
    }
    else {
        
    }
}

void wtemp(const char *event, const char *data){
    if(strcmp(data,"Hot")==0){
        digitalWrite(red, HIGH);
        digitalWrite(blue, LOW);
        digitalWrite(green, LOW);
    }else if(strcmp(data,"AC")==0){
        digitalWrite(red, HIGH);
        digitalWrite(blue, LOW);
        digitalWrite(green, HIGH);
    }else if(strcmp(data,"Comfortable")==0){
        digitalWrite(red, LOW);
        digitalWrite(blue, LOW);
        digitalWrite(green, HIGH);
    }else if(strcmp(data,"Heat")==0){
        digitalWrite(red, LOW);
        digitalWrite(blue, HIGH);
        digitalWrite(green, HIGH);
    }else if(strcmp(data,"Cold")==0){
        digitalWrite(red, LOW);
        digitalWrite(blue, HIGH);
        digitalWrite(green, LOW);
    }else{
        digitalWrite(red, HIGH);
        delay(100);
        digitalWrite(red, LOW);
        digitalWrite(blue, HIGH);
        delay(100);
        digitalWrite(blue, LOW);
        delay(100);
    }
}

Workshop Controller Code

Arduino
This drives the Workshop controller, and publishes the temperature and light level to the cloud.

NOTE: Replace event names with unique event names to ensure reliable functionality
No preview (download only).

Google Scripts script

JavaScript
This automatically harvests temperature and light data every ten minutes.
var device_ID = 'DEVICE_ID';
var access_token = 'AUTH_TOKEN';
var variables = ['Temperature','lightlevel'];
var checkLatestData = true;
var refreshTime = 60;

//  Select the active spreadsheet
var sheet = SpreadsheetApp.getActiveSheet();

//	Function to create a header
function showHeader()	{
	//	Clear the first row
	sheet.deleteRow(1);

	//	At first add the timestamp
	sheet.getRange(1,1).setValue('Timestamp');

	//	Loop through all the variables and add the names of them
	for (var i = 0; i < variables.length; i++) {
		sheet.getRange(1,2 + i).setValue(variables[i]);
	};

	if(checkLatestData) {
		sheet.getRange(1, 3 + variables.length).setValue('Timestamp');

		//	Loop through all the variables and add the names of them
		for (var i = 0; i < variables.length; i++) {
			sheet.getRange(1,4 + variables.length).setValue(variables[i]);
		};
	}

	collectData();
}

//	Function to show the latest data
function showLatestData(timestamp, results)	{
	//	At first add the timestamp
	sheet.getRange(2,3 + variables.length).setValue(timestamp);

	//	Loop through all the variables and add the names of them
	for (var i = 0; i < results.length; i++) {
		sheet.getRange(2,4 + variables.length).setValue(results[i]);
	};
}

//  Function to get and parse the JSON variable from the spark API
function getResponse(variable){
	var JSONResponse = UrlFetchApp.fetch("https://api.spark.io/v1/devices/" + device_ID + "/" + variable + "?access_token=" + access_token);
	
	var response = JSON.parse(JSONResponse.getContentText());
	return response.result;		
}

function collectData()  {
	//	Declare a result array
	var timestamp = new Date();
	var results = [timestamp];
	var resultsWithKey = [];

	//	Loop through the array with variables and get their content
	for (var i = 0; i < variables.length; i++) {

		//	Push the results in an array
		results.push(getResponse(variables[i]));
		resultsWithKey[variables[i]] = getResponse(variables[i]);
	};

	if(checkLatestData) showLatestData(timestamp, results)
	
	//  Add the responses to the spreadsheet
	sheet.appendRow(results);

	Utilities.sleep(refreshTime * 1000)
	collectData();
}

Credits

Daniel Spencer

Daniel Spencer

1 project • 0 followers
Thanks to John R McAlpine.

Comments