Arduino Dc Motor Running For A Specific Time

About the project

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.

Project info

Difficulty: Easy

Platforms: ArduinoDFRobotSparkFunVisuino

Estimated time: 1 hour

License: GNU General Public License, version 3 or later (GPL3+)

Items used in this project

Hardware components

Resistor 1k ohm Resistor 1k ohm x 1
Breadboard (generic) Breadboard (generic) x 1
Jumper wires (generic) Jumper wires (generic) x 1
DFRobot Gravity:Digital Push Button (Yellow) DFRobot Gravity:Digital Push Button (Yellow) x 1
DC Motor, 12 V DC Motor, 12 V x 1
SparkFun Dual H-Bridge motor drivers L298 SparkFun Dual H-Bridge motor drivers L298 x 1

Software apps and online services

Visuino Visuino
Arduino IDE Arduino IDE

Story

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

1 / 7

  • 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

Step 2: Brought by PCBWay

1 / 2

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.

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 [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]

Step 4: Start Visuino, and Select the Arduino UNO Board Type

1 / 2

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

1 / 3

  • Add "Debounce Button" component
  • Add "Timer" component
  • Add "L298N" component

Step 6: In Visuino Set Components

1 / 4

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

1 / 2

  • 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]

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: https://www.visuino.eu

Schematics, diagrams and documents

Visuino File

Code

Visuino File

Credits

Photo of Ron

Ron

Arduino Developer

   

Leave your feedback...