
This project consists of building a four-wheel robot car controlled remotely using an ESP32 development board and an infrared (IR) remote control. The system is designed to receive infrared signals, process user commands, and control the movement of the robot car.
The infrared sensor KY-032 is used as the infrared receiver module in the system. When the user presses a button on the remote control, an infrared signal is transmitted and detected by the receiving circuit. The received signal is then processed by the ESP32 board to determine the requested movement.
The ESP32 controls the four DC motors through the L298N motor driver module. This module acts as a power interface between the ESP32 and the motors, allowing the board to control their rotation direction and speed.
Depending on the selected button on the remote control, the robot car can move forward, move backward, turn left, turn right, or stop. The ESP32 coordinates the operation of the motors to perform the requested movements.
This project provides an introduction to ESP32 programming, infrared communication, DC motor control, and motor driver applications in mobile robotics.

The ESP32 is the main control unit of the robot car. It receives the infrared signals from the receiver, processes the commands sent by the remote control, and generates the appropriate control signals to operate the motors. It also provides GPIO pins and PWM outputs for controlling the motor driver.

The L298N is a dual H-bridge motor driver used to control the four DC motors of the robot car. It receives control signals from the receiver ESP32 and regulates the direction and speed of the motors. Its two output channels allow the motors on the left side and right side of the car to be controlled independently.

The infrared remote control allows the user to operate the robot car wirelessly. By pressing different buttons, the user can send commands to control the car's movements, such as moving forward, moving backward, turning left, turning right, and stopping.

The KY-032 is an infrared sensor module used to detect infrared signals or nearby obstacles. In this project, it is intended to receive infrared signals and transmit its output through the OUT pin to the ESP32. The ESP32 uses the received signal to determine the required action.

The 5V/3.3V power supply module provides the appropriate regulated voltage to power the receiver ESP32 board and its associated electronic components

The four-wheeled car chassis provides the mechanical structure of the robot. It consists of four DC motors, four wheels, and a supporting frame. The motors allow the car to move forward, backward, turn left, and turn right.

Connecting wires are used to establish electrical connections between the ESP32 boards, joystick, L298N motor driver, motors, and power supply. They ensure the transmission of electrical signals and power throughout the system.

The two 3.7V rechargeable batteries provide the electrical power required to operate the robotic car. They supply energy to the L298N Motor Driver Module and the four DC motors, allowing the car to move autonomously according to the commands received from the sender ESP32.

The breadboard is used to connect and assemble electronic components without soldering. It facilitates the connection of the receiver ESP32 board to the 5V/3.3V power supply module and other electronic components. It allows students to build, test, and modify electronic circuits easily.

The 9V battery serves as the electrical power source for the system. It supplies power to the 3.3V/5V power supply module, which converts the 9V input voltage into two regulated output voltages: 5V and 3.3V. These voltages are used to power the various electronic components of the system.


