# Move A Robot

# Forward Movement

Meet our robot. It has 2 servo motors that control the two side wheels and a small caster wheel. The servo motors are connected to the Arduino boards. The left servo is connected to pin 9 and the right servo is connected to pin 10. In order to control the motors, we use a library Servo.h. To include the library into our program we use the #include <Servo.h>. Note that the line that starts with # does not end in a semicolon.

After we include the library we can create two objects of Servo, which is done on line 3 and 4. For every servo variable, we give it a name to be able to use it afterwards in our code. Inside the setup function, we will attach the pin number to the library servos. The left one is at pin 9 and the right servo at pin 10. This is done on line 7 and 8.

To control the servo, we can write to it an angle from 0 to 180. At 90 the continuos servo does not move. And as you increase the value towards the 180 or decrease it towards 0, the servo will change the speed in the specific direction clockwise or anticlockwise, depending if the angle is above or under 90.


The following program writes an angle of 170 to the left servo and then waits for 3 seconds. After that it writes 90 to both servos for them to stop. Modify the code to collect all 3 coins.


The servos are installed opposite to each other. If the servo motors are both moving clockwise (or anticlockwise), then they will be turning in opposite directions relative to each other.

# Robot Rotation


Can you get all the coins??