[Arduino] Speed control with DC Motor and Pot

Hi all,
simple way to control the speed of a DC Motor!

This is the first step to control a car!!!

You can turn potentiometer to control speed of your dc motor. When motor is too fast, RED led will light on!!

Here the scheme:
Arduino with DC Motor and Potentiometer

Components:
– 1 DC Motor
– 1 Potentiometer 10k
– 1 TIP120
– 1 diode (1N4001)
– 1 10kohm resistor
– 2 100ohm resistor
– 1 red led
– 1 green led
– arduino
– wires

Here a demo video:


Ref: albertopasca.it

Here the code:

[code lang=”cpp” autolinks=”false” collapse=”false” firstline=”1″ gutter=”true” htmlscript=”false” light=”false” padlinenumbers=”false” smarttabs=”true” tabsize=”4″ toolbar=”false”]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);
}[/code]

Ref: albertopasca.it

 

Alberto Pasca

Software engineer @ Pirelli & C. S.p.A. with a strong passion for mobile  development, security, and connected things.