Disclaimer: Project's description may be outdated.
The system provides a live video stream from a camera (ESP32-Wrover) and allows remote control of four motors. The Raspberry Pi Pico measures distance using an HC-SR04 ultrasonic sensor and sends the result to the ESP32 via a simple pulse-based signal. Two LEDs are switched using MOSFETs. The ESP32 operates as a Wi-Fi Access Point and an HTTP server, controlling the motors on demand. Communication with the system is handled by a desktop application that sends HTTP requests to the ESP32.
- The Raspberry Pi Pico periodically triggers a measurement using the HC-SR04 sensor and calculates the distance (in centimeters).
- After each measurement, the Pico generates a single-wire pulse whose duration is approximately equal to the measured distance (in milliseconds) on a communication pin.
- The ESP32 monitors this pin, measures the pulse duration, converts it back into a distance value, and exposes it via the /distance HTTP endpoint.
- The ESP32 creates a Wi-Fi network (AP) and an HTTP server with the following endpoints:
/video(MJPEG stream)/heartbeat(connection status)/motor/use(motor control commands)/motor/stop(stop motors)
- Motor operation is controlled using PWM functions (analogWrite) on the motor driver control pins. A safety timeout mechanism is implemented to stop the motors if no new command is received within a defined time period.
- ESP32 Wrover with camera support
- Camera compatible with ESP32 Wrover
- Raspberry Pi Pico
- HC-SR04 ultrasonic distance sensor
- 2× BTS7960 motor drivers
- DC motors
- Logic-level MOSFETs
- 2× LEDs
- Resistors
- 2× AG9905LP
- The Pico measures the distance in centimeters.
- It then uses the communication pin, setting it HIGH for delay(distance) milliseconds, then sets it LOW and waits for a short pause of 10 milliseconds.
- The ESP32 monitors this pin in a serialTask loop, waits for a HIGH state, measures the pulse duration in microseconds, scales and corrects it to obtain the distance, and stores it in a variable.
- The /distance endpoint returns this value as text with two decimal places.
- GET
/distance– returns a text value representing the distance in centimeters. - POST
/motor/use– expects one of the following commands in the request body as text: "forward", "backward", "left", "right". - POST
/motor/stop– stops all motors. - GET
/heartbeat– returns ALIVE. - GET
/video– opens an MJPEG video stream.
- Assemble the wiring according to the schematic.
- Power the system using a stable power supply and turn it on.
- Connect a computer to the ESP32 Wi-Fi network
ESP32-CAM_APusing the password12345678. - Launch the desktop application, which will establish a connection with the ESP32.
- Assemble the wiring according to the schematic, excluding the communication line between the ESP32 and the Raspberry Pi Pico.
- Power the system using a stable power supply and turn it on.
- Connect the ESP32 and the Raspberry Pi Pico to the computer using USB cables.
- Using, for example, the Arduino IDE (or another suitable environment), upload the software to both the ESP32 and the Raspberry Pi Pico.
- Connect the ESP32 and the Pico according to the schematic to establish the communication line.
- Operates as an Access Point with IP address
192.168.4.1and runs a WebServer. - On startup, all previously mentioned endpoints are registered.
- For each client requesting video streaming, a separate FreeRTOS task is created, sending JPEG frames in multipart MJPEG format.
- Distance reading is performed by measuring the duration of the HIGH signal and storing the result in a variable using
portENTER_CRITICALandportEXIT_CRITICALto ensure thread safety. - Functions
motorAForward,motorABackward,motorBForward,motorBBackward,motorAStop, andmotorBStopcontrol the motors using PWM. - The
motorSwitchSafeDelayfunction prevents simultaneous direction switching. If no further commands are received for a defined period, the motors are stopped.
- Measures distance using the HC-SR04 sensor by generating a 10-microsecond pulse on the TRIG line and reading the ECHO line using a timing function. The distance is then calculated and corrected using an appropriate formula.
- LEDs are turned on immediately after startup.
- Distance information is sent to the ESP32 as a pulse on the communication line.
Click on the image to open the full PDF file.





