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!
Step 1: What You Will Need
- Arduino UNO (or any other board)
- L298N DC MOTOR CONTROLER Driver
- DC Motor
- 1K ohm resistor for the button
- Jumper wires
- Visuino program Version 22.214.171.124: Download Visuino
Step 2: 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!
Step 3: 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  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]
Step 4: Start Visuino, and Select the Arduino UNO Board Type
The Visuino: https://www.visuino.com also needs to be installed. Download Free version or register for a Free Trial.
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
Step 5: In Visuino Add Components
- Add “Debounce Button” component
- Add “Timer” component
- Add “L298N” component
Step 6: 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
Step 7: In Visuino Connect Components
- Connect Arduino board Digital pin  to “Button1” pin [In]
- Connect “Button1“l pin [Out] to “Timer1” pin [Start]
- Connect “Timer1“l pin [Out] to “DualMotorDriver1” > “Motors pin [Enabled]
- Connect “”DualMotorDriver1” > Motors  Pin [Direction]” to Arduino digital pin
- Connect “”DualMotorDriver1” > Motors  Pin [Speed]” to Arduino digital pin Analog PWM
Step 8: 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.
Step 9: 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.