Advertisement
safwan092

Untitled

Feb 21st, 2023
18
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. #include <Servo.h>
  2. Servo myservo;
  3. const int analogInPin = A0;
  4. const int relayPin = 9;
  5. int sensorValue = 0;
  6.  
  7. void setup() {
  8. Serial.begin(9600);
  9. pinMode(relayPin,OUTPUT);
  10. digitalWrite(relayPin,0);
  11. myservo.attach(7);
  12. myservo.write(0);
  13. delay(1000);
  14. myservo.detach();
  15. }
  16. void loop() {
  17. sensorValue = analogRead(analogInPin);
  18. if (sensorValue < 1000) {
  19. digitalWrite(relayPin,1);
  20. myservo.attach(7);
  21. delay(500);
  22. myservo.write(90);
  23. delay(500);
  24. myservo.detach();
  25. }
  26. else {
  27. digitalWrite(relayPin,0);
  28. myservo.attach(7);
  29. delay(500);
  30. myservo.write(0);
  31. delay(500);
  32. myservo.detach();
  33. }
  34. Serial.print("sensor = ");
  35. Serial.println(sensorValue);
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement