Guest User

Untitled

a guest
Apr 20th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. // include the servo library
  2. #include <Servo.h>
  3.  
  4. Servo myServo;
  5. // creates an instance of the servo object to control a servo
  6. // declare the control pin for servo motor, call it servoPin
  7.  
  8. void setup() {
  9. // initialize serial communications
  10. // attach the servo object to the servoPin
  11. myServo.attach(3);
  12. }
  13.  
  14. void loop() {
  15. // read the analog input
  16. int sensor = analogRead(A0);
  17. int angle = map(sensor, 0, 1023, 0, 179);
  18.  
  19. // print it to the serial monitor
  20.  
  21. // make a new int called angle - use the map() function to map the range of your sensor to the range of the servo (which is 0 to 179)
  22. // move the servo using the angle from the sensor with the servo write() function
  23. myServo.write(angle);
  24. delay(20);
  25. }
Add Comment
Please, Sign In to add comment