Main Content

Raspberry Pi Pico and L298N Motor Driver

Control motors With Raspberry pi pico, L298N motor Driver and MicroPython.

Introduction
If you want to make a robot (such as Line Follower, Obstacle avoider, Arm Robot or Racing Robot) or a car using a microcontroller(such as Arduino, ESP8266, ESP32, Raspberry pi pico etc.), you use motors to make your robot move. The motors consists of many winding of copper wire inside a magnetic field. These motors require more power than a microcontroller can supply so you cannot drive or control motors using a microcontroller directly. This is because the microcontroller boards work on low voltage and consumes less power and their Input/Output pins cannot supply enough current to drive your motors. If you try to connect a motor directly to a microcontroller board input/output pin, your microcontroller board may stop working. To get rid of this problem you must use a proper motor driver to control the direction as well as the speed of rotation. You can use a BJT or FET as a motor driver but a single BJT or FET can control speed only not direction of rotation. For controlling speed as well as direction you need to use 4 BJTs or FETs in H bridge configuration. Due to usage of 4 BJTs or FETs in H bridge your circuit will become complex and bulky. To overcome this problem, we use motor driver IC. Inside a motor driver IC one and more H bridges are fabricated on a single chip so you can easily use it in your circuit. L298N and L293D are two motor driver ICs that are most popular for using in robots. You can use these ICs directly or can use an already assembled motor driver circuit which is also called as module.Here I am going to show you how you can control motors using L298N motor driver module and Raspberry pi pico(as a microcontroller board) using MicroPython programming language.After reading and understanding this article carefully one will be able to:

- Control motors easily using L298N module and MicroPython programming language.
- Make a robot easily using L298N and MicroPython programming language.
- Control motors with Raspberry pi pico.

Requirements

Hardware Requirements:

- Raspberry pi pico
- L298N motor driver module
- Bread board(Full size)
- Jumper wires(M-t-M and M-t-F)
- Wires with alligator clips
- 12V Battery
- Micro USB cable
- Gear motors(2)
- Screw driver
- Soldering Iron
- Soldering wire and paste
- Laptop or computer
- HC-05 Bluetooth module
- 10K potentiometer

Software Requirements

- Thonny(Python IDE for beginners).
- MicroPython Firmware for Raspberry pi pico.

L298N_motor.py MicroPython Module.
- https://github.com/ramjipatel041/Micropython-Driver-for-L298N-Motor-Driver.git

Theory
L298N Motor Driver Module:

This dual bidirectional motor driver, is based on the very popular L298 Dual H-Bridge Motor Driver Integrated Circuit. The circuit will allow you to easily and independently control two motors of up to 2A each in both directions. It is ideal for robotic applications and well suited for connection to a microcontroller requiring just a couple of control lines per motor. It can also be interfaced with simple manual switches, TTL logic gates, relays, etc. This board equipped with power LED indicators, on-board +5V regulator and protection diodes.

Specifications:

- Input Voltage: 3.2V~40Vdc. Brief Data:
- Driver: L298N Dual H Bridge DC Motor Driver
- Power Supply: DC 5 V - 35 V
- Peak current: 2 Amp
- Operating current range: 0 ~ 36mA
- Control signal input voltage range :
- Low: -0.3V ≤ Vin ≤ 1.5V.
- High: 2.3V ≤ Vin ≤ Vss.
- Enable signal input voltage range : o Low: -0.3 ≤ Vin ≤ 1.5V (control signal is invalid). o High: 2.3V ≤ Vin ≤ Vss (control signal active).
- Maximum power consumption: 20W (when the temperature T = 75 ℃).
- Storage temperature: -25 ℃ ~ +130 ℃.
- On-board +5V regulated Output supply (supply to controller board i.e. Arduino).
- Size: 3.4cm x 4.3cm x 2.7cm”

Link to article