DC Motor Speed Control Using Arduino Nano and D12 Button
by devkrishnavhora in Circuits > Arduino
155 Views, 0 Favorites, 0 Comments
DC Motor Speed Control Using Arduino Nano and D12 Button
in this project, we control the speed of a 12V DC motor using an Arduino Nano, DESHBOT Shield with L293D motor driver, and a push button connected to D12.
Every time the button is pressed, the motor speed changes to the next level. The selected speed remains active until the button is pressed again.
Supplies
Arduino Nano
DESHBOT Shield
L293D motor driver
12V DC motor
Push button(integrated in Deshbot)
12V power supply
Connections
Push Button
- Button signal → D12
- Button → GND
The program uses INPUT_PULLUP, so an external resistor is not required.
Motor
- Motor driver input → D8
- Motor driver PWM → D9
- 12V motor → Motor output of the driver
- Motor power → Suitable 12V supply
Working
The D12 button is used to select different motor speed levels.
Every time the button is pressed, the Arduino moves to the next speed level:
Stop → Slow → Faster → Medium → Fast → Very Fast → Full Speed → Stop
The Arduino uses PWM (Pulse Width Modulation) on D9 to control the motor speed.
The PWM value ranges from:
0 → 255
A value of 0 means the motor is stopped, while 255 represents maximum PWM output.
Speed Level | Button Press | PWM Value | Motor Speed
------------|--------------|-----------|------------
0 | Start | 0 | Stop
1 | 1st Press | 130 | Slow
2 | 2nd Press | 160 | A Little Faster
3 | 3rd Press | 190 | Medium
4 | 4th Press | 220 | Fast
5 | 5th Press | 240 | Very Fast
6 | 6th Press | 255 | Full Speed
0 | 7th Press | 0 | Stop
Code Explanation
Button Setup
The D12 button uses the Nano's internal pull-up resistor. When the button is not pressed, the input reads HIGH. When pressed, it reads LOW.
Speed Selection
Every button press increases the speed level by one.
When the maximum level is reached:
the system returns to the stopped state.
PWM Speed Control
This sends the selected PWM value to D9 and controls the motor speed.
Button Debouncing
Downloads
Conclusion
This project demonstrates how an Arduino Nano and a push button can be used to control multiple motor speed levels. By using PWM, the motor speed can be changed without using a potentiometer. The project is a simple example of digital input, button debouncing, PWM, and DC motor control using an Arduino and L293D motor driver.