Hardware Reference
In-Depth Information
• The global variables servo , servoPin , and angle are used by the program.
The Servo data type adds a set of functions so that you can control your servo.
This includes the servo.attach(servoPin) and
servo.write(angle) functions, which you will use in this program to send
the servo to a specific angle. To find out all the different functions that are avail-
able, visit http://arduino.cc/en/reference/servo .
• The setup() function connects the servo functionality to the proper pin and
then initializes the serial port.
• The loop() function reads the serial port, and then uses that data to send the
servo to the proper angle by using servo.write(angle) .
When you have entered the code, upload the program. When it runs, navigate to Tools |
Serial Monitor . You can then enter the desired angle, as shown in the following screen-
shot:
Now you can imagine adding a whole set of servos, one controlled by a different digital
output pin on Arduino. However, Arduino itself will soon run out of the ability to supply
enough current to control more servos. So if you have projects that require more than just
one or two servos, you'll probably want to go with a servo motor shield.
Search WWH ::




Custom Search