Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.70 KB | None | 0 0
  1. #include <Servo.h>
  2.  
  3. /*
  4.  * servoPin -> the pin which the servo is connected. Default is pin 7
  5.  * sensorPin -> the pin which the LDR sensor is connected. Default is A0
  6.  * sensorLimit -> the limit value where the servo is activated if the sensor reading falls below than this value.
  7.  */
  8. int servoPin = 7;
  9. int sensorPin = A0;
  10. int sensorLimit = 100;
  11.  
  12. Servo doorServo;
  13. int sensorReading;
  14.  
  15. void setup() {
  16.   doorServo.attach(servoPin);
  17.   doorServo.write(0);
  18.   Serial.begin(9600);
  19. }
  20.  
  21. void loop() {
  22.   sensorReading = analogRead(sensorPin);
  23.   Serial.println(sensorReading);
  24.  
  25.   if (sensorReading < sensorLimit) {
  26.     doorServo.write(90);
  27.     delay(5000);
  28.     doorServo.write(0);
  29.     delay(5000);
  30.   }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement