ESP32 Projects
Start a build
Markdown

Shuttumani for ESP32

An alarm clock that runs away from obstacles. ESP32 firmware for a one-motor toy-car chassis.

ESP32ArduinoUnrated
Parts and source

Before you start

Confirm board compatibility and supported firmware targets in the upstream documentation.

Upstream README

Shuttumani

An alarm clock that runs away from obstacles. ESP32 firmware for a one-motor toy-car chassis.

Shuttumani prototype, front view Shuttumani prototype, alternate view

What it does

An HC-SR04 ultrasonic sensor checks the space ahead. An ESP32 drives one DC motor through an L298N.

  • Path clear (valid reading above 20 cm): drive forward.
  • Obstacle at 20 cm or closer: stop, reverse briefly, stop.
  • No echo, or a reading outside 2 to 100 cm: stop. It is not treated as a clear path.
  • Valid distances are printed to the Serial Monitor at 115200 baud.

This is an early prototype. The clock is just the body: no timekeeping, no alarm sound, no steering, no turning.

How it works

The sketch is one file: firmware/runaway_alarm_clock/runaway_alarm_clock.ino.

  1. Send a 10 μs trigger pulse, then time the echo with pulseIn() (6000 μs timeout).
  2. Distance in cm is duration * 0.0343 / 2.
  3. Above STOP_DISTANCE the motor runs forward. At or below it, the motor stops for 200 ms, reverses for 500 ms, then stops for 500 ms.
Setting Value Purpose
MOTOR_SPEED 180 PWM duty, 0 to 255
STOP_DISTANCE 20.0 cm Obstacle threshold
MAX_DISTANCE 100.0 cm Longest accepted reading

Because of the timeout and range limit, an obstacle farther than 100 cm reads as invalid and stops the motor.

Hardware

  • ESP32 development board
  • L298N motor driver and one DC motor (salvaged from a toy car)
  • HC-SR04 ultrasonic sensor
  • 3.7 V Li-ion cell (with protection and a proper charger), USB cable, jumper wires
  • 1 kΩ and 2 kΩ resistors, or a level shifter, for the ECHO line
Module Pin Connect to
L298N ENA / IN1 / IN2 ESP32 GPIO 25 / 26 / 27
L298N OUT1 / OUT2 DC motor
HC-SR04 TRIG ESP32 GPIO 32
HC-SR04 ECHO ESP32 GPIO 33, through a voltage divider
All GND Common ground

Remove the L298N ENA jumper, since GPIO 25 drives ENA. Full details are in docs/wiring.md and docs/troubleshooting.md.

Read before powering on. The HC-SR04 ECHO pin can output about 5 V and ESP32 GPIOs are not 5 V tolerant, so never connect it directly. A single 3.7 V cell may not drive the motor reliably through an L298N because of its voltage drop. Keep the wheels raised for first tests.

images/wire-diagram.jpeg is a generic reference illustration. It shows two motors and a 7.4 V battery, so it does not match this project's wiring.

Build and upload

No extra libraries. analogWrite() comes from the ESP32 Arduino core.

  1. Install the Arduino IDE and Espressif's ESP32 board package.
  2. Open firmware/runaway_alarm_clock/runaway_alarm_clock.ino.
  3. Select your ESP32 board and serial port, then upload.
  4. Open the Serial Monitor at 115200 baud.

Notes

Known limits: one motor, no clock, no alarm, and invalid readings always stop the motor. Next steps I would try: steering, a buzzer, an RTC, adjustable thresholds.

MIT, see LICENSE.