Circuit 2
Arduino Code:
8
Troubleshooting:
Servo Not Twisting
Even with colored wires it is still shockingly easy to plug a
servo in backward. is might be the case.
Still Not Working
A mistake we made a time or two was simply forgetting
to connect the power (red and brown wires) to +5 volts
and ground.
Fits and Starts
If the servo begins moving then twitches, and there's a
ashing light on your RedBoard, the power supply you
are using is not quite up to the challenge. Using a wall
adapter instead of USB should solve this problem.
You should see your servo motor move to
various locations at several speeds. If the
motor doesn't move, check your
connections and make sure you have
veried and uploaded the code, or see the
troubleshooting tips below.
Code to Note:
Real World Application:
Robotic arms you might see in an assembly line or sci-
movie probably have servos in them.
Open Arduino IDE // File > Examples > SIK Guide > Circuit # 8
What You Should See:
IOREF
RESET
RESET
7-15V
SCL
SDA
AREF
GND
13
12
~11
~10
~9
8
7
~6
~5
4
~3
2
1
0
TX
RX
13
3.3V
5V
GND
GND
VIN
A0
A1
A2
A3
A4
A5
POWER
ANALOG IN
DIGITAL (PWM~)
ON
ISP
TX
RX
IOREF
RESET
RESET
7-15V
SCL
SDA
AREF
GND
13
12
~11
~10
~9
8
7
~6
~5
4
~3
2
1
0
TX
RX
13
3.3V
5V
GND
GND
VIN
A0
A1
A2
A3
A4
A5
POWER
ANALOG IN
DIGITAL (PWM~)
ON
ISP
TX
RX
#include is a special "preprocessor" command that inserts a library (or any
other le) into your sketch. You can type this command yourself, or
choose an installed library from the "sketch / import library" menu.
#include <Servo.h>
e servos in this kit don't spin all the way around, but they can be commanded
to move to a specic position. We use the servo library's write() command to
move a servo to a specied number of degrees(0 to 180). Remember that the
servo requires time to move, so give it a short delay() if necessary.
servo1.write(180);
e servo library adds new commands that let you control a servo. To
prepare the Arduino to control a servo, you must rst create a Servo
"object" for each servo (here we've named it "servo1"), and then "attach" it
to a digital pin (here we're using pin 9).
Servo servo1;
servo1.attach(9);
Page 52