Skip to main manual content
Circuit Manual
BeginnerESP325V USB / 3.3V Logic

ESP32 Autonomous Obstacle Avoiding Mini Boat (Prototype V1)

Build an autonomous ESP32 mini boat using an ultrasonic sensor, TIP120 Darlington transistor, and 5V submersible pump to stop safely before obstacles.

By Chathura PrabashanaUpdated Nov 23, 2026
Difficulty
Beginner
Build / Read Time
60 mins
Operating Voltage
5V USB / 3.3V Logic
Hardware Platform
ESP32 Dev Module (30 Pin)
Est. Parts Cost
$18 USD
Direct Summary / Key Takeaway

An ESP32 Dev Module continuously measures forward clearance using a bow mounted HC-SR04 ultrasonic distance sensor and switches a 5V submersible water pump through a TIP120 NPN Darlington transistor on GPIO 4. When open water exceeds 15.0 cm ahead, the pump jets forward for propulsion; whenever an obstacle enters 15.0 cm or closer, GPIO 4 drops LOW and stops the pump automatically.

Building your first autonomous vehicle does not require expensive brushless thruster pods or custom printed circuit boards. With a single ESP32 Dev Module, a budget HC-SR04 ultrasonic sensor, a TIP120 transistor, and a 5V submersible mini water pump, you can assemble a working tabletop prototype boat that drives itself across a test tub and halts cleanly before bumping into walls.

01. How the Autonomous Boat Works (Beginner Overview)

At its heart, every autonomous robot runs a continuous sense and react loop. This boat checks what lies directly ahead twice per second and decides whether to run its stern water jet pump:

  1. Send an Ultrasonic Ping: The ESP32 pulls the HC-SR04 Trig pin HIGH for exactly 10 microseconds. The left metal transducer emits an inaudible burst of 40 kHz sound waves straight ahead across the water surface.
  2. Measure the Echo Time: When those sound waves strike a wall or floating obstacle, they bounce back to the right transducer. The HC-SR04 holds its Echo pin HIGH for the exact round trip flight time in microseconds, which Arduino reads using pulseIn(echoPin, HIGH).
  3. Convert Time Into Centimeters: Sound travels through air at roughly 0.034 cm per microsecond. Because the sound pulse travels out to the obstacle and back again, we divide the total distance by 2:
distance_cm = duration * 0.034 / 2
  1. Control the Water Pump: If distance_cm > 15.0, the path ahead is clear, so the ESP32 drives GPIO 4 HIGH to switch on the 5V submersible pump. The moment an obstacle comes within 15.0 cm or closer, GPIO 4 drops LOW and cuts propulsion immediately.

02. Circuit Theory: Why We Use a TIP120 Transistor Instead of Direct GPIO Power

Every beginner eventually asks: why not wire the water pump red wire straight into ESP32 GPIO 4?

Microcontroller pins are logic signals, not power outlets. Each ESP32 GPIO pin outputs 3.3V and can safely supply only 20 mA to 40 mA of continuous current. By contrast, a 5V submersible mini water pump easily pulls 150 mA to 350 mA while pushing water, plus a brief startup surge when the impeller begins spinning. Connecting a motor directly to an ESP32 GPIO pin will permanently burn out the output transistor inside the silicon chip.

To bridge a tiny 3.3V signal to a heavier 5V motor load, we insert a TIP120 as a low side switch:

  • TIP120 TO-220 Pinout Orientation: Hold the TIP120 upright with the flat black plastic face pointing toward you (printing visible, silver metal heatsink tab facing away behind it) and the three metal legs pointing down:
    • Left Pin = Base (B): Receives the tiny 3.3V control signal from ESP32 GPIO 4 through a resistor.
    • Middle Pin = Collector (C): Connects to the negative (black) wire of the 5V water pump.
    • Right Pin = Emitter (E): Connects straight to ESP32 GND.
  • Role of the 330 Ohm Base Resistor: Without a resistor between GPIO 4 and the TIP120 Base, the transistor base emitter junction behaves like a forward biased diode and draws excessive current from the ESP32 pin. Placing a 330 Ohm resistor in series caps base current safely around 5 mA to 6 mA, which is plenty to saturate the TIP120 fully ON. Check your bands with the Circuit Manual Resistor Decoder before wiring.
  • Role of the 1N4007 Flyback Diode: Spinning pump motors contain copper wire coils (). The instant the TIP120 shuts the pump OFF, the collapsing magnetic field tries to keep current flowing and creates a high voltage spike. Wiring a 1N4007 directly across the pump wires (silver stripe facing the +5V red wire, plain black end facing the Collector / pump black wire) absorbs that spike safely.

