Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Servo.h>
- Servo myservo;
- const int analogInPin = A0;
- const int relayPin = 9;
- int sensorValue = 0;
- void setup() {
- Serial.begin(9600);
- pinMode(relayPin,OUTPUT);
- digitalWrite(relayPin,0);
- myservo.attach(7);
- myservo.write(0);
- delay(1000);
- myservo.detach();
- }
- void loop() {
- sensorValue = analogRead(analogInPin);
- if (sensorValue < 1000) {
- digitalWrite(relayPin,1);
- myservo.attach(7);
- delay(500);
- myservo.write(90);
- delay(500);
- myservo.detach();
- }
- else {
- digitalWrite(relayPin,0);
- myservo.attach(7);
- delay(500);
- myservo.write(0);
- delay(500);
- myservo.detach();
- }
- Serial.print("sensor = ");
- Serial.println(sensorValue);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement