Things used in this project

Hardware components:
Photon new
Particle Photon
×2
11026 02
Jumper wires (generic)
×6
Adafruit Simple 315 MHz RF Receiver
×1
EMAX ES08A II servo
×1
Adafruit 2 Button 315 MHz RF Transmitter
×1

Schematics

Photon 2
Circuit Diagram for Photon 2
Img 0439 yw515gcrsf
Photon 1 (RF Receiver)
Photon breadboard h6elblgaip

Code

Code for Photon 2C/C++
The code for this photon controls the servo by moving the servo to pos1 when the unlock button is pressed and moving the servo to pos2 when the lock button is pressed.
Servo myservo;
int pos1=90; //servo position for light switch off
int pos2=0; //servo position for light switch on




void setup() {


myservo.attach(D0);//attatch servo pin to D0
Particle.subscribe("button_status", myHandler); //subscribe to 1st photon event
}

void loop() {}

void myHandler(const char *button_status, const char *data)
{
 

  if (strcmp(data,"on")==0) {
    // if your buddy's beam is intact, then turn your board LED off
    myservo.write(pos1);
  particle.publish("on")
  }
  else if (strcmp(data,"off")==0) {
    // if your buddy's beam is broken, turn your board LED on
   myservo.write(pos2);
  }
  else {
    // if the data is something else, don't do anything.
    // Really the data shouldn't be anything but those two listed above.
  }
}
Code for Photon 1C/C++
The code for Photon 1 reads pin D4 (the pin connected to the output of the receiver) and publishes and event with a short data string based on the condition of the pin. If the pin reads HIGH then it will publish the data string "on" (instructing Photon 2 to activate the servo). If the pin reads LOW, it will publish the data string "off" (instructing Photon 2 to "close").
int rfr = D4;
bool button_changed=false;
void setup()
{
  pinMode(rfr, INPUT_PULLDOWN); 
}
void loop()
{ if (digitalRead(rfr)==HIGH) { 
    Particle.publish("button_status","on", 60, PUBLIC);}
     
      else {
        Particle.publish("button_status","off", 60, PUBLIC);}
delay(1000);
    }

Credits

04c7a0414b3f43c329c1311bc8f9a8aa
Tyler Stogner
1 project • 0 followers
Contact
4ba36d2357c598660249042af3f607be
Grayson Bennett
1 project • 0 followers
Contact

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Add projectSign up / Login