03. Bill of Materials and Hull Assembly (V1 Prototype)

Autonomous Mini Boat V1 BOM

9 Line Items / 9 Parts Total
Part NameSpecificationQtyBeginner Notes
ESP32 Dev Module (30 Pin)3.3V Logic, 5V VIN via USB1Main microcontroller running Arduino C++ firmware
HC-SR04 Ultrasonic Distance Sensor5V DC, 2 cm to 400 cm range1Mounted at the bow to detect obstacles ahead
5V Submersible Mini Water Pump3V to 5V DC brushless/brushed micro pump1Zip tied to the stern for water jet propulsion
TIP120 NPN Darlington TransistorTO-220 package, 60V 5A rated1Acts as a low side electronic switch for the 5V pump
330 Ohm Resistor1/4W Carbon or Metal Film (Orange, Orange, Brown, Gold)1Limits base current between ESP32 GPIO 4 and the TIP120 Base
1N4007 Rectifier Diode (Recommended Protection)1000V 1A flyback diode1Placed across pump terminals (striped cathode to +5V) to absorb motor voltage spikes
Solderless Breadboard and Jumper Wires400 or 830 tie points, Male to Male / Female1Holds the prototype control circuit on the deck
Plastic Water Bottle, Cardboard Deck and Zip Ties500 ml to 1L bottle1Simple buoyancy hull and mounting deck for V1 testing
5V USB-C Power Bank (e.g., Anker)5V DC output1Portable power supply for untethered water testing

Assembling the Prototype V1 Hull

Before investing in waterproof enclosures or custom hulls, Prototype V1 validates buoyancy, weight balance, and sensor height using zero cost household materials:

  1. Seal the Buoyancy Hull: Screw the cap tightly onto an empty 500 ml to 1L plastic water bottle so zero water can leak inside.
  2. Mount the Submersible Pump at the Stern: Wrap two nylon zip ties firmly around the lower rear section of the bottle to hold the 5V submersible pump beneath the waterline, pointing its outlet nozzle straight backward for clean forward thrust.
  3. Build the Dry Electronics Deck: Cut a flat piece of stiff corrugated cardboard wider than the bottle diameter and secure it horizontally across the top of the bottle with tape or zip ties. Position the solderless breadboard and portable USB power bank near the center of gravity so the bottle does not roll sideways.
  4. Mount the HC-SR04 at the Front Bow: Tape or bracket the ultrasonic sensor vertically at the front edge of the deck with both cylindrical transducers facing straight ahead and completely clear of the bottle neck so the deck never triggers false close range echoes.
