Justin KeithCameron Marashi
Published © GPL3+

Let There Be Light! Voice Activated IOT Light Control System

With the help of two Particle Photon's, you can turn your light on and off using your own voice!

IntermediateShowcase (no instructions)2 hours1,334
Let There Be Light! Voice Activated IOT Light Control System

Things used in this project

Story

Read more

Schematics

Energy Usage

Plot of energy usage over time.

Circuitry

Code

Untitled file

C/C++
////////2nd photon with relay shield 

int digitalvalu;
int activate;
int questions(String command);
void setup() {
    pinMode(D1,OUTPUT);
    pinMode(A5,OUTPUT);
    pinMode(D0,OUTPUT);
    pinMode(A0,INPUT);
    
    Particle.variable("digitalvalu", &digitalvalu, INT);
    Particle.variable("Activate", &activate, INT);
    Particle.function("Questions", questions);
    Particle.function("Answers", ans);
    Particle.function("Why", why);
  
}

void loop() {
    digitalWrite(A5,HIGH);
    if (activate==1) {
        digitalvalu = digitalRead(A0);
    }    
    else if (activate==0){
            
        }
    
}    


// Button Light Activation Condition
int questions(String command) {
    digitalWrite(D0,HIGH);
     if (command=="on") {
        digitalWrite(D0,HIGH);
        activate==1;
        return 1;
    }   
    else if (command=="off") {
        digitalWrite(D0,LOW);
        activate==0;
        return 0;
    }
    else {
        return -1;
    }
}
// KILL COMMAND activates when trigger command is set on main photon
int why(String command) {
    digitalWrite(D0,LOW);
    
}

int ans(String command) {
    if (digitalvalu==1) {
        digitalWrite(D0,LOW);
        command=="off";
        return 1;
    }   
    else if (digitalvalu==0) {
        digitalWrite(D0,HIGH);
        command=="on";
        return 0;
    }
    
}


//////Photon with Microphone and Relay shield

int digitalvalue;
int count;
int var;

void setup() {
    //INITIALIZE
    pinMode(D1,OUTPUT);
    pinMode(D3,OUTPUT);
    pinMode(D7,OUTPUT);
    pinMode(D0,OUTPUT);
    pinMode(DAC,INPUT);
    
    Particle.variable("digitalvalue", &digitalvalue);
    Particle.variable("count", &count);
    Particle.variable("var", &var);
    Particle.function("digitalvalue",digitalvalueToggle);
}

void loop() {
    var = 0;
    digitalvalue = analogRead(DAC);
    digitalWrite(D7,HIGH);
    digitalWrite(D0,HIGH);
    //LIGHT ACTIVATION CONDITION
    if (digitalvalue> 2200){
        //Varriables that UPDATE when Light is on
        var = 1;
        digitalWrite(D1,LOW);
        Particle.publish("LED","on");
        //Thingspeak looks at this to graph
        count = 1 + count; //the delay and 1 where calulated by how much energy consumed with time from the lamp
        String temp = String(count);
        Particle.publish("temp", temp, PRIVATE);
    
        delay(45000);
        //OFF or continue condition
        if (digitalvalue< 2200){
        digitalWrite(D1,HIGH);
        }
    }
    else if (digitalvalue< 2200){
        digitalWrite(D1,HIGH);
        
    }
}    

int digitalvalueToggle(String command) {
    digitalWrite(D1,HIGH);
    Particle.publish("LED","off");
}

Credits

Justin Keith

Justin Keith

1 project • 0 followers
Cameron Marashi

Cameron Marashi

1 project • 0 followers

Comments