Your first robot in a weekend
Build a two-motor robot that drives and turns in a weekend: the part types, the wiring, a first program, a wheel-distance check and the safety basics.
In short
You have a free weekend and want to make something move on its own. A two-wheeled robot is the best first project because everything it teaches, from wiring to code to debugging, carries over to bigger robots. The goal for Sunday night is modest: a robot that drives forward, turns and stops.
In short
- A first robot needs five part types: a controller board, a motor driver, two geared motors with wheels, a chassis and a battery pack.
- Wire power first, test each motor alone, then write a program that drives forward, turns and stops.
- Use a small battery pack of AA cells, keep wires off the wheels, and never power the robot from a wall outlet.
Who this is for
This is for beginners new to robotics who have never wired a circuit, though some comfort with a computer helps. You do not need to solder if you pick parts with screw terminals or plug-in headers. Check the seller's page for the current price and specifications of anything you buy, because they change.
The plan at a glance
When | Goal |
|---|---|
Saturday morning | Gather the parts types, build the chassis, mount the motors and wheels |
Saturday afternoon | Do the wiring and test each motor separately |
Sunday morning | Write the first program and tune the turns |
Sunday afternoon | Fix problems, and run a tidy test course |
Step by step
1. Know the five part types
A controller board runs your program. A motor driver takes small signals from the board and switches the larger current that motors need. Two geared DC motors with wheels move the robot. A chassis holds everything. A battery pack (four AA cells in a holder is a safe start) powers the motors.
2. Assemble the chassis
Mount the motors so the wheels sit on opposite sides and in line. Add a ball caster or a slider at the back or front for a third point of support. Make sure nothing hangs below the frame where it can catch.
3. Wire with the power off
Battery positive and negative to the driver's power input. Each motor to its own output on the driver. The driver's input pins to the controller pins, and the driver's ground to the controller's ground. Put the battery switch off while you work. Compare every wire to the driver's diagram twice.
4. Test one motor at a time
Lift the robot so the wheels spin in the air. Run a short program that turns the left motor forward for a second. Then the right. If one spins the wrong way, swap that motor's two wires at the driver.
5. Write the driving program
Combine forward, turn and stop into functions and call them in order. Keep each action short while testing.
6. Tune and repeat
Change one number at a time, run again and write down what happened.
Worked example: a two-motor robot that drives and turns
A robot with two powered wheels steers by running them at different speeds. Both forward: it goes straight. Left reversed and right forward: it spins to the left on the spot. Here is a first program in the style of the Arduino language, with the pins as examples you would change to match your wiring.
// Example pins: change these to match your wiring
const int LEFT_FWD = 5;
const int LEFT_BACK = 6;
const int RIGHT_FWD = 9;
const int RIGHT_BACK = 10;
void setup() {
pinMode(LEFT_FWD, OUTPUT);
pinMode(LEFT_BACK, OUTPUT);
pinMode(RIGHT_FWD, OUTPUT);
pinMode(RIGHT_BACK, OUTPUT);
delay(3000); // time to put it on the floor
}
void stopAll() {
digitalWrite(LEFT_FWD, LOW);
digitalWrite(LEFT_BACK, LOW);
digitalWrite(RIGHT_FWD, LOW);
digitalWrite(RIGHT_BACK, LOW);
}
void forward(int ms) {
digitalWrite(LEFT_FWD, HIGH);
digitalWrite(RIGHT_FWD, HIGH);
delay(ms);
stopAll();
}
void turnLeft(int ms) {
digitalWrite(LEFT_BACK, HIGH);
digitalWrite(RIGHT_FWD, HIGH);
delay(ms);
stopAll();
}
void loop() {
forward(2000);
delay(500);
turnLeft(600);
delay(500);
}Timed moves are rough, but they are a fine start. To estimate how far the robot goes, measure the wheel diameter. For a 65 mm wheel, the circumference is π × 65 = 204 mm. If the wheel makes 5 turns, the robot travels 5 × 204 = 1020 mm, a little over a meter. Going the other way, 1000 mm needs 1000 ÷ 204 = 4.9 turns.
To find out how fast your robot actually moves, run forward(2000) on a tape measure and note the distance. Say it covers 0.50 m in 2 s. Its speed is 0.50 ÷ 2 = 0.25 m/s, so a 1 m drive needs 1 ÷ 0.25 = 4 s, which is forward(4000). Test it, because battery level changes the speed.
Safety first
Use a small battery pack of AA cells to start. Never connect a robot to mains power. Do not charge, puncture or bypass the protection on lithium polymer packs; learn about them from the maker's instructions before you ever use one. Keep fingers away from spinning wheels, and switch off before you change any wire.
If something goes wrong
- Nothing happens. Check the battery switch, the cell orientation and that the program uploaded.
- One wheel spins the wrong way. Swap the two wires of that motor at the driver.
- It veers when going straight. The motors are not identical. Run the faster one for a shorter time or reduce its speed with PWM.
- The controller resets when the motors start. The batteries are weak or the power wiring is loose; replace the cells first.
- A part gets hot. Switch off and disconnect the battery. Find the cause before you try again.
Keep it going
Next, make it drive a square, then add a distance sensor so it stops before a wall. Learning the basics of electronics, a coding path and a simulator will make each step faster. If you get stuck on a wiring diagram, DuckyHelper can see your screen and talk through it while you keep working, but always compare to your parts' own documentation.
Frequently asked questions
- Do I need to know how to code first?
- No. The program above uses four commands. Type it in, change a number and see what happens.
- Why not just buy a finished robot?
- A finished robot hides the wiring and the code. Building one teaches you how to find a fault when something stops working.