Arduino DC Motor Running for a Specific Time
by RonFrtek in Circuits > Arduino
317 Views, 1 Favorites, 0 Comments
Arduino DC Motor Running for a Specific Time
In this tutorial we will learn how to rotate a DC motor for a certain time period and then with a push of a button repeat it again. In this tutorial we use 10s period but you can change it to any time.
Watch the Video!
What You Will Need
- Arduino UNO (or any other board)
- L298N DC MOTOR CONTROLER Driver
- Batteries
- DC Motor
- Button
- 1K ohm resistor for the button
- Breadboard
- Jumper wires
- Visuino program Version 8.0.0.84: Download Visuino
Brought by PCBWay
Thank you PCBWay for supporting this tutorial and helping users learn more about electronics.
NEW! Now you can get Aluminum PCB & FLEX PCB in their Special Offer!
What I like about the PCBWay is that you can get 10 boards for approximately $5 which is really cost effective for professional made boards, not to mention how much time you save!
Go check them out here. They also offer special discounts celebrating their 9th anniversary More info here.
The Circuit
- Connect Power supply (batteries) pin (gnd) to motor driver controler pin (gnd)
- Connect Power supply (batteries) pin (+) to motor driver controler pin (+)
- Connect Power supply (batteries) pin (+) to Arduino pin (VIN)
- Connect GND from Arduino to motor driver controler pin (gnd)
- Connect digital pin(3) from Arduino to motor driver pin (IN1)
- Connect digital pin(4) from Arduino to motor driver pin (IN2)
- Connect DC motor to the motor driver as you can see on the schematic
- Connect Arduino pin [5V] to breadboard positive pin [Red line]
- Connect Arduino pin [GND] to breadboard negative pin [Black line]
- Connect Arduino Digital pin [2] to the Resistor and button
- Connect other side of the resistor to the breadboard pin [GND]
- Connect Other pin of the button to the breadboard positive pin [5V]
Start Visuino, and Select the Arduino UNO Board Type
Start Visuino as shown in the first picture Click on the "Tools" button on the Arduino component (Picture 1) in Visuino When the dialog appears, select "Arduino UNO" as shown on Picture 2
In Visuino Add Components
- Add "Debounce Button" component
- Add "Timer" component
- Add "L298N" component
In Visuino Set Components
Select "Timer1" and in the properties window set "Interval (uS)" to 10000000 <<this 10 seconds, you can change this value if you want
Select "DualMotorDriver1" and in the properties window Expand "Motors" > "Item[ 0 ]" and select "Enabled" and click on the pin Icon and select "Boolean SinkPin" and set "Enabled" to False
Select "DualMotorDriver1" and in the properties window Expand "Motors" > "Item[ 0]" and set "Initial Value" to 1 or to 0 depends on the direction that you want, you can also adjust this value to change the speed
In Visuino Connect Components
- Connect Arduino board Digital pin [2] to "Button1" pin [In]
- Connect "Button1"l pin [Out] to "Timer1" pin [Start]
- Connect "Timer1"l pin [Out] to "DualMotorDriver1" > "Motors[0] pin [Enabled]
- Connect ""DualMotorDriver1" > Motors [0] Pin [Direction]" to Arduino digital pin[4]
- Connect ""DualMotorDriver1" > Motors [0] Pin [Speed]" to Arduino digital pin Analog PWM[3]
Generate, Compile, and Upload the Arduino Code
In Visuino, at the bottom click on the "Build" Tab, make sure the correct port is selected, then click on the "Compile/Build and Upload" button.
Play
If you power the Arduino module and press the button the Motor will start to rotate for 10s and if you press the button again it will repeat.
Congratulations! You have completed your project with Visuino. Also attached is the Visuino project, that I created for this Project, you can download it here and open it in Visuino: https://www.visuino.eu