Hackster is hosting Hackster Holidays, Ep. 7: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Friday!Stream Hackster Holidays, Ep. 7 on Friday!
Tyler StognerGrayson Bennett
Published

Button-Controlled Door Lock (MEGR 3171 Fall 2017)

The days of the traditional lock-and-key door locks are a thing of the past with RF-controlled door locks at the touch of a button!

BeginnerFull instructions provided1,158
Button-Controlled Door Lock (MEGR 3171 Fall 2017)

Things used in this project

Hardware components

Photon
Particle Photon
×2
Jumper wires (generic)
Jumper wires (generic)
×6
Adafruit Simple 315 MHz RF Receiver
×1
EMAX ES08A II servo
×1
Adafruit 2 Button 315 MHz RF Transmitter
×1

Story

Read more

Schematics

Photon 2

Circuit Diagram for Photon 2

Photon 1 (RF Receiver)

Code

Code for Photon 2

C/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 1

C/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

Tyler Stogner
1 project • 0 followers
Grayson Bennett
1 project • 0 followers

Comments