Arduino Control DC Motor Speed and Direction Using a Potentiometer

by RonFrtek in Circuits > Arduino

4064 Views, 3 Favorites, 0 Comments

Arduino Control DC Motor Speed and Direction Using a Potentiometer

Arduino Control DC Motor Speed and Direction using a potentiometer

In this tutorial we will learn how to use a L298N DC MOTOR CONTROL driver and a potentiometer to control a DC motor speed and direction.

Watch a demonstration video.

What You Will Need

41BWeFs+hHL.jpg
s-l640.jpg
pctdetail.775-114.1.jpg
F4O2K8LK54FYLTM.LARGE.jpg
F5OFEUQJJ4ZYFKY.LARGE.jpg
battery-pack.png

  • Arduino UNO
  • L298N DC MOTOR CONTROLER
  • DC Motor
  • Battery pack
  • Potentiometer
  • Jumper wires
  • Visuino program: Download Visuino

The Circuit

2020-02-22_17-36-30.jpg
  • Connect digital pin(2) from Arduino to motor driver pin (IN2)
  • Connect digital pin(3) from Arduino to motor driver pin (IN1)
  • Connect DC one motor to one side of motor driver
  • Connect Power supply (batteries) pin (gnd) to motor driver controler pin (gnd)
  • Connect Power supply (batteries) pin (+) to motor driver controler pin (+)
  • Connect GND from Arduino to motor driver controler pin (gnd)
  • Connect potentiometer pin (DTB) to Arduino Analog pin (A0)
  • Connect potentiometer pin (VCC) to Arduino pin (5V)
  • Connect potentiometer pin (GND) to Arduino pin (GND)

Start Visuino, and Select the Arduino UNO Board Type

FRWQB80K1RVKKV9.LARGE.jpg
F311FBVK5AHN5HJ.LARGE.jpg

To start programming the Arduino, you will need to have the Arduino IDE installed from here: http://www.arduino.cc/.

Please be aware that there are some critical bugs in Arduino IDE 1.6.6. Make sure that you install 1.6.7 or higher, otherwise this Instructable will not work! If you have not done follow the steps in this Instructable to setup the Arduino IDE to program ESP 8266! The Visuino: https://www.visuino.eu also needs to be installed. 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 AND Connect Components

2020-02-22_18-34-06.jpg

  • Add "Dual DC Motor Driver Digital and PWM Pins Bridge (L9110S, L298N)" component
  • Connect Arduino AnalogIn [0] to DualMotorDriver1mptors[0] pin [In]
  • Connect DualMotorDriver1 pin Direction[B] to Arduino digital pin [2]
  • Connect DualMotorDriver1 pin Speed[A] to Arduino digital pin [3]

Generate, Compile, and Upload the Arduino Code

FU1A0OGK5YP3LRO.LARGE.jpg
FNWTHBCK1RVKM7U.LARGE.jpg

In Visuino, Press F9 or click on the button shown on Picture 1 to generate the Arduino code, and open the Arduino IDE

In the Arduino IDE, click on the Upload button, to compile and upload the code (Picture 2)

Play

If you power the Arduino Uno module and add batteries for motor controller, the DC motor is ready to spin.

By sliding potentiometer you can regulate the motor speed and change the direction. The stopping point is in the middle of the potentiometer and if you slide it to the left it will go to one direction and if you slide it to the right it will go to another direction.

Congratulations! You have completed your Project. Also attached is the Visuino project, that I created for this Instructable. You can download it here and open it in Visuino: https://www.visuino.eu