FIG 01A / ELECTRICAL SCHEMATIC REV V13.3V LOGIC / 5V LOW SIDE PUMP DRIVER / ORTHOGONAL ROUTINGESP32 DEV MODULE3.3V LOGIC / 5V VIN30 PIN BOARD / USB POWERVIN (5V)GPIO 5GPIO 18GPIO 4Remapped from GPIO 13GNDHC-SR04 ULTRASONIC5V DC / RANGE: 2 TO 400 CMTRVCCTrigEchoGND+5V VIN POWER RAILTRIG PULSE (10 us)ECHO RETURN PULSECOMMON GND BUSR1: 330 OHMTO-220 FRONT FACETIP120NPN DARLINGTON (60V 5A)1:B2:C3:E1: BASE (LEFT)2: COLLECTOR (MID)3: EMITTER (RIGHT)D1: 1N4007FLYBACK DIODE(STRIPE TO +5V)M5V PUMPRED (+)BLACK (-)5V WATERPUMPSUBMERSIBLEFIG 01B / V1 HULL AND DETECTION PROFILESIDE ELEVATION / BOW LEFT, STERN RIGHTWATERLINEOBSTACLESTOP THRESHOLD <= 15.0 CMSEALED PLASTIC BOTTLE HULLCARDBOARD DECK + TAPEHC-SR04BREADBOARD + ESP325V PUMPWATER JET THRUST5V SUBMERSIBLE PUMP (ZIP TIED)
FIG 01: Complete electrical wiring schematic and V1 mechanical hull layout for the ESP32 obstacle avoiding mini boat.

04. Wiring Schedule

Always unplug the USB cable while placing components on the breadboard. Double check the TIP120 flat face orientation (Left = Base, Middle = Collector, Right = Emitter) before powering up.

ESP32 Boat Control Circuit Wiring Schedule

8 Jumpers
Source PinDestination PinWire ColorSignal / Purpose
ESP32 VIN (5V)HC-SR04 VCCRedPower supply for the ultrasonic sensor
ESP32 GNDHC-SR04 GNDBlackCommon ground reference
ESP32 GPIO 5HC-SR04 TrigYellowSends the 10 microsecond ultrasonic trigger pulse
ESP32 GPIO 18HC-SR04 EchoBlueReads the returning ultrasonic echo pulse width
ESP32 GPIO 4330 Ohm Resistor -> TIP120 Base (Left Pin)OrangeLow current 3.3V control signal to switch the transistor on
ESP32 VIN (5V)Water Pump Positive (Red Wire)RedDirect 5V power feed to the pump
Water Pump Negative (Black Wire)TIP120 Collector (Middle Pin)BlueSwitched ground path through the Darlington transistor
TIP120 Emitter (Right Pin)ESP32 GNDBlackCompletes the high current pump return path to ground

05. Bench Troubleshooting Note: Why We Moved From GPIO 13 to GPIO 4

Real hardware prototyping rarely succeeds on the first jumper wire. During initial bench testing of Prototype V1, the pump control signal was first assigned to GPIO 13. The Serial Monitor reported accurate ultrasonic distances above 15 cm, yet the water pump stayed completely silent.

Checking the breadboard with a digital multimeter (DC Volts mode, black probe on GND, red probe on the GPIO header pin) immediately revealed the root cause: GPIO 13 measured 0.00V even when the sketch commanded HIGH. Reassigning the signal wire and firmware constant to GPIO 4 (const int pumpPin = 4;) immediately restored a crisp 3.3V output on the base resistor, saturating the TIP120 and spinning the 5V submersible pump reliably on every cycle.

Whenever a motor or transistor fails to respond on your own bench, measure the microcontroller output pin directly with a multimeter before replacing parts. You can also check safe pin behavior in our Interactive ESP32 GPIO Explorer.

06. Tested Arduino IDE Firmware

Open Arduino IDE 2.3.10, select ESP32 Dev Module under Tools > Board, choose your active USB COM port, and upload the verified sketch below. No external third party libraries are needed.

esp32_obstacle_boat_v1.inocpp
Library Note:Verified in Arduino IDE 2.3.10 with ESP32 Dev Module board package at 115200 baud; zero external libraries required
const int trigPin = 5;
const int echoPin = 18;
const int pumpPin = 4;

long duration;
float distance_cm;

void setup() {
Serial.begin(115200);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(pumpPin, OUTPUT);
digitalWrite(pumpPin, LOW);
}

void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);

duration = pulseIn(echoPin, HIGH);
distance_cm = duration * 0.034 / 2;

Serial.print("Distance: ");
Serial.print(distance_cm);
Serial.println(" cm");

