Arduino Projects: Arduino DC motor control

Lots of beginners are having some issue with connecting a motor to the Arduino board. Some even try to connect the motor directly to the board’s pins. huge fail. Do not do this! That would likely damage your Arduino Board  regardless of the size of the motor.

The maximum current that the Arduino can supply is 20 mA and the smallest motor can easily draw 100 mA. That would be a way to kill the Arduino board in no time flat.

In this project, I will show you how you can use a simple and cheap transistor to control your motor. This will be just a simple circuit not a fully functional H bridge.

Arduino DC motor control

Here are the part needed:

First, the wiring part.

Make sure that the transistor is connected correctly. If you do not have the BC547 you can use a different NPN transistor, just make sure its maximum voltage and current are sufficient enough for your motor.

You can also experiment with the resistor value, for me 47 kΩ works the best. There are some formulas to calculate those values, but you should measure some values with a special multimeter and it can be hard for beginners to make.

The program for this project is super simple, just two for loops to slowly turn ON and OFF the motor using PWM (Pulse Width Modulation). This project is more about hardware than software, that’s the reason why code is so simple.

void setup() {
//declaring pin 13 as output to control transistor
pinMode(13, OUTPUT);

}

void loop() {
//slowly increasing the PWM signal on the transistor base
for(int a = 0; a < 255; a++){
analogWrite(13, a);
delay(10);
}
//slowly decreasing the PWM signal on the transistor base
for(int a = 255; a > 0; a--){
analogWrite(13, a);
delay(10);
}

}

Here is how our motor works.

 

That’s the cheapest way to control your motor and you can use it for your robotic projects.

tchouken2

Related Posts