This project introduces students to controlling a DC motor using an L298N motor driver module and an ESP32 microcontroller. The project will help students understand how microcontrollers interface with higher-power components using drivers, and how PWM signals affect motor speed.
ESP32 GPIO26 —> IN1 (L298N)
ESP32 GPIO25 —> IN2 (L298N)
ESP32 GPIO14 —> ENA (L298N, PWM control)
OUT1 & OUT2 —> DC Motor
L298N GND —> ESP32 GND
L298N 12V —> External Power Source
from machine import Pin, PWM
from time import sleep
# Define pins
in1 = Pin(26, Pin.OUT)
in2 = Pin(25, Pin.OUT)
pwm = PWM(Pin(14), freq=1000)
pwm.duty(0) # Start with 0% speed
# Move forward
def forward(speed=512):
in1.on()
in2.off()
pwm.duty(speed)
# Move reverse
def reverse(speed=512):
in1.off()
in2.on()
pwm.duty(speed)
# Stop motor
def stop():
in1.off()
in2.off()
pwm.duty(0)
# Main loop
while True:
print("Forward")
forward(800) # speed range: 0–1023
sleep(2)
print("Reverse")
reverse(800)
sleep(2)
print("Stop")
stop()
sleep(1)
You can explore a wide range of microcontroller and electronics projects, including Arduino, ESP32, IoT, and more. Each project comes with downloadable code, detailed guides, and the necessary hardware list.
You can explore a wide range of microcontroller and electronics projects, including Arduino, ESP32, IoT, and more. Each project comes with downloadable code, detailed guides, and the necessary hardware list.
You can explore a wide range of microcontroller and electronics projects, including Arduino, ESP32, IoT, and more. Each project comes with downloadable code, detailed guides, and the necessary hardware list.
You can explore a wide range of microcontroller and electronics projects, including Arduino, ESP32, IoT, and more. Each project comes with downloadable code, detailed guides, and the necessary hardware list.