Building robots that move on two wheels is quite common. To do this you need two continuous rotation servos. This can be troublesome, because sudden turns of the robot can draw more current than the Arduino can handle. Therefore you need to use a capacitor, and when the wheels changes direction it needs to be done smoothly. We’ve included the second part in the library so that you don’t have to worry about that.
Materials
- 1 Arduino Uno board
- 1 Basic Education shield
- 2 Continuous rotation servos
- 1 100 micro F Capacitor
- 2 jumper wires
Instructions
- Connect the servo of the left wheel to D10 and the servo of the right wheel to D9.
- Connect a capacitor between GND and 5V, short leg to GND and long leg to 5V.
- Upload the code: File -> Examples -> BasicEducationShield -> Help-> Wheels
/* Wheels */ #include <BasicEducationShield.h> #include <Servo.h> //wheels(left, right) Wheels wheels=Wheels(10, 9); void setup(){ //Initialize the servo wheels wheels.begin(); } void loop(){ //Makes the wheel spin forward wheels.goForward(); delay(2000); //Makes the wheels spin backwards wheels.goBackwards(); delay(2000); //Makes the wheels spin in opposite direction so that //the vehicle will spin left wheels.turnLeft(); delay(2000); //Makes the wheels spin in opposite direction so that //the vehicle will spin right wheels.turnRight(); delay(2000); //Makes the wheels stop wheels.standStill(); delay(2000); }
When the code is uploaded the wheels should rotate forward for 2 seconds, then backwards for two seconds.
turnLeft()
makes the wheels rotate in opposite direction to each other so that the vehicle rotates counter clockwise, turnRight()
makes them rotate in the other direction so that the vehicle rotates clockwise. standStill()
makes both servos stop.
It’s not working
- Make sure that the servos are connected to the pins you have stated in the code. Make sure that the first digital pin stated in
begin(left, right)
is where the left wheel is connected and the second one the right wheel. If you get this wrong your robot will go backwards when it’s supposed to go forwards etc.