if (distance_cm > 15.0) {
  digitalWrite(pumpPin, HIGH);
} else {
  digitalWrite(pumpPin, LOW);
}

delay(500);
}

07. Bench Verification and V2.0 Upgrade Roadmap

Step by Step Dry Bench Verification

Never place a freshly wired prototype straight into water before proving the logic on a dry desk:

  1. Open Serial Monitor at 115200 Baud: Keep the ESP32 plugged into your computer USB COM port with the dry pump resting on the desk (run dry only for brief 1 to 2 second checks so the impeller bearings stay cool).
  2. Verify Clear Path Switching: Point the HC-SR04 into open air (> 15.0 cm). The Serial Monitor prints live readings in centimeters and the pump hums smoothly.
  3. Verify Obstacle Stop Behavior: Hold your open hand roughly 10 cm in front of the HC-SR04. Within half a second, the printed distance drops below 15.0 cm and the TIP120 switches the pump cleanly OFF.
  4. Switch to Portable Battery Power: Disconnect the computer USB cable, plug the ESP32 into a portable 5V Anker USB-C power bank, verify weight trim on the cardboard deck, and run your first supervised test in a bathtub or shallow storage bin.

Planned Prototype V2.0 Upgrade Roadmap

Once V1 proves reliable obstacle detection in water, three targeted mechanical and electrical upgrades turn it into a durable pond ready vessel:

  1. Permanent Soldered Perfboard: Migrate the 330 Ohm resistor, TIP120 transistor, 1N4007 flyback diode, and 1k/2k Echo voltage divider off the solderless breadboard onto a compact soldered perfboard inside a gasketed plastic project box so vibration never loosens a jumper wire.
  2. Twin Pontoon PVC Catamaran Hull: Replace the single plastic water bottle with two parallel sealed PVC pipe pontoons bridged by a flat deck. A twin hull eliminates roll wobble when carrying a heavier USB power bank.
  3. Active Steering Control: Upgrade from simple stop and go propulsion by adding either a second stern pump (differential thrust turning left or right) or a waterproof micro servo rudder behind the jet stream so the boat steers smoothly around obstacles instead of stopping in front of them.
Diagnostics & Common Questions

Testing and Troubleshooting FAQ

Why does my water pump refuse to spin even though the Serial Monitor shows open distance above 15 cm?+

First check which GPIO pin drives the 330 Ohm base resistor. During bench prototyping, GPIO 13 measured 0.00V under load, whereas moving both the jumper wire and pumpPin definition to GPIO 4 restored a clean 3.3V output. Also confirm the TIP120 Emitter shares a solid common GND wire with the ESP32.

Why does the TIP120 Base, Collector, and Emitter pin order matter so much?+

A Darlington transistor only switches current cleanly from Collector into Emitter when controlled by a small signal on the Base. With the flat black front face pointing toward you and the silver metal tab behind, Left is Base, Middle is Collector, and Right is Emitter. Reversing the chip backward can keep the pump stuck on permanently or overheat the transistor.

Why does my 5V USB power bank shut itself off automatically during testing?+

Many portable power banks include an automatic sleep circuit that turns off 5V output if total current falls below roughly 60 mA to 100 mA for 30 seconds. When the boat stops before an obstacle and the pump switches off, an idle ESP32 alone can dip below that threshold. Enable low current trickle charge mode if your Anker power bank supports it, or trigger periodic pump pulses.

How do I keep the breadboard and ESP32 dry during tub or pond tests?+

Keep the breadboard and USB power bank elevated on a rigid deck above the bottle hull, tape a clear plastic splash shield or food container lid over the electronics, and never run the open Prototype V1 build in choppy water or deep ponds where a capsize could submerge the USB battery.

Chathura Prabashana
Verified Author / Bench Tester

Chathura Prabashana

Embedded Systems Builder and IT Undergraduate

Chathura Prabashana builds, tests, and documents beginner friendly ESP32 circuits, microcontroller firmware, and practical electronics prototypes from scratch.

About the Author & Verification Standards →