Arduino Door Catcher


Arduino Nano
Magnetic Spring Module
MG995 Servo (3)
9G Servo
Magnet


  1. // Arduino Door Catcher
  2. // pkvi
  3. #include <VarSpeedServo.h>
  4. VarSpeedServo stopper;
  5. VarSpeedServo base;
  6. VarSpeedServo mid;
  7. VarSpeedServo handle;
  8. int pos;
  9. // Magnetic Sensor
  10. int hall = 2;
  11. int magnet;
  12. int state = 0;
  13. void setup() {
  14. Serial.begin(9600);
  15. pinMode(hall, INPUT);
  16. stopper.attach(3);
  17. stopper.write(140, 60, true);
  18. handle.attach(6);
  19. handle.write(95, 60, true);
  20. base.attach(4);
  21. mid.attach(5);
  22. base.write(180, 70);
  23. mid.write(25, 50);
  24. base.wait();
  25. mid.wait();
  26. }
  27. void loop() {
  28. // Did Door Open?
  29. magnet = digitalRead(hall);
  30. // Door Opened
  31. if (magnet == HIGH) {
  32. // Door Was Closed
  33. if (state == 0) {
  34. Serial.println("Active");
  35. delay(1000);
  36. engage();
  37. state = 1;
  38. // Door Was Open
  39. } else if (state == 1) {
  40. do_it();
  41. Serial.println("Deactived");
  42. delay(1000);
  43. state = 0;
  44. }
  45. }
  46. delay(47);
  47. }
  48. // Release Door Slide
  49. void engage() {
  50. stopper.write(40, 80, true);
  51. }
  52. void do_it() {
  53. // Retract
  54. stopper.write(140, 80, true);
  55. // Set
  56. mid.write(90, 50);
  57. base.write(130, 30);
  58. mid.wait();
  59. base.wait();
  60. handle.write(0, 50, true);
  61. // Push
  62. mid.write(70, 40);
  63. base.write(90, 40);
  64. mid.wait();
  65. base.wait();
  66. // Retract
  67. mid.write(90, 50, false);
  68. base.write(130, 50, true);
  69. // Set to Grab
  70. handle.write(95, 50, true);
  71. mid.write(85, 50, true);
  72. // Grab Door Handle
  73. base.write(95, 100, true);
  74. handle.write(0, 50, true);
  75. // Close Door
  76. mid.write(77, 50, false);
  77. base.write(77, 50, true);
  78. handle.write(95, 50, true);
  79. // Retract
  80. mid.write(90, 50);
  81. base.write(120, 30);
  82. mid.wait();
  83. base.wait();
  84. // Home
  85. mid.write(25, 50);
  86. base.write(180, 70);
  87. mid.wait();
  88. base.wait();
  89. }

Menu
Index
Engineering
Entertainment
Literature
Miscellaneous
Contact
Search
tiktok.com/@pkvi.xyz
Why Ayh?
Miter
Miter
@pkvi
"...may not meet professional standards."
2,363 miters
123 tenons
Subscribe
0.00365