Introduction: Arduino DC Motor Speed Control Potentiometer

Picture of Arduino DC Motor Speed Control Potentiometer

This instructable will guide you on how to controll the speed of a Dc motor with a potentiometer and an arduino...

Step 1: Part List

Picture of Part List

1) Arduino

2) D.C. motor

3) NPN transistor TIP120

4) Rectifier Diode

5) 3* 220 ohms resitors

6) 10K Potentiometer

7) Breadboard

8) Jumper wires

9) Green led

10) Red led

11) Computer with Arduino IDE

Step 2: Connect the Potentiometer

1) Connect the negative pin of the potentiometer to GNDPIN on the arduino.

2) Connect the signal pin of the potentiometer to AnalogPIN0 on the arduino.

3) Connect the positive pin of the potentiometer to 5VPIN on the arduino.

Step 3: Connect the Leds

1) Connect a 220ohm or any ressitor below 1komhs to the anode of the red led and connect the end of the resistor to DIGITALPIN8 on the arduino.

2) Connect the cathode of the red led to GNDPIN.

3) Connect a 220ohms resistor to the anode of the green led and connect the end of the resistor to DIGITALPIN9 on the arduino.

4) Connect the cathode of the green led to GNDPIN.

Step 4: Connect the Transistor,diode,resistor and the D.C.motor

1) Connect the BASE of the transistor to a 220ohms resitor and connect the end of the resistor to DIGITALPIN3 on the arduino.

2) Connect the COLLECTOR of the transistor to a negative of a diode and connect the end of the diode to GND.

3) Connect the EMITTER of the transistor to GND.

4) Connect a pin of the motor to 5v and another to negative of the Diode.

Step 5: TIP 120 NPN Transistor Pinout

Picture of TIP 120 NPN Transistor Pinout

Step 6: Breadboard Layout

Picture of Breadboard Layout

Step 7: Arduino Code

int analogInPin = A0;

int sensorValue = 0;

int outputValue = 0;

int transistorPin = 3;

void setup()

{

Serial.begin(9600);

pinMode(8, OUTPUT);

pinMode(9, OUTPUT);

pinMode(transistorPin, OUTPUT);

}

void loop()

{

sensorValue = analogRead(analogInPin)/4;

outputValue = map(sensorValue, 0, 1023, 0, 255);

analogWrite(transistorPin, sensorValue);

if (sensorValue >= 160)

{

//example

digitalWrite(8, HIGH);

digitalWrite(9, LOW);

}

else

{ digitalWrite(9, HIGH);

digitalWrite(8, LOW);

}

delay(10); }

Step 8: You're Done!!

Comments

QuestionsIns (author)2017-07-07

I might have read it wrong but the diode should go in parallel with the motor. Cathode (negative end) to voltage source (same connection motor pos) and anode (positive end) to the collector on the bjt. The diode provides a place for current to do when power is cut off. This circuit works (doesn't break) due to the low current, voltage, small motor, and durability of the arduino. A motor acts like an inductor and when current stops flowing an inductor tries creating a current, the current it creates has to go somewhere.

BENLochocki made it! (author)2016-03-19

what happens if you place the diode the wrong direction?

So, basically I built it (without the LEDs using an Arduino Nano) but...the motor is at constant speed.

Anyone an idea what went wrong?

Thx

QuestionsIns (author)BENLochocki2017-07-07

Switching the diode around shorts the transistor out. In other words it's almost like connecting the motor between voltage source and ground.

BENLochocki (author)BENLochocki2016-03-19

based on the attached schematic. That's how I understood the wiring. Might be wrong.

Ilovecars_mukut (author)2015-12-05

surya bhaii.....I have to do the same thing with my Raspberry Pi.....can u tell how to do?

Find me on fackebook

https://www.facebook.com/profile.php?id=100009289167675 and we will discuss there :D

Thanks for replying mate! I actually have been able to do this with my Raspi. Anyways, thanks for this lovely instructable!

acheide (author)2015-05-04

Another nicely done Instructable.

Thanks

Your feedbacks mean a lot :D

Surya Krishnakumar (author)2017-06-04

Hellow Friends :D Could you please spare some time and checkout my new instructable ? https://www.instructables.com/id/Simple-LM386-Powe...

Thanks a lot for all your support and appreciations. :D

NiallM9 (author)2017-05-23

does the voltage on the motor matter

cjspurs21 (author)2017-03-06

Hello sir. I have a question. We have a project called jar tester and it runs on a 24v dc motor. We want to control its speed but at the same time display the rpm accordingly. How can it be done sir? thanks ahead.

dimitrakis1992 (author)2016-11-06

Hello sir.I have a question.Why we use trnsistor,diode and resistor?If we use only the pot and the dc motor it doesn't work?What is the purpose of this?Thank you for your time i am newbie.Please answer.

Drask (author)dimitrakis19922017-02-28

Yes, it will work if you just hook one end of the motor to ground and the other to the PWM from the arduino, but then you are limited to the amount of power the arduino can source and run a chance of damaging the arduino.

Hooking one end of the motor to +V and using the transistor to allow power to flow through allows you to use any voltage and much higher current.

The diode prevents backflow when the motor turns off. It's usually not a problem with small toy motors, but with a heavy enough motor it will generate electricity as it is slowing down in reverse of the flow you were using to push it and can overload a circuit. It's just a good habit to get into.

The resistor is also just a good habit when working with motors.

SriramS21 (author)2016-12-08

can you please explain why we are using this line

sensorvalue=analogRead(analogPin)/4

Medo best (author)SriramS212017-02-16

this line of code must be without "/4"

wbarrows1 (author)2016-08-11

Correct me if I am wrong, but if I want a program on the arduino to control the speed of the motor, then the potentiometer is completely irrelevant? I say this, because another instructable shows how to control DC motor speed with a potentiometer, but no arduino. I'm not sure what is gained by directly controlling the motor speed using an arduino AND a potentiometer.

mistasage (author)wbarrows12016-10-13

If you want to control the speed of the motor without the potentiometer, you can replace:

sensorValue = analogRead(analogInPin)/4;
outputValue = map(sensorValue, 0, 1023, 0, 255);

with:

outputValue = 255; // stop=0-255=full speed

And, of course, you can programmatically set outputValue to whatever value you want based on the logic of your application.

giantpair (author)2016-08-04

It won't work probably because my motor is 12V. Now I need to try a
boost converter or find another way. I think I would use PWM via a
555-timer if I had one. Any thoughts? In update, I now have managed PWM via L298N motor driver and a potentiometer. In order to make the speed go really slowly and constant it seems I need to use either a step motor instead of a DC motor or use speed feedback on the DC motor. Just my understanding so far.

Chef CurryW (author)2016-01-15

im done c nul prout

Chef CurryW (author)Chef CurryW2016-01-15

lol

Chef CurryW (author)Chef CurryW2016-01-15

lol

NappaG made it! (author)2015-12-18

It works?

Which is always a nice surprise.

Gregted (author)NappaG2015-12-31

Great. Thanks. It works. Now I just have to get a servo to work and I am good. Thanks for posting.

About This Instructable

109,477views

73favorites

License:

More by Surya Krishnakumar:Arduino HCSR04 leds distance warnerArduino DC Motor Speed Control PotentiometerArduio Dc motor speed control serial monitor ..(no l293d)
Add instructable to: