Python Tutorials – Lesson 12 – L298N Motor Driver Module control single DC Motor using Raspberry Pi Pico
To control 1 DC motor with directional and speed control
Required Components
L298N Motor Driver Module_1 no
Raspberry Pi Pico_1 no
DC Motor(gear)_1 no
12V Battery_1 no
Data Cable_1 no
Connecting Wires_4 no
Circuit
Steps
Make sure the components are working properly.
Connect the 12V Battery to the L298N Motor Driver.
Connect the ENA, IN1, IN2 pins to the Raspberry Pi Pico board pins GP4, GP2, GP3 properly.
Connect the DC motor pins to the motor driver output pins.
Connect the ground connection respectively.
Check the Electrical Circuit.
Check the Python program.
Run the Python program.
Python Program
from machine import Pin
import utime
m1 = Pin(2, Pin.OUT)
m2 = Pin(3, Pin.OUT)
en1 = Pin(4, Pin.OUT)
en1(1) # motor 1 enable, set value 0 to disable
while True:
#Both Motor in forward direction
m1(1)
m2(0)
utime.sleep(1)
#Both Motor in Reverse direction
m1(0)
m2(1)
utime.sleep(1)
#Both Motor in stop position
m1(0)
m2(0)
utime.sleep(5)