Emily BarnettKwok Leong Yan
Published

LED Light Strip Controlled by Amazon Alexa

UNC Charlotte - MEGR3171 Introduction to Instrumentation - Fall 2019 IOT Project

BeginnerFull instructions provided17 hours321
LED Light Strip Controlled by Amazon Alexa

Things used in this project

Hardware components

Argon
Particle Argon
×1
Echo Dot
Amazon Alexa Echo Dot
×1
Breadboard (generic)
Breadboard (generic)
×1
Multi-White USB LED Light Strip - 6.5ft
×1

Software apps and online services

ThingSpeak API
ThingSpeak API
Amazon Alexa service
IFTTT Amazon Alexa service

Story

Read more

Schematics

Light Command(Top) and Communication(Bottom) Schematic

Code

Communication

C/C++
void lights(const char *event, const char *data){
   
    Particle.publish("transmission", data, PRIVATE);
    delay(1000);
   
}
 
void responce(const char *event, const char *data){
   
    if (strcmp(data, "1")==0) {
   
        digitalWrite(D7, HIGH);
        delay(500); 
        digitalWrite(D7, LOW);
        delay(500);
   
    }
   
    else {}
   
}
 
 
void setup() {
   
    pinMode(D7, OUTPUT);
 
}
 
void loop() {
 
    Particle.subscribe("party_lights", lights, MY_DEVICES);
    delay(1000);
   // String test = String(1);
    //Particle.publish("party_lights", test, PRIVATE);
    //delay(2000);
    //Particle.publish("party_lights", "0", PRIVATE);
    //delay(2000);
    
    Particle.subscribe("response", responce, MY_DEVICES);
    delay(1000);
}

Light Control

C/C++
void trans(const char *event, const char *data){
    
     String responsevalue = String(1);
        Particle.publish("response", responsevalue, PRIVATE);
        delay(2000);
   
    if (strcmp(data, "0")==0) { // lights off
       
        analogWrite(A0, 255); //blue
        analogWrite(A1, 255); //green
        analogWrite(A2, 255); //red
        
    }
       
    else if (strcmp(data, "1")==0) { // lights on
       
        analogWrite(A0, 0); 
        analogWrite(A1, 0);  
        analogWrite(A2, 0); 
 
    }
        
    else if (strcmp(data, "2")==0) { // red
       
        analogWrite(A0, 255); 
        analogWrite(A1, 255); 
        analogWrite(A2, 0); 

    }
    else if (strcmp(data, "3")==0) { // orange
       
        analogWrite(A0, 255);
        analogWrite(A1, 127);
        analogWrite(A2, 0);

    }
     else if (strcmp(data, "4")==0) { // yellow
       
        analogWrite(A0, 255);
        analogWrite(A1, 0);
        analogWrite(A2, 0);
        

    }
     else if (strcmp(data, "5")==0) { // green
       
        analogWrite(A0, 255);
        analogWrite(A1, 0);
        analogWrite(A2, 255);
        
    }
     else if (strcmp(data, "6")==0) { // blue
       
        analogWrite(A0, 0);
        analogWrite(A1, 255);
        analogWrite(A2, 255);
        
    }
     else if (strcmp(data, "7")==0) { // aqua
       
        analogWrite(A0, 0);
        analogWrite(A1, 127);
        analogWrite(A2, 255);
        
    }
     else if (strcmp(data, "8")==0) { // purple
       
        analogWrite(A0, 0);
        analogWrite(A1, 255);
        analogWrite(A2, 0);
    
    }
     else if (strcmp(data, "9")==0) { // pink
       
        analogWrite(A0, 127);
        analogWrite(A1, 255);
        analogWrite(A2, 0);

    }
   
    else if (strcmp(data, "12")==0 || strcmp(data, "12") !=0)  {
       
        analogWrite(A0, 127);  // pink
        analogWrite(A1, 255);
        analogWrite(A2, 0);
        delay(1500);
       
        analogWrite(A0, 255); // off
        analogWrite(A1, 255);
        analogWrite(A2, 255);
        
        analogWrite(A0, 255); // green
        analogWrite(A1, 0);
        analogWrite(A2, 255);
        
        analogWrite(A0, 255);
        analogWrite(A1, 255); //off
        analogWrite(A2, 255);
        delay(1500);
        
        analogWrite(A0, 255);
        analogWrite(A1, 255); //red
        analogWrite(A2, 0);
        
        analogWrite(A0, 255);
        analogWrite(A1, 255); // off
        analogWrite(A2, 255);
        delay(1500);
        
        analogWrite(A0, 0);
        analogWrite(A1, 255);  // purple
        analogWrite(A2, 0);
        
        analogWrite(A0, 255); // off
        analogWrite(A1, 255);
        analogWrite(A2, 255);
        delay(1500);
        
        analogWrite(A0, 0); // blue
        analogWrite(A1, 255);
        analogWrite(A2, 255);
        
        analogWrite(A0, 255); //off
        analogWrite(A1, 255);
        analogWrite(A2, 255);
        delay(1500);
        
        analogWrite(A0, 255); //orange
        analogWrite(A1, 127);
        analogWrite(A2, 0);
        
        analogWrite(A0, 255); // off 
        analogWrite(A1, 255);
        analogWrite(A2, 255);
        delay(1500);
        
        analogWrite(A0, 0);
        analogWrite(A1, 255); // aqua
        analogWrite(A2, 127);
        
        analogWrite(A0, 255);
        analogWrite(A1, 255); // off
        analogWrite(A2, 255);
        delay(1500);
        
        analogWrite(A0, 255);
        analogWrite(A1, 0); // yellow
        analogWrite(A2, 0);
        
        analogWrite(A0, 255);
        analogWrite(A1, 255); // off
        analogWrite(A2, 255);
        delay(1500);
        
        analogWrite(A0, 0);
        analogWrite(A1, 0); // white
        analogWrite(A2, 0);
        
        analogWrite(A0, 255);
        analogWrite(A1, 255); // off
        analogWrite(A2, 255);
    }
    else {}

delay(1000);    
}
    
    
void setup() {
 
    pinMode(A0, OUTPUT);
    pinMode(A1, OUTPUT);
    pinMode(A2, OUTPUT);
 
}
 
void loop() {
 
    Particle.subscribe("transmission", trans, MY_DEVICES);
    delay(1000);
}

Credits

Emily Barnett

Emily Barnett

1 project • 3 followers
Kwok Leong Yan

Kwok Leong Yan

0 projects • 1 follower

Comments

Add projectSign up / Login