ESP32 Joystick Controlled Robot Using ESP-NOW Protocol & L298N Motor Driver
30-07-2025
π€ ESP32 Joystick Controlled Robot Using ESP-NOW Protocol & L298N Motor Driver
Wireless bot control with speed adjustment via joystick tilt
π Introduction
In this project, we built a wireless robot controlled via a joystick and two ESP32 boards using the ESP-NOW communication protocol. Unlike Wi-Fi or Bluetooth, ESP-NOW enables fast, peer-to-peer data transfer between ESP32 devices using MAC addresses, making it ideal for real-time robot control.
The robot’s movement and speed are controlled through analog joystick input, and an L298N motor driver handles motor driving on the receiving end.
π§ Hardware Used
Component
Description
2x ESP32
One for sending joystick data, one for receiving and controlling motors
Joystick Module
Outputs analog X/Y values
L298N Motor Driver
Dual H-Bridge to drive DC motors
Robot Chassis
With 2x DC motors
Jumper Wires + Power
Batteries or USB
π§ How It Works
β€ Communication Setup
The sender ESP32 reads the X and Y analog values from a joystick.
These values are sent via ESP-NOW protocol to the receiver ESP32.
The receiver ESP32 processes the data and controls the L298N motor driver using the L298NX2 library.
Speed is adjusted based on how far the joystick is pushed.
β€ Direction Mapping
Y-axis forward → robot forward
Y-axis backward → robot reverse
X-axis left/right → turn accordingly
Small movements result in low speed; full push gives max speed.
π‘ Setting Up ESP-NOW Communication
To communicate using ESP-NOW, both ESP32 boards need to:
Be in WiFi Station mode
Share the receiver’s MAC address
Be added as peers in the ESP-NOW network
Use this code on the receiver ESP32 to get its MAC ad
π οΈ Wiring Summary
Sender (Joystick to ESP32)
Joystick Pin
ESP32 Pin
VRx
GPIO 34
VRy
GPIO 35
GND
GND
VCC
3.3V
Receiver (ESP32 to L298N)
L298N Pin
ESP32 Pin
IN1
18
IN2
19
IN3
16
IN4
17
ENA
4 (PWM)
ENB
5 (PWM)
π₯ Demo Output
Forward push: robot moves ahead
Full tilt → max speed
Side push: turns left or right
Release joystick → bot stops
Tested delay: ~50ms for excellent real-time response
Use this code on the receiver ESP32 to get its MAC ad
/*
Rui Santos & Sara Santos - Random Nerd Tutorials
Complete project details at https://RandomNerdTutorials.com/get-change-esp32-esp8266-mac-address-arduino/
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files.
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*/
#include <WiFi.h>
#include <esp_wifi.h>
void readMacAddress(){
uint8_t baseMac[6];
esp_err_t ret = esp_wifi_get_mac(WIFI_IF_STA, baseMac);
if (ret == ESP_OK) {
Serial.printf("%02x:%02x:%02x:%02x:%02x:%02x\n",
baseMac[0], baseMac[1], baseMac[2],
baseMac[3], baseMac[4], baseMac[5]);
} else {
Serial.println("Failed to read MAC address");
}
}
void setup(){
Serial.begin(115200);
WiFi.mode(WIFI_STA);
WiFi.STA.begin();
Serial.print("[DEFAULT] ESP32 Board MAC Address: ");