This project demonstrates a wireless, peer-to-peer joystick-to-servo system using three ESP32-CAM microcontrollers and ESP-NOW. A Wokwi simulation (non-P2P) of the core main.cpp
logic is also included.
The Wokwi demo uses src/main.cpp
to drive two servos directly from a joystick on a single ESP32:
Note: This sim does not use ESP-NOW. For the full peer-to-peer example, see master.cpp and slave.cpp below.
├─ .vscode/ # VSCode & PlatformIO settings
├─ include/ # Custom headers
├─ lib/ # External libraries
├─ src/
│ ├─ main.cpp # Single-ESP32 joystick→servo demo (Wokwi)
│ ├─ master.cpp # ESP32-CAM “Master” (joystick transmitter via ESP-NOW)
│ ├─ slave.cpp # ESP32-CAM “Slave” (servo receiver via ESP-NOW)
│ └─ camera_stream.cpp # ESP32-CAM camera streaming (IDE example)
├─ platformio.ini # PlatformIO build configuration
└─ README.md # This file
- PlatformIO (VSCode or CLI)
- Three ESP32-CAM boards (two for joystick/servo P2P, one for camera stream)
- Analog joystick module
- Two hobby servos (5 V, ~1 A stall current each)
- 5 V power supply (≥2 A)
- Common GND wiring (for boards sharing the same power)
git clone https://github.com/KillWasHere/ESP-Peer-To-Peer-Servo-and-Joystick.git
cd ESP-Peer-To-Peer-Servo-and-Joystick
- Open
src/main.cpp
in VSCode and press the Wokwi "▶️ " button, or click the link above.
Joystick VCC → 5 V
Joystick GND → GND
Joystick X → GPIO 34
Joystick Y → GPIO 35
Power servos with 5 V (tie GND to master)
Servo pan signal → GPIO 14
Servo tilt signal → GPIO 15
Mount device (camera or sensor) on pan-tilt bracket
Flash ESP32-CAM with Arduino IDE example "CameraWebServer"
Connect camera power & GND
Access camera via IP address on Wi-Fi network
- In
src/master.cpp
, replacereceiverAddress[]
with your servo-slave ESP32-CAM’s MAC (print viaSerial.println(WiFi.macAddress());
). src/slave.cpp
requires no MAC edits.
- Open the PlatformIO sidebar in VSCode.
- Select master environment → Upload to joystick ESP32-CAM.
- Select slave environment → Upload to servo ESP32-CAM.
- Use Arduino IDE to flash camera_stream.cpp (IDE example) to the third ESP32-CAM.
- Reads joystick on GPIO 34/35
- Maps 0–4095 → 0–180°
- Drives two servos directly
- Wokwi only (no ESP-NOW)
- Calibrates joystick center at boot
- Normalizes ±range to ±1.0 → maps to 0–180° around 90°
- Sends
angleX
/angleY
via ESP-NOW to a specific MAC
- Listens for ESP-NOW messages
- Parses
angleX
/angleY
- Drives servos on GPIO 14/15
- Serial debug output
- Standard ESP32-CAM "CameraWebServer" sketch
- Streams MJPEG to a browser
- Provided by Arduino IDE's ESP32 boards package
-
ESP-NOW: Low-latency, peer-to-peer, no router needed
-
Three ESP32-CAM MCUs:
- Master (joystick sender)
- Slave (servo head)
- Camera streamer (IDE example)
[env:master]
platform = espressif32
board = esp32cam
framework= arduino
src_dir = src
[env:slave]
platform = espressif32
board = esp32cam
framework= arduino
src_dir = src
- Yvx