Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.
Voltaat Arduino Ultimate Kit
120 min
Share

Control a motor Speed using Arduino and Potentiometer

The DC motor is widely employed in Robotics and electronics projects due to its popularity. To regulate the speed of a DC motor, there are multiple approaches available. In this particular project will employ the PWM method for controlling the motor's speed.

Project Video

Overview

In this tutorial, we will learn how to control the motor speed with a potentiometer and an Arduino, using the PWM technique.

Getting the Items

Arduino Uno R3 (Voltaat Version)
Get Item
Small DC motor RF-300
Get Item
2N2222 – NPN Transistor (3 pieces)
Get Item
Rotary Potentiometer
Get Item
Half-size Breadboard
Get Item
Jumper Wires - Male to Male (40 Pack)
Get Item

Steps

Wiring it Up

Connect the wires between the LDR and the Arduino and the LED as shown in the image below.

 

 

Connections from the Arduino to the breadboard:

 

  • Arduino 5v pin →breadboard 5v line

  • Arduino GND pin →breadboard GND line

 

Connections from the Rotary potentiometer to the Arduino:

 

  • potentiometer GND pin → Arduino GND pin

  • potentiometer out pin → Arduino A0 pin

  • potentiometer VCC pin → Arduino 5V pin

 

 

Connections from the NPN transistor:

 • NPN emitter pin →Arduino GND pin

  • NPN base pin(middle pin) → Arduino pin 3

 • NPN collector pin→ Motor first wire

Connections from the motor:

 • Motor first wire→ NPN collector pin

 • Motor second wire→ Arduino VCC pin (5V)

 

 

Coding

/*

Voltaat learn (http://learn.voltaat.com)

Link for full tutorial:

Tutorial: Control motor speed using Arduino and a potentiometer!

The purpose of this sketch is to control a motor speed with a potentiometer

and an Arduino, using the PWM technique.

Connections from the Arduino to the breadboard:

• Arduino 5v pin → breadboard 5v line

• Arduino GND pin → breadboard GND line

Connections from the Rotary potentiometer to the Arduino:

• potentiometer GND pin → Arduino GND pin

• potentiometer out pin → Arduino A0 pin

• potentiometer VCC pin → Arduino 5V pin

Connections from the NPN transistor:

• NPN emitter pin → Arduino GND pin

• NPN base pin (middle pin) → Arduino pin 3

• NPN collector pin → Motor first wire

Connections from the motor:

• Motor first wire → NPN collector pin

• Motor second wire → Arduino VCC pin (5V)

*/

int pwmPin = 3; // assigns pin 3 to variable pwm

int pot = A0; // assigns analog input A0 to variable pot

int c1 = 0;   // declares variable c1

int c2 = 0;   // declares variable c2

void setup()  // setup loop

{

 pinMode(pwmPin, OUTPUT);

 pinMode(pot, INPUT);  

}

void loop()

{

 c2= analogRead(pot);

 c1= 1024-c2;         // subtracts c2 from 1000 ans saves the result in c1

 digitalWrite(pwmPin, HIGH);

 delayMicroseconds(c1);  

 digitalWrite(pwmPin, LOW);  

 delayMicroseconds(c2);  

}

Testing it Out

Once you’ve uploaded the code to the Arduino board, you will find that you can control the motor speed with rotating the potentiometer.

Resources

No items found.