The ESP32 board receives Bluetooth commands from the transmitter and controls the motors through the L298N motor driver module.
| L298N Module | ESP32 Board | Function |
|---|---|---|
| IN1 | GPIO 22 | Controls the first motor rotation direction |
| IN2 | GPIO 21 | Controls the opposite rotation direction |
| IN3 | GPIO 19 | Controls the third motor control input |
| IN4 | GPIO 18 | Controls the fourth motor control input |
| ENA | GPIO 23 (PWM) | Controls the speed of the left-side motors |
| ENB | GPIO 5 (PWM) | Controls the speed of the right-side motors |
| GND | GND | Common ground connection |
| L298N Outputs | Connected Components |
|---|---|
| OUT1 – OUT2 | Two motors on the left side |
| OUT3 – OUT4 | Two motors on the right side |
The two motors on each side are connected together to operate simultaneously. This configuration allows the robot car to move in different directions by changing the motors' rotation direction and speed.
| KY-032 Pin | ESP32 Pin | Function |
|---|---|---|
| VCC | 3V3 | Power supply for the module |
| GND | GND | Common ground |
| OUT | GPIO 15 | Detection signal output |
The OUT pin transmits the infrared detection signals received by the module to the ESP32 board.
| Component | Connection | Function |
|---|---|---|
| 9V Battery | Power supply module input | Main energy source |
| Power Supply Module | 5V output | Supplies power to the ESP32 board |
| Two 3.7V Batteries | L298N motor power input | Supplies power to the motors |
| GND of the different modules | Common ground | Provides a common electrical reference |
Before starting the programming process, it is necessary to complete the following steps:
1. Install the MicroPython firmware: Download and install the esp32-20210902-v1.17.bin firmware on the ESP32 board.
2. Import the IR library: Download the ir_rx.py file and add it to the ESP32 board's files. This library allows the board to receive and decode the infrared signals transmitted by the remote control.
Cette personnalité vous plaît-elle ?
This program controls a four-wheel robot car using an ESP32 board, an infrared (IR) remote control, and an L298N motor driver module. It is written in MicroPython and uses the NEC infrared communication protocol to receive and decode commands transmitted by the remote control.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# Import the required libraries from machine import Pin, PWM from ir_rx import NEC_16 from DCMotor import DCMotor # Define the PWM frequency used to control the motors frequency = 15000 # Configure the ESP32 GPIO pins # These pins control the rotation direction of the motors pin1 = Pin(22, Pin.OUT) pin2 = Pin(21, Pin.OUT) pin3 = Pin(19, Pin.OUT) pin4 = Pin(18, Pin.OUT) # Configure PWM pins to control the motor speeds enable = PWM(Pin(23), frequency) enable1 = PWM(Pin(5), frequency) # Create objects representing the two DC motors # Each motor is controlled by two direction pins and one PWM pin dc_motor = DCMotor(pin1, pin2, enable, 350, 1023) dc_motor1 = DCMotor(pin3, pin4, enable1, 350, 1023) # Dictionary mapping infrared codes to remote control buttons # Each hexadecimal code corresponds to a specific button ir_key = { 0x45: 'POWER', 0x46: 'MODE', 0x47: 'MUTE', 0x44: 'PLAY', 0x40: 'PREV', 0x43: 'NEXT', 0x07: 'EQ', 0x15: 'MINUS', 0x09: 'PLUS', 0x16: '0', 0x19: 'REPEAT', 0x0D: 'USB', 0x0C: '1', 0x18: '2', 0x5E: '3', 0x08: '4', 0x1C: '5', 0x5A: '6', 0x42: '7', 0x52: '8', 0x4A: '9' } # Initialize global variables ir_data = 0 # Code of the last received button ir_addr = 0 # Address of the transmitting device # Function automatically executed when an IR signal is received def ir_callback(data, addr, ctrl): global ir_data, ir_addr # Check whether a valid infrared code has been received if data > 0: ir_data = data ir_addr = addr # Check whether the received code exists in the dictionary if data in ir_key: # Display the button name and received signal information print("Button:", ir_key[data]) print("IR Code:", hex(data)) print("Address:", hex(addr)) # Control the motors according to the pressed button if ir_key[data] == "2": # Move the car forward dc_motor.forward(60) dc_motor1.forward(60) if ir_key[data] == "8": # Move the car backward dc_motor.backwards(60) dc_motor1.backwards(60) if ir_key[data] == "6": # Turn the car right dc_motor.forward(65) dc_motor1.backwards(65) if ir_key[data] == "4": # Turn the car left dc_motor.backwards(65) dc_motor1.forward(65) if ir_key[data] == "5": # Stop both motors dc_motor.stop() dc_motor1.stop() else: # Display the code if the button is not recognized print("Unknown IR Code:", hex(data)) # Initialize the NEC infrared receiver # The IR receiver output pin is connected to GPIO 17 ir = NEC_16(Pin(17, Pin.IN), ir_callback) # Display messages indicating that the system is ready print("IR Receiver Ready.") print("Waiting for remote control commands...") # Main loop executed continuously while True: # Check whether an infrared command has been received if ir_data > 0: # Get the button name corresponding to the received code command = ir_key.get(ir_data, "UNKNOWN") # Display the received command print("Received Command:", command) # Reset the variable to wait for a new command ir_data = 0 |
Educational robotics refers to the use of robots and robotics technology to promote learning in educational settings. It involves the integration of technology, engineering, and computer science into the classroom, allowing students to engage in hands-on, project-based learning experiences.
In this context, our website represents an excellent resource for parents, teachers and children who wish to discover robotics.
Zaouiet Kontech-Jemmel-Monastir-Tunisia
Robotic site created by Mohamed Ali Haj Salah - Teacher info