Skip to content
Orange and blue RC rover with an arc of ultrasonic sensors in white printed mounts

NICER ROVER   /   EMBEDDED ROBOTICS

Driving
by echo.

Five ultrasonic sensors give an RC car enough information to choose its next turn. The decision happens onboard, on an ESP32-S3.

ControllerESP32-S3
Sensor array5 × HC-SR04
Motor driverBTS7960
Power supply7.4 V LiPo

MOTION STUDY

A corner in
slow motion.

Follow one possible encounter from the perspective of the controller.

ILLUSTRATED MANEUVER
145 cm

The wall comes into earshot.

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.

SENSING & CONTROL

How a wall becomes a turn.

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.

LFLFFRR
HC-SR04 · F

Straight ahead

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.

TRIG 6ECHO 11YAW 0°
Slowed illustration. Each sensor fires once per sweep.

When the corridor narrows

145 cm

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.

42 cm

Break off the turn

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.

750 ms

Back out and listen again

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.

ARDUINO / C++

The turn, in code.

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.

laneScore(int side)
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;
}
Power, motor and steering

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.

GPIO map and electrical interfaces
ESP32-S3 pin assignments from the sketch
DeviceSignalsGPIO
Left flankTRIG / ECHO4 / 9
Front leftTRIG / ECHO5 / 10
Straight aheadTRIG / ECHO6 / 11
Front rightTRIG / ECHO7 / 12
Right flankTRIG / ECHO8 / 13
Steering servoSignal16
BTS7960RPWM / LPWM17 / 18
BTS7960R_EN / L_EN21 / 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.

Echo filtering and motor duty

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.

Boot, diagnostics and recovery limits

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.

CAD / STL

Inside the sensor mount

CAD preview of the five-sensor mount
CAD preview

A bend in the bracket changes what the car can sense.

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.

Width × depth × height211 × 156.5 × 106.3 mm

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 STL