Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // include the servo library
- #include <Servo.h>
- Servo myServo;
- // creates an instance of the servo object to control a servo
- // declare the control pin for servo motor, call it servoPin
- void setup() {
- // initialize serial communications
- // attach the servo object to the servoPin
- myServo.attach(3);
- }
- void loop() {
- // read the analog input
- int sensor = analogRead(A0);
- int angle = map(sensor, 0, 1023, 0, 179);
- // print it to the serial monitor
- // 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)
- // move the servo using the angle from the sensor with the servo write() function
- myServo.write(angle);
- delay(20);
- }
Add Comment
Please, Sign In to add comment