Lesson Progress
0% Complete
The Motor Driver (L298N)
Objective: Connect the “Brain” (ESP32) to the “Muscles” (Motors) using the L298N Motor Driver.
1. Why do we need the L298N?
The ESP32 is smart, but it is weak. It can only output a tiny amount of current (about 20-40mA), while a BO motor needs about 200mA to 500mA to spin.
- The Bridge: The L298N acts as a high-power switch.
- Isolation: It protects your ESP32 from the electrical “noise” and high voltage of the motors.
- Direction Control: It uses an H-Bridge to flip the polarity of the electricity, allowing the motor to spin both clockwise and counter-clockwise.
2. Understanding the L298N Pins
Show the students the three main sections of the module:
- Power Terminals:
- 12V: Connect your 18650 battery positive (+) here.
- GND: Connect the Battery negative (-) and the ESP32 GND here (Common Ground).
- 5V: This can actually output power to turn on your ESP32.
- Output Terminals (The Muscles):
- OUT1 & OUT2: Connect to Motor 1.
- OUT3 & OUT4: Connect to Motor 2.
- Control Pins (The Logic):
- IN1, IN2, IN3, IN4: These pins receive signals from the ESP32 to tell the motors to go Forward, Backward, or Stop.
- ENA & ENB: Used with PWM to control the speed of the motors.
3. The Truth Table (How to Code it)
To move the robot, we must send specific HIGH/LOW signals to the Input pins:
| Movement | IN1 | IN2 | IN3 | IN4 |
| Forward | HIGH | LOW | HIGH | LOW |
| Backward | LOW | HIGH | LOW | HIGH |
| Left Turn | LOW | LOW | HIGH | LOW |
| Right Turn | HIGH | LOW | LOW | LOW |
| Stop | LOW | LOW | LOW | LOW |
4. Wiring the System
- Motors to Driver: Connect the wires from the Left Motor to OUT1/OUT2 and the Right Motor to OUT3/OUT4.
- Driver to ESP32: Connect IN1, IN2, IN3, and IN4 to four GPIO pins on your ESP32 (e.g., Pins 12, 13, 14, and 27).
- Power: Connect the 18650 battery holder to the 12V and GND terminals of the L298N.
- Common Ground: IMPORTANT: Connect a jumper wire from the L298N GND to the ESP32 GND. Without this, the robot will not move!
Required Materials for this Session
- L298N Motor Driver Module
- Assembled Chassis with BO Motors
- 18650 Batteries & Holder
- ESP32 & Extension Board
- Jumper Wires (Female to Male)
Presentation:
SC_RI_02__3_Motor Driver by Infinite Engineers