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 with two buttons.
Watch a demonstration video.
Step 1: What You Will Need
- Arduino UNO
- L298N DC MOTOR CONTROLER
- DC Motor
- Battery pack
- Potentiometer
- Jumper wires
- Two push buttons
- 2x 1K ohm resistor
- Breadboard
- Visuino program: Download Visuino
Step 2: The Circuit
- Connect Arduino Pin 5V to breadboard positive pin (red line)
- Connect Arduino Pin GND to breadboard negative pin (blue line)
- Connect button1 first pin to breadboard positive pin (red line)
- Connect button1 second pin to arduino digital pin 6
- Connect button1 second pin to resistor1
- Connect button2 first pin to breadboard positive pin (red line)
- Connect button2 second pin to arduino digital pin 7
- Connect button2 second pin to resistor2
- Connect resistor1 to breadboard negative pin (blue line)
- Connect resistor2 to breadboard negative pin (blue line)
- 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)
Step 3: Start Visuino, and Select the Arduino UNO Board Type
The Visuino: https://www.visuino.eu 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 4: In Visuino Add AND Connect Components
- Add “Dual DC Motor Driver Digital and PWM Pins Bridge (L9110S, L298N)” component
- Add “Speed and Direction To Speed” component
In the “Properties window ” set “Initial Reverse” to “True”
- Add “SR Flip-Flop” component
- Connect Arduino Board digital pin[6] to “SRFlipFlop1” pin[Set]
- Connect Arduino Board digital pin[7] to “SRFlipFlop1” pin[Reset]
- Connect Arduino Board AnalogIn pin[0] to “SpeedAndDirectionToSpeed1” pin[Speed]
- Connect “SRFlipFlop1” pin[Out] to “SpeedAndDirectionToSpeed1” pin[Reverse]
- Connect “SpeedAndDirectionToSpeed1” pin[Out] to “DualMotorDriver1” > Motors[0] pin [In]
- Connect “DualMotorDriver1” > Motors[0] pin [Direction(B] to Arduino board digital pin[2]
- Connect “DualMotorDriver1” > Motors[0] pin [Speed(A)] to Arduino board digital pin[3]
Step 5: 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 6: 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 by pushing the buttons.
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