Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // include the servo library
- #include <Servo.h>
- // creates an instance of the servo object to control a servo
- Servo myservo;
- // declare the control pin for servo motor, call it servoPin
- int servopin = A0;
- int angle;
- void setup() {
- // initialize serial communications
- Serial.begin(9600);
- // attach the servo object to the servoPin
- myservo.attach(3);
- }
- void loop() {
- // read the analog input
- angle = analogRead(servopin);
- // print it to the serial monitor
- Serial.println(servopin);
- // 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)
- angle = map(angle, 0, 1023, 0, 180);
- // 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