Arduino DC Motor Running for a Specific Time
2026-06-12 | By Ron Cutts
License: GNU Lesser General Public License Microcontrollers Motors Pushbutton PWM Arduino ESP32
In this tutorial, we will learn how to rotate a DC motor for a certain time period and then, with the push of a button, repeat it again. In this tutorial, we use a 10s period, but you can change it to any time.
Watch the video!
What You Will Need
Arduino UNO (or any other board)
1K ohm resistor for the button
Visuino program Version 8.0.0.84: Download Visuino









The Circuit
Connect the power supply (batteries) pin (gnd) to the motor driver controller pin (gnd)
Connect Power supply (batteries) pin (+) to motor driver controler pin (+)
Connect the power supply (batteries) pin (+) to the Arduino pin (VIN)
Connect the GND from the Arduino to the motor driver controller 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 the 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 the other side of the resistor to the breadboard pin [GND]
Connect the 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 in 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, depending on the direction that you want. You can also adjust this value to change the speed



In Visuino Connect Components
Connect Arduino board's 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 10 seconds, 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

