Circuit 2
Arduino Code:
8
Troubleshooting:
Servo Not Twisting
Even with colored wires it is still shockingly easy to plug a
servo in backward. This 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
flashing 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
verified 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-fi
movie probably have servos in them.
Open Arduino IDE
//
File > Examples > SIK Guide >
Circuit # 8
What You Should See:
IOREF
RES
ET
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
DIGIT
AL (PWM~)
ON
ISP
TX
RX
IOREF
RES
ET
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
DIGIT
AL (PWM~)
ON
ISP
TX
RX
LEARN. SHARE. HACK.
#include is a special "preprocessor" command that inserts a library (or any
other file) into your sketch. You can type this command yourself, or
choose an installed library from the "sketch / import library" menu.
#include <Servo.h>
The servos in this kit don't spin all the way around, but they can be commanded
to move to a specific position. We use the servo library's write() command to
move a servo to a specified 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);
The servo library adds new commands that let you control a servo. To
prepare the Arduino to control a servo, you must first 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
Содержание RedBoard
Страница 13: ...Page 11...