Advertisement
Guest User

Servo

a guest
Mar 18th, 2019
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. //Program to read an IR Sensor
  2. //Turn on LED if sensor is high, print to serial port "IR data status"
  3. //Inputs IR Sensor (Pin 6)
  4. //Outputs Serial Port, LED (Pin 13)
  5. //Written : Mark Cambron
  6. // Date : March 18, 2019
  7. #include <Servo.h>
  8. Servo myservo;
  9. void setup()
  10. {
  11. //initializes the digital pin as an output
  12. //Pin 13 has an LED connected on most Arduino boards:
  13. pinMode(13,OUTPUT);
  14. pinMode(6,INPUT); //Setup pin 6 or input from IR
  15. Serial.begin(9600);
  16. myservo.attach(9);
  17. myservo.write(90); // set servo to mid-point
  18. }
  19. void loop()
  20. {
  21. int LeftSensorIR;
  22. int RightSensorIR;
  23. LeftSensorIR = digitalRead(6); //Read Sensor data
  24.  
  25. Serial.print("IR is reading: ");
  26. Serial.print(LeftSensorIR);
  27. Serial.print(" ");
  28. Serial.print(RightSensorIR);
  29.  
  30. if (LeftSensorIR == 1)
  31. {
  32. digitalWrite(13,HIGH); //turn on LED
  33. Serial.println(" LED if on");
  34. myservo.write(180);
  35. }
  36. else
  37. {
  38. digitalWrite(13,LOW); //turn off LED
  39. Serial.println(" LED if off");
  40. myservo.write(0);
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement