mpmcws

Elevator - Cabin lift

Nov 2nd, 2018
101
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ELEVATOR
  2. // by MPMC Workshop - Marco Cerani, novembre 2018 V1.5
  3. // https://mpmcworkshop.blogspot.it/
  4. // https://www.facebook.com/mpmcworkshop/
  5. //Dual H-Bridge: in1 to pin 2 Arduino, in2 to pin 4 Arduino
  6. //Dual H-Bridge: 6Vcc connector 1 e 2 H-Bridge
  7. //Dual H-Bridge: motor out 1 e 2 pin H-Bridge
  8. //Dual H-Bridge: + 5 from Arduino to connector 3 H-Bridge
  9. //Dual H-Bridge: remove ENA. ENA to pin 3 Arduino
  10. //Servo: wire yellow = signal red +5Vcc
  11. //Buttons: Pull Down 10K
  12. //This example code is in the public domain.
  13.  
  14. #include <Servo.h>
  15. Servo myservo;
  16. Servo myservo2;
  17. int pos = 90; //servo bar of the cabin
  18. int pos2 = 90; //servo2 gangway
  19.  
  20. //motor
  21. int dir1PinA = 2; //direction clockwise
  22. int dir2PinA = 4; //anti-clockwise direction
  23. int speedPinA = 3; //PWM
  24. //
  25. int speed = 200; //speed motor
  26. int buttonState = 0; //up
  27. int buttonState1 = 0; // stop
  28. int buttonState2 = 0; // down
  29. //buttons
  30. const int buttonPin = 8; //up
  31. const int buttonPin1 = 9; //stop
  32. const int buttonPin2 = 10; //down
  33. //cabin light
  34. int light = 13; //cabin light
  35.  
  36. void setup() {
  37.   Serial.begin(9600);
  38.   myservo.attach(6);
  39.   myservo2.attach(5);
  40.   pinMode(dir1PinA, OUTPUT); //pin 2
  41.   pinMode(dir2PinA, OUTPUT); // pin 4
  42.   pinMode(speedPinA, OUTPUT); // 3 PWM
  43.   pinMode(buttonPin, INPUT); //up
  44.   pinMode(buttonPin1, INPUT); //stop
  45.   pinMode(buttonPin2, INPUT); //down
  46.   pinMode(light, OUTPUT); //cabin light
  47.   myservo.write (115);
  48.   myservo2.write (92);
  49. }
  50. void loop() {
  51.   buttonState = digitalRead(buttonPin);
  52.   buttonState1 = digitalRead(buttonPin1);
  53.   buttonState2 = digitalRead(buttonPin2);
  54.   //warning: do not close with a clamp (token). It could give an error in the conditions (if).
  55.   //up -------------------------
  56.   if (buttonState == HIGH) {
  57.     myservo.write (115);
  58.     myservo2.write (40);
  59.     delay (10);
  60.     analogWrite(speedPinA, speed);
  61.     digitalWrite(dir1PinA, LOW);
  62.     digitalWrite(dir2PinA, HIGH);
  63.     digitalWrite(light, HIGH);
  64.   }
  65.  
  66.   //stop -----------------------
  67.   if (buttonState1 == HIGH) {
  68.     myservo.write (30);
  69.     myservo2.write (92);
  70.     delay (10);
  71.     analogWrite(speedPinA, 0);
  72.     digitalWrite(dir1PinA, LOW);
  73.     digitalWrite(dir2PinA, LOW);
  74.     digitalWrite(light, LOW);
  75.   }
  76.  
  77.   //down -----------------------
  78.   if (buttonState2 == HIGH) {
  79.     myservo.write (115);
  80.     myservo2.write (40);
  81.     delay (10);
  82.     analogWrite(speedPinA, speed);
  83.     digitalWrite(dir1PinA, HIGH);
  84.     digitalWrite(dir2PinA, LOW);
  85.     digitalWrite(light, HIGH);
  86.   }
  87. }
RAW Paste Data