ESP-NOW RC Car | Joystick Remote Control 👌🏻
We will use transmitter created using analog, joystick and esp32 board to send car control, commands, transmitter and receiver. Esp32 modules will communicate using esp now protocol car will be controlled in two modes: simple movement and throttle steering mode, so lets get started and make this car. If you havent subscribed, please hit subscribe button below, and press bell icon to get latest updates. Music lets first make the transmitter. We will need esp32 module, analog, joystick, 5v dc supply or any power bank breadboard, double sided tape and few jumper wires lets make a connection as per circuit diagram for transmitter. First, mount esp32 on breadboard Music attach joystick using double sided tape on breadboard Music connect, joystick to esp32 pins as per table Music. First, we need to get the mac address of receiver esp32 module for that connect, receiver, esp32 board to laptop and upload. This get mac address, code, select, sp32 rover module and port hit upload once uploaded open serial, monitor and press enable button on esp32. You can see that the mac address is printed note down this address, as we will use it in the code. Lets take a look at transmitter code now inside transmitter code. First, we need to include the esp now and wi fi library. Then we have defined pins for x, axis and y axis also defined, pin for switch. Then we have set receiver mac address as found in previous step. We have defined packet data structure to send data.
We have defined map and adjust joystick deadband values function which is used to map the values from 0 to 4095 to 0 to 254. Hence 127 is the center value to be sent. We have defined on data, send callback function which will be called when data is sent using esp now protocol inside setup function. Initialize the esp now now register the callback function. Then we need to setup the receiver peer info and add it to asp now set switch, pin as input pull up inside loop function. Read the x axis and y axis value. Read the switch value and see if it is pressed. If switch is pressed, its value will be low. We will use this value to move the car using throttle and steering mode. Now we will send the data through esp now using esp now send function. We will add some delay for data to be sent. The code link is provided in the description below you can upload it directly connect transmitter, esp32 module to laptop using usb cable, select, esp32, ruler, module and port hit. Upload Music now lets take a look at receiver. We will need 2wd car kit. This car kit comes with car, chases 2 tt gear motors, wheels front wheel, connectors and screws. We will also need esp32 module l298 motor driver module 7 to 12 volt battery. In our case, lipo 2s battery double sided tape and few jumper wires lets assemble the car. Now first lets solder wires to gear motors mount two motors on car chassis using connectors and screws Music attach front wheel now, Music Music attach wheels to car now.
Music now lets make a connection as per circuit diagram, Music fix l298 motor driver module on car chassis. Using double sided tape, connect right side motor to out one and out two pins of l298 and motor driver model. Now connect left side motor to out 3 and out 4 pins of motor driver model. Music fix esp32 module on car chassis using double sided tape. Now, connect l298 and motor driver module to esp32 pins as per table attach dc battery power connector to motor driver module to plus 12 volt pin and ground pin Music. We will take plus 5 volt and ground from l298 and motor driver module and provide to esp32 module through 5v and ground. Pin Music Music lets take a look at receiver code. Now. First, we need to install esp32 board using arduino board manager. I have provided the esp32 board link in the description below go to file preferences and add the esp32 board link then go to tools, then boards manager and search for esp32 and install it. Now we need to include the espnow and wi fi library. We have assigned the right and left motor pins. We have defined max motor speed as 200. Its max value can be 255.. You can change this as per your need. We have set the pwm frequency resolution and channel for speed. We have set the signal timeout. As 1000 milliseconds, we have created packet data structure to store the received values.
We have throttle and steering mode variable to check if car to be controlled, using throttle and steering mode. We have on data, receive callback function which will be called when esp32 receives data inside this function we will check. If switch is pressed. If pressed, then we will rotate the car based on throttle and steering mode. If throttle and steering mode variable is set, then we will call throttle and steering movement function else. We will call simple movement function in simple movement function based on x and y axis value. We will rotate the curve y axis value is used to rotate the car in forward or backward direction x. Axis value is used to rotate the car in left or right direction. We have throttle and steering movement function which is used to move the car using throttle and steering mode in this mode. We can steer the car while it is moving in forward or backward direction. We have created rotate motor function, which takes right and left motor speed. As arguments it will rotate the motor in forward or backward direction. We have created setup, pin mode function to set the motor pins as output also set the pwm channel for speed control. Initially stop all the motors inside setup function. We will call setup, pin mode function. Then init esp now it will set up on data, receive callback function inside loop function. We will check if signal is timed out. If no data is received within one second, then we will stop all the motors.
I have provided the link to the code in the description below you can upload it directly now lets upload the code connect sp32 module to laptop using usb cable, select, sp32 rover module and port hit upload Music now connect battery to car Music provide 5v supply using Power bank and usb cable thats it lets see how it works. As you can see, car is controlled using joystick. You can change the mode to throttle and steering by pressing the switch. Now you can see the car is controlled with throttle and steering Music. So we need to remember following points we need to provide proper power supply to this car. Please use only rechargeable battery hope.