JonD1988

Self Locking Door

Jul 6th, 2022
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Self Locking Door Code
  2. //Reference Ahmad Shamshiri for Robojax.com for Base Code
  3. //This is modified from Ahmad's Code on controlling a linear actuator
  4. //This self-locking door code will lock a deadbolt on a door after a certain set time once the Arduino has been turned on.
  5. //A limit switch will be tied into the power circuit for the Arduino.
  6. //There are no traditional inputs at this time for this code.
  7.  
  8. //Written by Jonathan DeWitt on 6/28/2021 Rev 0 of Code
  9.  
  10. const int relay1 = 2;
  11. const int relay2 = 3;
  12. int extdT = 1000; //Time the Linear Actuator is Extended (stands for extension delay time)
  13. int drcldT = 10000; //The time after the door closes (limit switch in power circuit closes) before the linear actuator locks the deadbolt (stands for door close delay time)
  14. int actactiondT = 2000; //Time given to actuator to fully extend and fully retract (stands for actuator action delay time)
  15.  
  16. void actuatorPull();
  17. void actuatorPush();
  18. void turnOFF();
  19.  
  20. void setup() {
  21.   // put your setup code here, to run once:
  22.  
  23.     pinMode(relay1, OUTPUT);// set pin as output for relay 1
  24.     pinMode(relay2, OUTPUT);// set pin as output for relay 2
  25.     Serial.begin(9600);// initialize serial monitor with 9600 baud
  26.        
  27.     //Door Locking Sequence
  28.     delay(drcldT); //Prevents door locking sequence from occuring for a certain amount of time
  29.     actuatorPull(); //Extends the Linear Actuator - Locking the Deadbolt
  30.     delay(actactiondT); //Time needed to extend
  31.     delay(extdT); //Leaves the Linear Actuator Extended for a Certain Amount of Time
  32.    
  33.     actuatorPush(); //Retracts the Linar Actuator - So it doesn't interfere with the key
  34.     delay(actactiondT); //Time needed to retract
  35.     turnOFF(); //Turns the relays off
  36. }
  37.  
  38. void loop() {
  39.   // put your main code here, to run repeatedly:
  40.  
  41. }
  42.  
  43.  
  44. //Function Definitions - Functions Written by Robojax
  45.  
  46. void actuatorPush()
  47. {
  48.    // Robojax Actuator code https://youtu.be/_bkNOyPElOo
  49.     digitalWrite(relay1, LOW);// turn relay 1 ON
  50.     digitalWrite(relay2, HIGH);// turn relay 2 OFF  
  51.  
  52. }//actuatorPush()
  53.  
  54. void actuatorPull()
  55. {
  56.    // Robojax Actuator code https://youtu.be/_bkNOyPElOo
  57.     digitalWrite(relay1, HIGH);// turn relay 1 OFF
  58.     digitalWrite(relay2, LOW);// turn relay 2 ON
  59.  
  60. }//actuatorPull()
  61.  
  62. void turnOFF()
  63. {
  64.    // Robojax Actuator code https://youtu.be/_bkNOyPElOo
  65.     digitalWrite(relay1, HIGH);// turn relay 1 OFF
  66.     digitalWrite(relay2, HIGH);// turn relay 2 OFF
  67.  
  68. }//turnOFF()
Add Comment
Please, Sign In to add comment