Book Image

Arduino Robotic Projects

By : Richard Grimmett
Book Image

Arduino Robotic Projects

By: Richard Grimmett

Overview of this book

Table of Contents (21 chapters)
Arduino Robotic Projects
About the Author
About the Reviewers

Controlling the servos with a program

Now that the hardware is connected, you'll need to supply the control signal to make your servos move. To control your servo, bring up the Arduino IDE. Make sure that the proper Arduino and port are chosen. Then enter the lines of code as shown in the following screenshot:

This code uses the Servo library that is installed with the standard Arduino IDE. The three sections of code that you'll need to understand are as follows:

  • 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 available, visit

  • The setup() function connects the servo functionality to the proper pin and then initializes the serial port.

  • The loop() function reads...