Skip to content

Control DC motor speed using potentiometer + L298n + Arduino

 



Hello there,

Welcome to this tutorial where we see how to control DC motor speed using a potentiometer, the L298n Dual H-bridge motor driver and an Arduino board.

First If you’re not familiar with this module you can watch my previous tutorial here’s a video about how to use the L298n Motor driver with Arduino, where I explain step by step how to control your DC motor: Step by step on how to use the L298n dual H-bridge driver with Arduino

If you’re already familiar we can start from this:

First, I’m just gonna wire the potentiometer (I used 10k) with the Arduino board and calibrate it to get the values from 0-255 so it’s adapted to our module. I added this step so you know that your potentiometer is working fine and also you are using the same Analog-digital coding bits.

Make sure to watch the video above as I explained my tutorial further.

Wiring 1:

Simple wiring of a potentiometer with an Arduino UNO board, any analog pin will do the job, just don’t forget to adapt the code.

Potentiometer wired with an Arduino Uno board



Code 1: Calibrating the potentiometer so it suits the values needed for the driver

This is the first code, it only uses the Arduino with a potentiometer wired as shown above, the serial monitor will constantly show the values (0-255), normally an analog input will give you values from (0-1023), but here we did a mapping of the values.

The code here could be cleaner if I used a “Map” function, but sometimes you forget about these things 😐

 

Wiring 2: Add the motor and its driver

L298n wired with Arduino and a potentiometer

I talked before about power and usage of the module please check the other tutorial.

Attention !

The analog pin of the L298n (EnA/EnB) should be used with an Arduino PWM pin.


Code 2:

After uploading the code test with the potentiometer and set the speed you want.

 

Yassine View All

Automation and Electrical Engineer, Electronics amateur trying to share my little projects.

14 thoughts on “Control DC motor speed using potentiometer + L298n + Arduino Leave a comment

  1. I want with two potentiometers to control the speed of one dc motor(one pot for forward and the other one for backward).How can i do this?

  2. Hello sir.I am the same guy.Can you please give me your mail.I dont have facebook.Thank you again.

    • Maybe you used ” void setup” more than once in the code, or maybe your sketch has multiple tabs if you drag sketch and put them in the IDE, you may need to create a sketch with one tab only

    • If you want to control the Start/Stop and direction, you can do it using some relays and contactors, check how it’s done (Electrical wirings…) then when controlling the relays you can do it by Arduino.
      If you want to control the speed too it can be a bit tricky, check how inverters work (generally AC-DC then DC-DC and DC-AC)

Leave a Reply

Discover more from SURTR TECHNOLOGY

Subscribe now to keep reading and get access to the full archive.

Continue reading