This is the fifth project with the Arduino Starterkit. We learn to control the servo with a potentiometer.
Here are the schematics and a photo of the actual build:
And the source code.
/* Arduino Starter Kit example Project 5 - Servo Mood Indicator This sketch is written to accompany Project 5 in the Arduino Starter Kit Parts required: servo motor 10 kilohm potentiometer Created 13 September 2012 by Scott Fitzgerald http://arduino.cc/starterKit This example code is part of the public domain */ // include the servo library #include <Servo.h> Servo myServo; // create a servo object int const potPin = A0; // analog pin used to connect the potentiometer int potVal; // variable to read the value from the analog pin int angle; // variable to hold the angle for the servo motor void setup() { myServo.attach(9); // attaches the servo on pin 9 to the servo object Serial.begin(9600); // open a serial connection to your computer } void loop() { potVal = analogRead(potPin); // read the value of the potentiometer // print out the value to the serial monitor Serial.print("potVal: "); Serial.print(potVal); // scale the numbers from the pot angle = map(potVal, 0, 1023, 0, 179); // print out the angle for the servo motor Serial.print(", angle: "); Serial.println(angle); // set the servo position myServo.write(angle); // wait for the servo to get there delay(15); }
Hi, I’m doing the same tutorial. How did you succeed without any capacitor?
Also I have exactly the same code and the connection layout(except the capacitors) but my Servo is moving on its own….. Any suggestion?
Hey Guys.
I’ve just tested the setup and I noticed theres is an error in your schematic:
The “yellow” cables (servo control cable and potentiometer value cable) have to be switched in order for the whole setup to work:
servo control -> 9~
potentiometer value -> A0
Of Course, since A0 is analouge INput and 9~ an output connector.