Arduio Dc Motor Speed Control Serial Monitor ..(no L293d)

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

Share

    Recommendations

    • Furniture Contest 2018

      Furniture Contest 2018
    • Tiny Home Contest

      Tiny Home Contest
    • Metalworking Contest

      Metalworking Contest

    6 Discussions

    0
    None
    waelpcb

    2 years ago

    please, when i was writting that command

    {int speed = Serial.parselnt();

    it showed me that error while verifing

    'class HardwareSerial' has no member named 'parselnt'

    please advice ASAP as i'm working on it with final steps

    1 reply
    0
    None
    Starbuck7410waelpcb

    Reply 1 year ago

    The command is int speed = Serial.parseint() with a capital i

    0
    None
    koz12

    3 years ago

    Line side of a diode or cathode side is negative. Anode side is positive. Is the diode acting as a fly back?

    2 replies
    0
    None
    Surya Krishnakumarkoz12

    Reply 3 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.

    0
    None
    koz12Surya Krishnakumar

    Reply 3 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?