Arduio Dc motor speed control serial monitor


hi. 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 :

Résultat de recherche d'images pour "arduino"

1* Arduino uno
2* small dc motor
3* 270ohms resistor or 220ohms or 330 ohms.
4* Rectifier diode
5* Bc547 or any NPN transistor or 2N2222
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
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 :

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
}}}


EmoticonEmoticon