Building My First Autonomous Robot
Six months into my embedded systems course at Prime Robotics, we were given a capstone challenge: build a robot that can navigate a maze without any human input. No remote control, no pre-programmed paths — just sensors, a microcontroller, and whatever logic we could write in three weeks.
I chose the ESP32 as my brain. It is overkill for a simple maze bot, but I wanted the experience of working with a dual-core processor and built-in Wi-Fi for future remote monitoring.
What I Used
The hardware list was small: one ESP32 development board, two HC-SR04 ultrasonic distance sensors, one L298N dual H-bridge motor driver, two 6V DC gear motors with wheels, a 4xAA battery pack, and a small acrylic chassis. Total component cost: under 8,000 naira.
Wiring It Up
The HC-SR04 works by sending a 10-microsecond pulse on its TRIG pin and measuring how long the echo takes to return on the ECHO pin. Divide the echo duration by 58 and you get centimetres. Straightforward in theory. In practice, the timing is tight — the ESP32 running at 240 MHz can register the echo before the sound fully returns if you are not careful. I lost half a day to that bug.
The L298N takes two direction pins and one enable PWM pin per motor channel. Direction is HIGH or LOW logic; speed is 0-255 on the enable pin. The catch: the L298N drops about 2V internally, so on 6V batteries my motors were only seeing 4V. I switched to a 9V supply and the improvement was immediate.
The Navigation Algorithm
I used a right-hand rule: always try to go forward; if blocked, turn left; if still blocked, turn around. The front sensor triggers at anything within 20 cm. The right sensor maintains a consistent gap from the right wall so the robot hugs it smoothly instead of zigzagging.
The hardest part was not the sensing — it was the timing. How long do you run a motor to make a precise 90-degree turn? It depends on battery voltage, surface friction, and motor wear. I added an MPU-6050 gyroscope to close the loop on turns, measuring the actual rotation angle instead of relying on time.
Three Things That Went Wrong
First: I connected the L298N logic supply to the battery pack instead of the ESP32 onboard regulator. The regulator overheated and shut down. Twice. Lesson: read the datasheet before wiring, not after.
Second: both sensors were on the same timing loop and fired simultaneously. Ultrasonic sensors can pick up each other's echoes. Fix: stagger the trigger pulses by 50 ms.
Third: the chassis flexed under load and the front sensor tilted down, detecting the floor as an obstacle. The robot refused to move. A foam spacer behind the sensor mount fixed it in three minutes after two hours of debugging.
What I Shipped
The final robot navigated a 2x2 metre maze in an average of 47 seconds across ten test runs. Not fast, but reliable. More importantly, I now understand motor drivers, sensor timing, and closed-loop control in a way no lecture could have given me. Start simple, add one component at a time, and never trust a component whose datasheet you have not read.