Charles Bounds and Andrew Kuhn
Published © GPL3+

MEGR 3171 Alexa Controlled Lights

Too lazy to get off the couch? "Alexa, turn on the lights."

IntermediateFull instructions provided10 hours214
MEGR 3171 Alexa Controlled Lights

Things used in this project

Hardware components

Wall Outlet
×2
Relay Module (Generic)
5 volt
×2
Extension cord
×2
Photon
Particle Photon
×2
Echo Dot
Amazon Alexa Echo Dot
×1
Maker Essentials - Mini Breadboards & Jumper Jerky
Pimoroni Maker Essentials - Mini Breadboards & Jumper Jerky
×1

Software apps and online services

Blynk
Blynk
Google Sheets
Google Sheets
Amazon Alexa service
IFTTT Amazon Alexa service

Hand tools and fabrication machines

Wire stripper
#2 philips head screwdriver

Story

Read more

Schematics

Wiring Diagram

This is the wiring diagram for both photons

Code

Living Room Lights

Arduino
This code is for the Photon controlling the living room lights. It is subscribed to the other photon and to the Alexa device and it also publishes data for the other Photon to receive and push to a live graph.
int relayPin = A0;

void setup() {
    
    pinMode(relayPin, OUTPUT); //Set the relay pin to output mode
    Particle.subscribe("livingroomlights", myHandler); //subscribes to the other photon and to alexa

}

void loop() {
    //Not Used Here

}

void myHandler(const char *event, const char *data) {
    
    if (strcmp(data,"0")==0) {
    // If the board is triggered by the other photon or alexa, turn off the relay
    digitalWrite(relayPin,HIGH); //HIGH is needed to turn the relay off
    
    Particle.publish("livingRoomData","0");  //publishes this data back to the other photon so that it can graph the data

    
  }
  else if (strcmp(data,"1")==0) {
    //If the control board is triggered by the other photon or alexa turn on the relay
    digitalWrite(relayPin,LOW); //Low turns the relay on
    
    Particle.publish("livingRoomData","1"); //publishes this data back to the other photon so that it can graph the data
   
  }

}

Kitchen Lights and Data Publishing

Arduino
This is the code used for the second photon in the kitchen which is used for the blynk control and to publish data
// This #include statement was automatically added by the Particle IDE.
#include <blynk.h>


int relaypin = A0;

int state = 1;

char blynkAuth[] = "8a742c76750644abacdcd2d499a2a8d9"; //sent from blynk app

void setup() {
    
    pinMode(relaypin, OUTPUT);
    
    pinMode(D7,OUTPUT); //just to add a visual 
    
    
    Particle.subscribe("kitchenlights", myHandler); //subscribe to the the IFTTT alexa statement
    Particle.subscribe("livingRoomData",myHandler2); //subscribe to the data coming from the other photon
    
    Blynk.begin(blynkAuth);
    

}

//Blynk Control
void loop() { //This is the code that will allow this photon to control the other photon with the blynk app on your phone
    //note that the blynk app will have a button that will directly conect to the relaypin and so there is no need for any code for that

     Blynk.run(); //Starts Blynk App Control
     
     int livButton = digitalRead(D7); //This Reads D7 so that Blynk can change d7 and trigger the lights
    
     
     if(state != 1) //Make sure that we arent just publishing data over and over again
     {
        if (livButton == HIGH){
             Particle.publish("livingroomlights","1"); //publish the data to the other photon to tell it to turn on
             state = 1;
         }
     }
     
     if(state != 0) //Make sure that we arent just publishing data over and over again
     {
        if (livButton == LOW) //If the blynk app as the button off then publish the command to turn off the other relay
        {
             Particle.publish("livingroomlights","0"); //publish the data to the other photon to tell it to turn off
             state = 0;
         } 
     }
}

//Kitchen Data
void myHandler(const char *event, const char *data) { //This event handles what happens when alexa triggers this photon
    
    if (strcmp(data,"0")==0) {
    digitalWrite(relaypin,HIGH); //HIGH is needed to turn the relay off
    Particle.publish("cloudDataK","0");//publishes data to the cloud of IFTTT to read and write to a google sheet
    
  }
  else if (strcmp(data,"1")==0) {
    digitalWrite(relaypin,LOW); //Low turns the relay on
    Particle.publish("cloudDataK","1");//publishes data to the cloud of IFTTT to read and write to a google sheet
   
  }

}

//Living room Data
void myHandler2(const char *event, const char *data) { //this one recieves data from the living room photon and then will publish it to be graphed
    
    if (strcmp(data,"0")==0) {
    // Publish that the living room is off
    Particle.publish("cloudDataLR","0");//publishes data to the cloud of IFTTT to read and write to a google sheet

   
    
  }
  else if (strcmp(data,"1")==0) {
    //Publish that the living room is on
    Particle.publish("cloudDataLR","1");//publishes data to the cloud of IFTTT to read and write to a google sheet
  }

}

Credits

Charles Bounds and Andrew Kuhn

Charles Bounds and Andrew Kuhn

1 project • 1 follower

Comments

Add projectSign up / Login