Introduction: Arduio Dc Motor Speed Control Serial Monitor ..(no L293d)
This instructable will show you how to control the speed of a dc motor with PWM pins of arduino and serial monitor.
Step 1: Part List
1) Arduino uno
2) small dc motor
3) 270ohms resistor or 220ohms or 330 ohms( anything bellow ik and above 220 will do).
4) Rectifier diode
5) Bc547 or any NPN transistor
6) breadboard
7) Jumper wires
Step 2: Connecting the Transistor,Diode,Resistor and the D.C.motor
NOTE: place the transistor on the breadboard in such a way that the flat side faces you or the curved side faces away from you.
1) Connect the transistor's Collector to GND
2) Connect the transistor's Base to a 270ohm resitor and connect the resistor's end to DIGITALPIN3 on the arduino.
3) Connect the transistor's Emitter to the diode's negative(where there is no line).
4) Connect the end of the diode(negative where there is a line) to any of the D.C.motor's PIN
5) Connect the Diode's positive to 5v.
6) Connect the D.C.motor's another PIN to the transistor's Emitter PIN.
Step 3: Breadboard Layout
Step 4: Arduino Code
void setup()
{
pinMode(3, OUTPUT);// where the motor is connected to
Serial.begin(9600);
while (! Serial);
Serial.println("Speed 0 to 255");
}
void loop()
{
if (Serial.available())
{ int speed = Serial.parseInt();
if (speed >= 0 && speed <= 255)
{
analogWrite(3, speed);//sets the motors speed
}
}
}
Step 5: THATS IT.
1) Upload your code.
2) Open the serial monitor.
3) Set it to no line ending.
4) Enter your HEX value from 0 to 255 and hit enter.
4 Comments
6 years ago
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
8 years ago
Line side of a diode or cathode side is negative. Anode side is positive. Is the diode acting as a fly back?
Reply 8 years ago
Sorry for the wrong and dangerous information... It's the opposite as shown in the instructable... i will edi thee instructable as soon as possible.. hope u liked it.
Reply 8 years ago
No worries. It's an interesting little circuit. A schematic would be a nice addition. So this is basically a pwm motor speed test whereas the input is a 0-255 and the output is observed at the motor. If you wanted to extend on the circuit, you could use a potentiometer on a input pin instead of reading from the serial monitor?