Chapter 3
Implementation and Results
3.1 Implementation
The controller is an ESP32 running Arduino/C++. We wire two HC-SR04 modules on the left and right (TRIG
on GPIO 5 and 17; ECHO on GPIO 18 and 16), a DHT11 on GPIO 15 for temperature, and an LDR to ADC
GPIO 34 through a simple resistor divider. The motors are driven by an L298N using IN1=26, IN2=27, IN3=13,
IN4=14. We use GPIO 21 for the buzzer, GPIO 2 for a status LED, and GPIO 25 for the headlight LED, which
is wired active-low so 0 V turns it on. Power comes from a 5 V bank, and all grounds are common; we also
place a large capacitor across the motor supply to reduce voltage sag.
In software, we keep two FreeRTOS tasks. The sensor task (Core 0) samples temperature, LDR, and both
distances roughly every 100 ms, and decides the headlight state. The motor task (Core 1) runs about every 50
ms: if both sides are closer than 30 cm, it performs a smart evasion routine (back off, check which side is
clearer, try left/right turns, re-check); if only one side is close, it turns away; otherwise it goes forward.
Temperature ≥ 33 °C triggers a fire alert that stops the robot and plays SOS beeps with the LED until it cools.
For visibility, an HTTP server on port 80 serves a neat HTML dashboard at / and JSON at /data. The ESP32
first tries to join a given Wi-Fi network (STA mode). If it cannot connect in time, it automatically creates its
own hotspot so we can always open the dashboard during demos.
3.2 Performance Analysis
From hands-on tests, the dashboard updates feel quick and stable with about a half-second refresh. The robot
reacts smoothly to obstacles at arm’s length; when both sides are blocked, the smart evasion wiggles out within
a second or two. The headlight state tracks normal room lighting well: covering the LDR immediately flips it
to “ON,” and bright light switches it off. The fire alert begins near our set point (around 33–34 °C), and the
robot halts and signals clearly, which is exactly what we expect for a safety-first behavior. These results indicate
that sensor sampling, decision logic, and UI polling are balanced well for a small lab robot.
3.3 Results and Discussion
The robot achieved its main goals. It kept a safe buffer, avoided direct collisions, and handled tight spots thanks
to the smart evasion steps. The dashboard made our internal state visible—distances, headlight, fire status, and
vehicle action—so it was easy to debug and to present in class. We did notice that very soft or angled materials
sometimes confuse ultrasonics, which is normal for this sensor type. The DHT11 is slow and not very precise,
but it is good enough to show an alert demo. Occasional long delays (like SOS beeps) can briefly reduce web
responsiveness, but not enough to hurt a live demo. Overall, the system is simple, understandable, and solid for
student use.