Advertisement
Guest User

Untitled

a guest
Apr 27th, 2017
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. #include <Servo.h>
  2. Servo myservo;
  3.  
  4. int LDR = 0; // light sensor connected to A0
  5. int prevValue = 0; // reference point
  6. int curValue = 0; // to check against prevValue
  7. void setup() {
  8. myservo.attach(13);
  9. pinMode(LDR, INPUT); //put light sensor as input
  10. myservo.write(140); // put servo in starting position
  11. Serial.begin(9600); // speed to interact with Arduino
  12. curValue = analogRead(LDR); //initialize curValue
  13. }
  14.  
  15. void loop() {
  16. prevValue = curValue; // put prevValue to reference point
  17. curValue = analogRead(LDR); // get new value for light sensor
  18. Serial.println(curValue); //print sensor data (0-1023)
  19. if(curValue - prevValue >= 20) { // if light spikes up
  20. myservo.write(180); //move servo to button
  21. delay(400); //hold servo in current position
  22. myservo.write(140); //move servo back to initial position
  23. }
  24. delay(100); // wait a tenth of a second for new data
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement