Advertisement
macbelieve

Servo for raindrop

Aug 17th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1.  
  2. #include <Servo.h>
  3. int servoPin = 3;
  4. int button = 2;
  5. Servo Servo1;
  6.  
  7. void setup() {
  8. Serial.begin(9600);
  9. pinMode(button, INPUT_PULLUP);
  10. Servo1.attach(servoPin);
  11.  
  12. }
  13. void loop() {
  14. int sensorVal = digitalRead(2);
  15. Serial.println(sensorVal);
  16.  
  17. if (sensorVal == HIGH) {
  18. digitalWrite(13, LOW);
  19. Servo1.write(0);
  20. } else {
  21. digitalWrite(13, HIGH);
  22. Servo1.write(180);
  23. }
  24.  
  25. delay(1); // delay between reads
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement