Introduction
Building your first mobile robot is a rite of passage for any maker. The two-wheel differential drive robot is the most popular entry point because it is simple, affordable, and highly maneuverable. By using two powered wheels and one passive castor wheel for balance, you create a robot that can spin on a dime and navigate tight spaces. In this guide, we will build a basic version using an Arduino and NPN transistors.
Components Needed
To follow this tutorial, you will need the following parts:
Microcontroller: Arduino Uno or Nano
Motors: 2x 3V-6V DC Gear Motors (Yellow TT Motors)
Transistors: 2x BC107 or BC547 (NPN type)
Diodes: 2x 1N4007 (Flyback protection)
Resistors: 2x 1k Ohm (Base protection)
Power: 9V Battery or 7.4V Li-ion pack
Stabilizer: 1x Mini Castor Wheel
Chassis: Acrylic plate or cardboard
Breadboard & Jumper Wires
Circuit Diagram
The circuit uses the Arduino to trigger the "gate" of the transistors, allowing a higher voltage external power supply to drive the motors.
Circuit Connections & Explanation
The wiring is broken down into three main sections:
The Control Logic: Arduino Digital Pins 8 and 9 connect to the Base (B) of the transistors through 1k Ohm resistors. This protects the Arduino from drawing too much current.
The Power Path: The Collector (C) of each transistor connects to one terminal of the motor. The other motor terminal connects to the Positive (+) rail of your battery. The Emitter (E) of the transistor goes to Ground (GND).
The Protection (Flyback): We place a 1N4007 diode across each motor’s terminals. The silver band (Cathode) must point toward the positive voltage. This prevents "Inductive Kickback" from destroying your transistors when the motor stops.
Common Ground: The Arduino GND and the Battery GND must be connected together for the circuit to complete.
The Code
This program follows a specific movement loop: Forward → Stop → Left → Stop → Right → Stop.
/*
* 2-Wheel Robot with Castor Wheel
* Movement Sequence: Forward, Stop, Left, Stop, Right, Stop
*/
int leftMotor = 9;
int rightMotor = 8;
void setup() {
pinMode(leftMotor, OUTPUT);
pinMode(rightMotor, OUTPUT);
}
void loop() {
// 1. FORWARD
digitalWrite(leftMotor, HIGH);
digitalWrite(rightMotor, HIGH);
delay(2000);
// 2. STOP
digitalWrite(leftMotor, LOW);
digitalWrite(rightMotor, LOW);
delay(1000);
// 3. TURN LEFT
digitalWrite(leftMotor, LOW);
digitalWrite(rightMotor, HIGH);
delay(1500);
// 4. STOP
digitalWrite(leftMotor, LOW);
digitalWrite(rightMotor, LOW);
delay(1000);
// 5. TURN RIGHT
digitalWrite(leftMotor, HIGH);
digitalWrite(rightMotor, LOW);
delay(1500);
// 6. STOP
digitalWrite(leftMotor, LOW);
digitalWrite(rightMotor, LOW);
delay(1000);
}
Code Explanation
digitalWrite(pin, HIGH): Sends 5V to the transistor base, "closing the switch" and letting the motor spin.digitalWrite(pin, LOW): Cuts the signal, opening the switch and stopping the motor.Steering Logic: Since we have a castor wheel, stopping the left motor while the right motor spins causes the robot to pivot around the left wheel, resulting in a Left Turn.
delay(): This controls the duration of the movement. You can increase or decrease these numbers to make the turns sharper or the forward path longer.
Pro-Tips for Success
Weight Distribution: Keep your batteries low and centered. If the robot is too "tail-heavy" on the castor wheel, the drive wheels might slip.
Transistor Heat: Small transistors like the BC107 can get hot. If your robot stops moving after a minute, you likely need a beefier transistor like the TIP120 or an L298N Motor Driver.
Surface Tension: Castor wheels work best on smooth surfaces. On thick carpet, they can get stuck, causing the robot to jitter.
Common Uses
Obstacle Avoidance: Add an Ultrasonic sensor to make the robot turn when it sees a wall.
Line Following: Add IR sensors to make the robot follow a black tape path.
Remote Control: Connect a Bluetooth module (HC-05) to drive the robot from your phone.
Conclusion
Building a castor-wheel robot is a fantastic way to learn the relationship between code and physical motion. While this transistor-based circuit is great for learning the basics of switching, your next step should be exploring H-Bridges, which will allow your robot to drive in reverse!