Look for an opening
Inside this distance ahead, the firmware weighs each diagonal at 70% and its neighbouring flank at 30%. Missing echoes lower the score. The car holds a turn decision for up to 550 ms before weighing the two sides again.

NICER ROVER / EMBEDDED ROBOTICS
Five ultrasonic sensors give an RC car enough information to choose its next turn. The decision happens onboard, on an ESP32-S3.
MOTION STUDY
Follow one possible encounter from the perspective of the controller.
Five HC-SR04 modules take turns sending a pulse. As the front reading falls below 145 cm, the ESP32-S3 compares the space beside the car with the space ahead of each front wheel.
The body shell hides a small conversation. One sensor sends a pulse, listens for its echo and hands the next sensor its turn. The ESP32-S3 gives each direction a slot 65 milliseconds apart. In roughly a third of a second, it has listened across the whole nose.
A wall inside 145 cm prompts the car to look for a turn. At 42 cm or closer, the controller cuts motor power and prepares to reverse.
Inside this distance ahead, the firmware weighs each diagonal at 70% and its neighbouring flank at 30%. Missing echoes lower the score. The car holds a turn decision for up to 550 ms before weighing the two sides again.
At or below this front threshold, or 17 cm on either diagonal, the controller cuts motor power. It centres the steering and waits 350 ms before requesting reverse.
Reverse runs on a timer. After another 350 ms at rest and five new pings, the car picks an escape side. The steering gets 350 ms to settle before forward torque returns.
Look at the last penalty. A tight corner costs a side 65 points after a failed turn, giving the car a reason to try the other way on its next pass.
float laneScore(int side) {
uint8_t diag = side > 0 ? FRONT_LEFT : FRONT_RIGHT;
uint8_t edge = side > 0 ? LEFT : RIGHT;
float diagCm = observed(diag, 105.0f);
float edgeCm = observed(edge, 85.0f);
float score = 0.70f * min(diagCm, 220.0f) + 0.30f * min(edgeCm, 220.0f);
if (!known(diag)) score -= 27.0f;
if (!known(edge)) score -= 15.0f;
if (side == failedSide) score -= 65.0f; // avoid repeating the failed corner
return score;
}The Li-polymer pack carries a 7.4 V, 850 mAh, 6.30 Wh label. The LM2596S module steps voltage down and provides an on-board LED voltmeter. The output setting and the current drawn under load would need bench measurements.
The BTS7960 module switches the drive motor with two direction inputs and an enable pair. The sketch sets 12 kHz, eight-bit PWM. The familiar 43 A marking refers to the chip’s typical current-limit figure. Infineon datasheet · TI regulator specifications
A separate servo sets the wheel angle at 50 Hz. Its centre pulse is 1,500 µs, bounded between 1,180 and 1,820 µs. The direction fix makes shorter pulses steer left. Each 20 ms update moves the pulse by at most 18 µs, smoothing the motion.
| Device | Signals | GPIO |
|---|---|---|
| Left flank | TRIG / ECHO | 4 / 9 |
| Front left | TRIG / ECHO | 5 / 10 |
| Straight ahead | TRIG / ECHO | 6 / 11 |
| Front right | TRIG / ECHO | 7 / 12 |
| Right flank | TRIG / ECHO | 8 / 13 |
| Steering servo | Signal | 16 |
| BTS7960 | RPWM / LPWM | 17 / 18 |
| BTS7960 | R_EN / L_EN | 21 / 14 |
The wiring notes specify level shifting each 5 V ECHO signal to 3.3 V at the ESP32-S3, a suitable independent servo regulator and a shared ground.
The sketch accepts distances from 3 to 240 cm. A closer echo contributes 60% to the filtered update, while a receding echo contributes 27%. The result reacts quickly to an approaching wall and more slowly to a sudden opening. After 950 ms, an old reading becomes unknown.
On the 0–255 duty scale, a clear path requests 95, a bend 68, a tight approach 55 and reverse 80. Missing front data caps forward duty at 52. The controller can add three counts or shed 22 per 20 ms tick, slowing the car faster than it accelerates.
The supplied ESP32-S3 N16R8 sketch targets Arduino-ESP32 3.x and ESP32Servo. It begins autonomous driving after seven seconds. At 115,200 baud, STOP, START and STATUS control the test session. Every 600 ms, diagnostics report five distances, motor duty, steering pulse, mode and reverse attempts.
FTEST and RTEST run a 400 ms motor check after STOP and a short wait, with wheels raised. Rear clearance must be checked on the test track because the five sensors face forward and sideways. A fourth reverse request in a 12-second window enters FAULT. A rescan with all four side and diagonal readings unavailable also stops the motor.

The middle sensor faces straight ahead. On either side, one holder turns outward by 35° and the next by 75°. Two risers lift the curved assembly above its chassis plate.
Each holder has about 12° of adjustment in either direction. The board outline and hole pattern in the CAD files are provisional fit dimensions.
Download STLWORKSHOP PHOTOGRAPHS