A structured, beginner-friendly learning journey to build and program a 2WD robot car using an Arduino UNO R3 starter kit. This repository documents every step of the progression — from blinking a single LED to building a fully autonomous obstacle-avoiding and line-following robot.
Philosophy: Before wheels spin, we learn how the Arduino "talks" to components. Each phase builds directly on the last, so no step is skipped.
- About the Project
- Hardware & Components
- Software Requirements
- Repository Structure
- Learning Progression
- Wiring Diagrams
- How to Upload Code
- Contributing
- License
This project is a personal learning log and codebase for building a 2WD robot car from scratch using an Arduino UNO R3 starter kit. It is aimed at absolute beginners who want a clear, step-by-step path — from understanding basic electronics to writing autonomous robot behavior.
Each folder in this repository corresponds to a step in the progression plan below, containing the sketch (.ino file), any relevant wiring notes, and a short description of what was learned.
| Component | Description |
|---|---|
| Arduino UNO R3 | The main microcontroller board |
| L298N Motor Driver Module | Drives the two DC motors (the Arduino alone can't power them) |
| 2× DC Gear Motors | The "muscles" — one per side |
| 2× Wheels + 1× Caster Wheel | 2WD chassis movement |
| Acrylic / Wood / Metal Chassis | The car's frame |
| HC-SR04 Ultrasonic Sensor (Grove) | Detects distance to obstacles (the robot's "eyes") |
| IR Sensor Module(s) | Detects black/white surfaces for line following |
| Breadboard | For prototyping circuits without soldering |
| LEDs (Red, Yellow, Green) | Used in early learning steps |
| Resistors (220Ω – 1kΩ) | Protect LEDs and other components from excess current |
| Push Button | Digital input device |
| Dupont Jumper Wires (M-M, M-F) | Connect components together |
| Battery Holder + Batteries | Powers the motors via the L298N |
| USB Type-B Cable | Uploads code from computer to Arduino |
- Arduino IDE (v1.8.x or v2.x) — Download here
- USB Drivers — Usually installed automatically; on Linux (Ubuntu), you may need to add your user to the
dialoutgroup:Then log out and back in.sudo usermod -a -G dialout $USER - Libraries (install via Arduino IDE → Sketch → Include Library → Manage Libraries):
NewPing— for the HC-SR04 ultrasonic sensor (optional but recommended)
arduino-2wd-robot/
│
├── 1_basics
│ ├── 1_builtin_led
│ ├── 2_external_led
│ ├── 3_button_input
│ ├── 4_traffic_light
│ └── 5_interactive_traffic_light
├── 2_sensors
│ ├── 4_ultrasonic_sensor
│ └── 5_ir_sensor
├── 3_motors
│ ├── 6_l298n_intro
│ ├── 7_single_motor
│ └── 8_speed_control_pwm
├── 4_assembly
│ ├── 10_wiring
│ ├── 11_movement_blocks
│ └── 9_physical_assembly
├── 5_autonomy
│ ├── 12_obstacle_avoidance
│ └── 13_line_follower
├── documents
└── README.md
Before the wheels turn, we need to understand how the Arduino communicates with components.
Goal: Upload the very first piece of code. Make the small LED already soldered onto the Arduino board blink, confirming the computer can successfully send code to the board.
Concepts: setup(), loop(), digitalWrite(), delay(), OUTPUT
Goal: Take the components out of the box. Learn how to use the breadboard to connect an external LED. Understand why resistors are essential to prevent burning out components.
Concepts: Breadboard layout (rails, rows), Ohm's Law basics, current limiting resistors
Goal: Instead of the Arduino only sending power (Output), teach it to read power (Input). Use a button to toggle an LED on and off. Introduction to the Serial Monitor — the Arduino sends text messages back to the computer screen.
Concepts: INPUT_PULLUP, digitalRead(), Serial.begin(), Serial.println()
Goal: Connect Red, Yellow, and Green LEDs (each with its own resistor) and program the timed traffic light sequence: Green on → wait → off; Yellow on → wait → off; Red on → wait → off.
Concepts: Multiple digital outputs, timing logic, clean code organization
Goal: Combine Steps 3 and 4. The light stays green for cars, but when someone presses the button, the code triggers the yellow → red sequence so pedestrians can cross.
Concepts: Combining inputs and outputs, event-driven logic, real-world simulation
Now we test the "advanced" components individually.
Goal: Connect the sensor (which looks like two little "eyes") and program the Arduino to measure the distance to an object on the desk. This is how the robot will avoid walls later.
Concepts: pulseIn(), time-to-distance conversion, NewPing library, Serial Monitor output
Goal: Connect the IR sensor module and observe how it reacts when pointed at a white surface versus a black surface. This is the foundation for line following.
Concepts: Analog vs digital IR output, surface reflectivity, threshold calibration
Things start moving here! The Arduino alone doesn't have enough electrical power to drive motors — that's why we need the L298N module.
Goal: Identify each terminal on the L298N: where battery power enters, where motors connect, and where the Arduino control pins plug in.
Concepts: H-bridge topology, power separation (logic vs motor power), pin mapping
Goal: Write code to make one motor spin forward, stop, and then spin in reverse.
Concepts: digitalWrite() on L298N IN pins, motor direction control
Goal: Learn to make the motor spin slower or faster using PWM (Pulse Width Modulation).
Concepts: analogWrite(), PWM pins on Arduino UNO (~), duty cycle, analogWrite(ENA, 0–255)
The mechanical and engineering phase — the robot is born!
Goal: Assemble the acrylic (or wood/metal) chassis: screw in the motors, attach the wheels, and mount the battery holder.
Notes: Take photos at each stage! They're useful for troubleshooting and for this repository.
Goal: Mount the Arduino and L298N on top of the car and make all final connections using Dupont jumper wires (M-M).
⚠️ Double-check polarity before connecting the battery. Reversed polarity can damage the L298N and motors.
Goal: Create clean, reusable code functions for each direction: moveForward(), moveBackward(), turnLeft(), turnRight(), stopMotors(). Test each one.
Concepts: Functions/subroutines, code reusability, timing-based turns
Give intelligence to the car by combining everything learned so far.
Goal: The car drives on its own, uses the ultrasonic sensor to detect a wall, stops, turns, and continues exploring the environment.
Logic:
loop:
measure distance
if distance < threshold → stop → turn → continue
else → move forward
Goal: Use the IR sensors to follow a track made of black electrical tape on the floor.
Logic:
if left_sensor = black AND right_sensor = black → forward
if left_sensor = black AND right_sensor = white → turn right
if left_sensor = white AND right_sensor = black → turn left
if left_sensor = white AND right_sensor = white → stop (end of line)
Diagrams for each phase are stored in the /diagrams folder. Tools used:
- Fritzing for breadboard-style diagrams
- Photos of physical setups
- Open the
.inofile for the relevant step in Arduino IDE. - Connect the Arduino UNO to your computer via USB.
- Go to Tools → Board and select
Arduino UNO. - Go to Tools → Port and select the correct port (e.g.,
/dev/ttyACM0on Linux). - Click the Upload button (→).
- Open Tools → Serial Monitor (baud rate:
9600) to view debug messages where applicable.
This is a personal learning project, but suggestions, corrections, and improvements are welcome! Feel free to open an Issue or submit a Pull Request.
This project is licensed under the MIT License — feel free to use, adapt, and share.
Happy building!