DC motors are widely used in electronics and robotics projects due to their simplicity and effectiveness. Controlling the direction of a DC motor is an essential task in many applications such as robotic arms, car wheels, and conveyor belts. In this article, we’ll explore how to control the direction of a DC motor using an Arduino Uno, L293D motor driver, and push buttons.
Project OverviewThe goal of this project is to change the rotation direction of a DC motor using two push buttons. One button will rotate the motor clockwise and the other will rotate it in the opposite direction (anti-clockwise). The Arduino reads the button inputs and sends the appropriate signals to the motor driver, which then controls the motor's direction.
Required ComponentsArduino Uno board
- Arduino Uno board
L293D Motor Driver IC
- L293D Motor Driver IC
DC motor (5V to 12V)
- DC motor (5V to 12V)
Two push buttons
- Two push buttons
Two 10K ohm resistors
- Two 10K ohm resistors
Breadboard and jumper wires
- Breadboard and jumper wires
Power supply (9V battery or adapter)
- Power supply (9V battery or adapter)
The L293D is a dual H-Bridge motor driver IC that allows you to control the direction and speed of two DC motors. It works by receiving logic inputs from the Arduino and controlling the direction of current flow to the motor accordingly.
In this project:
Button 1 is used to rotate the motor clockwise
- Button 1 is used to rotate the motor clockwise
Button 2 is used to rotate the motor anti-clockwise
- Button 2 is used to rotate the motor anti-clockwise
The Arduino checks the state of both buttons. If Button 1 is pressed, the Arduino sends signals to the L293D to rotate the motor in one direction. If Button 2 is pressed, the signals reverse, causing the motor to spin in the opposite direction.
Circuit ConnectionsDC Motor: Connect the motor terminals to Pin 3 and Pin 6 of the L293D.
- DC Motor: Connect the motor terminals to Pin 3 and Pin 6 of the L293D.
Motor Inputs: Connect Pin 2 and Pin 7 of the L293D to Arduino digital pins (e.g., pin 8 and 9).
- Motor Inputs: Connect Pin 2 and Pin 7 of the L293D to Arduino digital pins (e.g., pin 8 and 9).
Push Buttons: Connect each push button to digital pins (e.g., pin 2 and 3) and use 10K pull-down resistors to prevent floating signals.
- Push Buttons: Connect each push button to digital pins (e.g., pin 2 and 3) and use 10K pull-down resistors to prevent floating signals.
Enable Pin: Connect Pin 1 (Enable) of L293D to 5V to enable motor movement.
- Enable Pin: Connect Pin 1 (Enable) of L293D to 5V to enable motor movement.
Power Supply: Connect a 9V battery or external power supply to power the motor, while the Arduino is powered via USB.
- Power Supply: Connect a 9V battery or external power supply to power the motor, while the Arduino is powered via USB.
The Arduino code uses digitalRead()
to detect button presses and digitalWrite()
to send HIGH or LOW signals to the L293D inputs.
Example Logic:
cpp
CopyEdit
if (digitalRead(button1) == HIGH) {
digitalWrite(motorPin1, HIGH);
digitalWrite(motorPin2, LOW);
}
else if (digitalRead(button2) == HIGH) {
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, HIGH);
}
cpp
CopyEdit
if (digitalRead(button1) == HIGH) {
digitalWrite(motorPin1, HIGH);
digitalWrite(motorPin2, LOW);
}
else if (digitalRead(button2) == HIGH) {
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, HIGH);
}
ApplicationsRobotic vehicles
- Robotic vehicles
Smart automation systems
- Smart automation systems
Electric wheelchairs
- Electric wheelchairs
Garage doors and gates
- Garage doors and gates
DIY rotating devices
- DIY rotating devices
This DC motor direction control project using Arduino is simple yet highly useful. It introduces you to interfacing input buttons, motor drivers, and controlling mechanical movement with microcontrollers. Once mastered, this knowledge can be extended to more complex applications such as remote-controlled cars, sensor-based motion, and programmable robotic arms.
Comments