Placeholder Notice: This article is an example placeholder created for the Robotics Learning Lab website template. It contains no invented experimental data, verified research findings, or claims of personal achievement.
Overview
As an introductory lab project in my first semester of Robotics Engineering, I set out to construct a differential-drive two-wheeled mobile platform. The primary goal was to connect foundational embedded programming concepts with physical hardware actuation.
The core architecture uses:
- Microcontroller: Arduino Uno (ATmega328P)
- Actuation: 2x DC TT gear motors with yellow gearboxes
- Motor Driver: L298N Dual H-Bridge module
- Sensor: HC-SR04 Ultrasonic Distance Sensor mounted on a micro SG90 servo
- Power: 2x 18650 Li-ion cells (7.4V nominal) for motors; separate 5V regulator for logic
Schematic & Wiring Logic
The system is partitioned into two power domains to isolate electrical motor noise from logic circuits:
[ 7.4V Battery Pack ]
│
├───> L298N Power In (VS & GND) ───> [ DC Motors Left & Right ]
│
└───> Step-Down LM2596 (5V Out) ───> [ Arduino Uno 5V & GND ]
│
├───> HC-SR04
└───> SG90 Servo
Common Ground Rule
A critical beginner lesson was the necessity of connecting all ground lines (GND) together. Without a common ground reference between the Arduino and the L298N motor driver, the PWM control signals lacked a return path, resulting in erratic motor behavior.
Control Architecture
The program loop follows a simple state machine:
- State: FORWARD
- Both motors drive forward at nominal PWM speed (
180 / 255). - Ping ultrasonic sensor every 50ms.
- Both motors drive forward at nominal PWM speed (
- State: OBSTACLE_DETECTED
- If distance
< 20 cm, brake motors immediately. - Sweep micro-servo 45° left, measure distance; sweep 45° right, measure distance.
- If distance
- State: ROTATE
- Rotate chassis in place toward the direction with larger clearance.
- Transition back to FORWARD.
Motor Driver Pinout & Direction Table
| Movement | IN1 | IN2 | IN3 | IN4 | ENA (PWM) | ENB (PWM) |
|---|---|---|---|---|---|---|
| Forward | HIGH | LOW | HIGH | LOW | 180 | 180 |
| Reverse | LOW | HIGH | LOW | HIGH | 160 | 160 |
| Turn Left | LOW | HIGH | HIGH | LOW | 160 | 160 |
| Turn Right | HIGH | LOW | LOW | HIGH | 160 | 160 |
| Hard Stop | LOW | LOW | LOW | LOW | 0 | 0 |
Key Debugging Takeaways
- Voltage Drops Under Stall: When both motors start simultaneously from rest, the inrush current causes a brief voltage sag. Adding a 470µF electrolytic capacitor across the motor driver input stabilized the supply.
- Sensor Blind Spots: The HC-SR04 ultrasonic sensor struggles with soft surfaces (foam, fabric) and angled obstacles that bounce sound waves away from the receiver.
- Hardware PWM Timers: Using
Servo.hdisablesanalogWrite()PWM functionality on Arduino Uno pins 9 and 10 because both utilize Timer 1. Moving motor PWM lines to pins 5 and 6 (Timer 0) resolved the conflict.
Future Improvements
- Replace open-loop control with wheel encoders for dead reckoning and PID speed regulation.
- Upgrade from Arduino Uno to an ESP32 or STM32 for real-time telemetry over Wi-Fi/Bluetooth.