Full width home advertisement

Electronics Hub

Internet of Networks

Post Page Advertisement [Top]



Lets begin then!
Firstly, to achieve the control of the speed of your motor, you need to attach the potentiometer to your circuit.
You need:
  • An Arduino Uno
  • A breadboard
  • A transistor
  • A DC motor
  • A diode
  • A 10k ohm variable resistor
  • A 2.2k ohm resistor
  • Jump wires
dc motor speed control, arduino dc motor
Free Picture downloaded from unsplash.com

Explained, Step-by-Step

Find a space available on the breadboard and place your potentiometer. The central pin of the potentiometer must be connected back to pin 9 using a jump wire, and the remaining two pins will be connected to 5V on one side and GND (ground) on the other.
The 5V and the GND can be on either of the side of breadboard, however switching them will definitely invert the value that the potentiometer will be sending to the Arduino. Even though the potentiometer uses the same power and ground as the motor, note that they are different circuits and both communicates through the Arduino.
Once you have built the circuit, open a new Arduino sketch and save it with another memorable name, such as “ControlMotor”. Then type the following code:
int potPin = A0;
int motorPin = 9;
int potValue = 0;
int motorValue = 0;
void setup() 
void loop() 
 potValue = analogRead(potPin); 
 motorValue = map(potValue, 0, 1023, 0, 255);
 analogWrite(motorPin, motorValue); 
 Serial.print("potentiometer = " );    
 Serial.print("t motor = ");

After you’ve typing, save it and compile it by click the Compile button to underline any syntax errors occurred.
If the sketch (code) compiles it correctly, then click on Upload button to upload the sketch to your Arduino board. After uploading it, you should be able to empower your desirable motor by using the potentiometer. Turning the potentiometer in one direction provides an increasing speed in your motor; and turning it the other way may cause to slow it down.


This sketch is the variation on (Analog In, Serial Out) sketch and it works exactly in the same way changing few name to indicate better on what you are controlling and how are you monitoring the circuit.
As always, we declared the different set of variables used in the sketch. But, we used the potPin to assign the potentiometer pin and motorPin to send a signal to the motor. The potValue variable is used to store the raw value of the potentiometer and the motorValue variable stores the converted value that you want to output to the transistor to switch the motor.

int potPin = A0;
int motorPin = 9;
int potValue = 0;
int motorValue = 0;


You will find a soothing humming sound from your motor which will indicate that there is a minimum speed after which the motor will just hum. It does so because it doesn’t have enough power to spin. By monitoring the values sent to the motor using the MotorControl sketch, you can find the motor’s minimum value to turn and optimize the motorValue to turn the motor within its true range.

To find the range of motorValue, just follow these steps:

1. With the MotorControl sketch uploaded, click the serial monitor button at the top right of your Arduino window.
The serial monitor window will show the potentiometer value along with the output value that is sent to the motor, such as:

potentiometer = 1023 motor = 255

These values are displayed in a long list and also the values will be updated as you turn the potentiometer. If you don’t see the list scrolling down, make sure that the Autoscroll option is selected.

2. Start the potentiometer with reading a value of 0, and the turn potentiometer very slowly until the humming sound stops and the motor starts spinning.

3. Make a note of the value displayed at this point.

4. Will be better to use a “if” statement to command the motor to change speed limit only if the value is greater than its minimum speed needed to spin the motor, which is:

(a). Find the part of your code that writes the motorValue to the motor:

analogWrite(motorPin, motorValue);

(b). Replace it with the following piece of code:

if(motorValue > yourValue) {
 analogWrite(motorPin, motorValue);
} else {
 digitalWrite(motorPin, LOW);

5. Now replace yourValue with the number that you made a note of.

If the value motorValue is greater than that, the motor speeds up. If it is lower than that, the pin is written LOW so that it is fully off. You could also type the following code section analogWrite(motorPin, 0) to achieve the same thing. Miniature optimizations such as this can help the project function and run properly, with no tiresome movement or values.

No comments:

Post a Comment

Bottom Ad [Post Page]

| Designed by Sriparna Sarkar