Software apps and online services

Story

Intro

Motion controlled lighting is an environmental way to conserve electricity and an excellent way to decrease your electricity bill. Many of us have busy lifestyles and can forget to turn the lights off, which means that the electrical meter keeps running our bill up, so if we run out of the house and forget to turn the lights off, you don't have to worry. Motion controlled lights are also good if you are worried about burglars coming into your home, as it will act as a deterrent because the light will turn on when the house is dark. These are also good for preventing your elderly grandparent from bumping into something on their way to the bathroom.

The Basics

This technology is fairly simple and straight forward. Two photons are connected to one another with a photo resistor on a breadboard. If light is not detected, the first photon lights up the LED on the breadboard. It takes a reading from the photo resistor, at which time, it determines if the light should be turned on or not. If the light should be turned on, the second photon communicates to the two channel at which time, the light turns on. With the same thought process, if the photo resistor has enough light, the photons will communicate to the channel relay shield to turn off. The photos are connected to one another with ThingSpeak. (Put ThingSpeak web address)

Geaph 2: Servet's Light Graph

Schematics

SCHEMATICS

Photo resistor setup

Code

Photon1

C/C++

This is the code for Photon1

#include"Adafruit_SSD1306.h"/*********************************************************************This is a library for our Monochrome OLEDs based on SSD1306 drivers Pick one up today in the adafruit shop! ------> http://www.adafruit.com/category/63_98These displays use SPI to communicate, 4 or 5 pins are required to interfaceAdafruit invests time and resources providing this open source code, please support Adafruit and open-source hardware by purchasing products from Adafruit!Written by Limor Fried/Ladyada for Adafruit Industries. BSD license, check license.txt for more informationAll text above, and the splash screen must be included in any redistribution*********************************************************************/#define OLED_DC A1 // Define the OLED display pins that are used#define OLED_CS A2#define OLED_RESET A0SYSTEM_THREAD(ENABLED);// Photon will crash and screen will not update quickly without thisconstStringkey="XXXXXXXXXXXXXXXX";// ThingSpeak Write API Keyintphotoresistor=D1;// Create names for Photon pins that are used for light sensingintpower=D0;Adafruit_SSD1306display(OLED_DC,OLED_RESET,OLED_CS);voidsetup(){display.begin(SSD1306_SWITCHCAPVCC);// Start the displaydisplay.display();// Displays the splash screendelay(2000);display.clearDisplay();// Clears the displaydisplay.display();Particle.subscribe("Photon2",light);// Subscribe to other PhotonParticle.subscribe("IFTTTapplet",GoogleNews);// Subscribe to IFTTT Google News RSS readerpinMode(photoresistor,INPUT);// Tell the Photon's pins for the photoresistor what to dopinMode(power,OUTPUT);digitalWrite(power,HIGH);}voidGoogleNews(constchar*event,constchar*data){display.clearDisplay();display.setTextSize(1);display.setTextColor(WHITE);display.setCursor(0,0);display.println(data);display.display();// Displays the feedback from IFTTT to the OLED display}voidlight(constchar*event,constchar*data){display.setTextSize(1);display.setTextColor(WHITE);display.setCursor(0,55);display.println("Light is:");display.setCursor(60,55);display.setTextColor(BLACK,WHITE);// Inverts the colors so the display will not write over itselfdisplay.println(data);display.display();// Displays the feedback from the other Photon to the OLED display}voidloop(){intcounts=0;while(counts<=30){// Publish data to the other Photon every second, but publish data to ThingSpeak every thirty secondsStringlight="ERROR";if(digitalRead(photoresistor)==1){// The light is on if the reading pin receives 3.3 voltslight=" ON ";}if(digitalRead(photoresistor)==0){// The light is of if the reading pin does not receive 3.3 voltslight=" OFF";}Particle.publish("Photon1",light);// Tell the other Photon if the light is on or offdelay(1000);counts=counts+1;}Stringlight="0";if(digitalRead(photoresistor)==1){// Determine if the light is on or off for the ThingSpeak live graphlight="1";}Particle.publish("thingSpeakWrite_","{ \"1\": \""+light+"\","+"\"k\": \""+key+"\" }",PRIVATE);// Publish light level to ThingSpeak}

Photon2

C/C++

This is the code for Photon2

#include"Adafruit_SSD1306.h"/*********************************************************************This is a library for our Monochrome OLEDs based on SSD1306 drivers Pick one up today in the adafruit shop! ------> http://www.adafruit.com/category/63_98These displays use SPI to communicate, 4 or 5 pins are required to interfaceAdafruit invests time and resources providing this open source code, please support Adafruit and open-source hardware by purchasing products from Adafruit!Written by Limor Fried/Ladyada for Adafruit Industries. BSD license, check license.txt for more informationAll text above, and the splash screen must be included in any redistribution*********************************************************************/#define OLED_DC A1 // Define the OLED display pins that are used#define OLED_CS A2#define OLED_RESET A0SYSTEM_THREAD(ENABLED);// Photon will crash and screen will not update quickly without thisconstStringkey="XXXXXXXXXXXXXXXX";// ThingSpeak Write API Keyintphotoresistor=D1;// Create names for Photon pins that are used for light sensingintpower=D0;Adafruit_SSD1306display(OLED_DC,OLED_RESET,OLED_CS);voidsetup(){display.begin(SSD1306_SWITCHCAPVCC);// Start the displaydisplay.display();// Displays the splash screendelay(2000);display.clearDisplay();// Clears the displaydisplay.display();Particle.subscribe("Photon1",light);// Subscribe to other PhotonParticle.subscribe("IFTTTapplet",GoogleNews);// Subscribe to IFTTT Google News RSS readerpinMode(photoresistor,INPUT);// Tell the Photon's pins for the photoresistor what to dopinMode(power,OUTPUT);digitalWrite(power,HIGH);}voidGoogleNews(constchar*event,constchar*data){display.clearDisplay();display.setTextSize(1);display.setTextColor(WHITE);display.setCursor(0,0);display.println(data);display.display();// Displays the feedback from IFTTT to the OLED display}voidlight(constchar*event,constchar*data){display.setTextSize(1);display.setTextColor(WHITE);display.setCursor(0,55);display.println("Light is:");display.setCursor(60,55);display.setTextColor(BLACK,WHITE);// Inverts the colors so the display will not write over itselfdisplay.println(data);display.display();// Displays the feedback from the other Photon to the OLED display}voidloop(){intcounts=0;while(counts<=30){// Publish data to the other Photon every second, but publish data to ThingSpeak every thirty secondsStringlight="ERROR";if(digitalRead(photoresistor)==1){// The light is on if the reading pin receives 3.3 voltslight=" ON ";}if(digitalRead(photoresistor)==0){// The light is of if the reading pin does not receive 3.3 voltslight=" OFF";}Particle.publish("Photon2",light);// Tell the other Photon if the light is on or offdelay(1000);counts=counts+1;}Stringlight="0";if(digitalRead(photoresistor)==1){// Determine if the light is on or off for the ThingSpeak live graphlight="1";}Particle.publish("thingSpeakWrite_","{ \"1\": \""+light+"\","+"\"k\": \""+key+"\" }",PRIVATE);// Publish light level to ThingSpeak}