Ibrahim AwadallahHussain Almutawa
Published

Snap It

Turn the lights on and off with a finger snap.

IntermediateShowcase (no instructions)2,493
Snap It

Things used in this project

Story

Read more

Schematics

Schematics

Graphs

Code

Sound Sensor

C/C++
This code picks up the signal from the Sound Sensor, and sends it to the second photon which turns the LED light on and sends a signal back that turns on the LED light on the first sensor to enhance the 2 way communication between the 2 Photons.
int BigSound = D0;

int Message = D7;

void setup() {
pinMode(Message, OUTPUT);
  
    
    Particle.subscribe("Signal-recieved-999",someONEdidCLAP,"37001b000651353530373132");

}

void someONEdidCLAP(const char *event, const char *data)
{
  
   delay(1000);
  digitalWrite(Message, HIGH);

}

void loop() {
    if(digitalRead(BigSound)==HIGH){
        Particle.publish("sound-detected","Someone did clap",PUBLIC);
    }

}

LED light Code

C/C++
The code for the second photon that receives the signal from the first photon, turns the LED light on, and sends an acknowledgment signal back to the first photon.
int LED = D7;


void setup() {
    
    pinMode(LED, OUTPUT);
    digitalWrite(LED, LOW);
    
    Particle.subscribe("sound-detected",someONEdidCLAP,"370041001747343438323536");
    
    
}

void someONEdidCLAP(const char *event, const char *data)
{
  

digitalWrite(LED,HIGH);

}


void loop(){
   if(digitalRead(LED)==HIGH){
        Particle.publish("Signal-recieved-999","The light turned on",PUBLIC);
    }


}

Credits

Ibrahim Awadallah

Ibrahim Awadallah

1 project • 0 followers
Hussain Almutawa

Hussain Almutawa

1 project • 0 followers

Comments