Wireless RC Car (ESP32 + ESP-NOW)
Independent project
ESP32 · Arduino C++ · ESP-NOW
An RC car driven by two ESP32s talking directly to each other over ESP-NOW, Espressif's peer-to-peer Wi-Fi
protocol (no router or network needed). One board reads the controls; the other turns each packet into
wheel commands.
- Compact packet: speed level, direction, and stick displacement are packed into one small
struct sent to the receiver's MAC address, keeping latency at 100 ms or less
- Differential steering: the receiver slows the inside wheel in proportion to stick
displacement and mirrors the command for the opposite-facing servo
- Event-driven: all control happens in the ESP-NOW receive callback (a small state switch on
direction), so the main loop stays empty; wheel speeds are returned through pointers
Packet format shared by both boards Transmitter_Demo.ino / Receiver_330.ino
// Must match on transmitter and receiver
typedef struct carInfo {
uint8_t speed; // 0: Slow. 1: Medium. 2: Fast.
uint8_t direction; // 0: Idle. 1: Forward. 2: Backward
int32_t displacement; // value between -2400 +2400
} carInfo;
// Transmitter: register the receiver as a peer, then send the struct
memcpy(peerInfo.peer_addr, broadcastAddress, 6);
esp_now_add_peer(&peerInfo);
esp_now_send(broadcastAddress, (uint8_t *) &carData, sizeof(carData));
Turning stick displacement into wheel speeds Receiver_330.ino
// Servo commands: 90 = stop; farther from 90 = faster
uint8_t forward[3] = { 120, 150, 180 };
uint8_t backward[3] = { 60, 30, 0 };
// Scale a wheel toward stop in proportion to how far the stick is pushed
uint8_t calculate_wheel_speed(int32_t xDisplacement, uint8_t speed, int32_t maxDisplacement) {
return speed - ((int16_t)speed-90) * ((float)xDisplacement/maxDisplacement);
}
// Mirror a command around 90 for the servo mounted the other way
uint8_t reverse_direction(uint8_t speed) {
return speed - ((int16_t)speed-90)*2;
}
void setSpeeds(uint8_t speed, uint8_t *leftSpeed, uint8_t *rightSpeed, uint8_t *direction, int32_t xDisplacement) {
if (xDisplacement<-100) { // Left turn: slow the left wheel
*leftSpeed = reverse_direction(calculate_wheel_speed((xDisplacement*-1), direction[speed], leftMax));
*rightSpeed = direction[speed];
}
else if (xDisplacement>100) { // Right turn: slow the right wheel
*leftSpeed = reverse_direction(direction[speed]);
*rightSpeed = calculate_wheel_speed(xDisplacement, direction[speed], rightMax);
}
else { // Straight
*leftSpeed = reverse_direction(direction[speed]);
*rightSpeed = direction[speed];
}
}