In this post, we are going to see how to controll DC motors using L293D motor driver IC and Raspberry Pi 4. L293D diver IC used here is capable of controlling two DC motors. Let's understand the circuit first and proceed with setup.
Components Required:
DC Motor (2)
Raspberry Pi 4 Model B (Note: with Raspbian OS installed)
L293D Driver IC
About L293D:
L293D is high-current half H-Bridge drivers. These are designed to drive inductive loads such as relays, solenoids, DC and bipolar stepping motors and other high-current and high-voltage loads. It gives output current of 600mA. The pin description is as follows.
Circuit Diagram:
How it works?:
From the above circuit diagram, the Raspberry Pi GPIO pins 18, 23, 24 and 25 have been connected with L289D driver inputs 2, 7, 10 and 15 respectively. This will inturn control the two motors connected with driver outputs 3 and 6 for motor 1 and driver outputs 11 and 14 for motor 2.
When active high is given to driver input 2 and active low to driver input 7, the motor will rotate in clockwise direction. When the inputs were reversed, the direction of rotation will be anti-clockwise. The below table describes how to controll the forward, reverse, left and right direction of the wheels of robotic car using the above logic.
When GPIO 18 is given active high, then motor 1 will rotate in clockwise direction. Consider moter 1 is our left wheel. If left wheel rotates in clockwise direction and motor 2 is off, then RC car will turn right. And if right wheel rotates in clockwise direction i.e. active high input in GPIO 25 and motor 1 is off, then RC call will turn left.
When both GPIO 18/GPIO 25 are active high and GPIO 23/GPIO 24 are active low, then both the motors will rotate in clockwise direction and the RC car will move in forward direction. When both GPIO 23/GPIO 24 are active high and GPIO 18/GPIO 25 are active low, then both the motors will rotate in anti-clockwise direction and RC car will move in reverse direction.
This is just a setup of connecting to motor driver and we are not sending the control signals from Raspberry Pi yet. The python flask application to control the motor will be explained in the next part.
(Note: This can be done using cheap microcontrollers and Raspberry Pi has been selected for learning the functioning of Raspberry Pi processor and further enhancements.)
Comments