Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Servo.h>
- /*
- * servoPin -> the pin which the servo is connected. Default is pin 7
- * sensorPin -> the pin which the LDR sensor is connected. Default is A0
- * sensorLimit -> the limit value where the servo is activated if the sensor reading falls below than this value.
- */
- int servoPin = 7;
- int sensorPin = A0;
- int sensorLimit = 100;
- Servo doorServo;
- int sensorReading;
- void setup() {
- doorServo.attach(servoPin);
- doorServo.write(0);
- Serial.begin(9600);
- }
- void loop() {
- sensorReading = analogRead(sensorPin);
- Serial.println(sensorReading);
- if (sensorReading < sensorLimit) {
- doorServo.write(90);
- delay(5000);
- doorServo.write(0);
- delay(5000);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement