Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Servo.h>
- Servo myservo; // create servo object
- // variable to hold servo angle
- int angle = 0;
- int pot = 0; // for potentiometer reading
- void setup() {
- // attach the servo motor
- myservo.attach(6);
- Serial.begin(9600);
- }
- void loop() {
- // read the potentiometer
- pot = analogRead(A0);
- // pot will be value between 0-1023
- // servo accepts values between 0-180
- Serial.println(pot);
- angle = map(pot, 0, 1023, 0, 180);
- myservo.write(angle);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement