Introduction: DC Motors and Arduino - Ways of Controlling
DC motors are very fun to play with. They can be used to make small cars or other little inventions that need some sort of rotation.
But there is a small problem with controlling them. They need lots of current. Arduino can't handle this amount of current so there is possibility of destroying the Arduino board. we need to be very careful when controlling DC motors.
Another problem is spinning in both directions. In this tutorial I will show you two easy ways to control DC motors with your Arduino board.
I also maded video, so you can check. All informations are in video also.
Check videt to see full tutorial: https://www.youtube.com/watch?v=cVQTWQ4eq6A
Yo will need:
- any Arduino board, i used Arduino Uno
- breadboard
- wires
- NPN transistor
- small DC motor (Large DC motors will not work, they need higher voltage than 5 V)
- L9110S H-bridge
Step 1: Where to Find DC Motors
DC motors can be found in broken toys. You can also find it in old CD or DVD drives or old cassette player. If you don't have these devices you can always buy DC motor on the internet.
Be sure to use small DC motors. Because larger motor needs more voltage.
In this tutorial i am using small DC motor that i finded in old CD drive. This motor was used to open and close door of CD drive.
Step 2: Control DC Motor Using Transistor
Easy way to control DC motor is to use transistor and arduino board. Transistor in this case is used as a switch.
For this you will need any NPN transistor. I am using 2N2222 transistor. Every transistor has a Base (B), emitter (E) and collector (C). Check data sheet of your transistor to identify C, B, E.
-Check picture to see how to connect, if you have problems check this video : https://www.youtube.com/watch?v=cVQTWQ4eq6A
-When motor is connected you will need arduino code. Just open your BLINK sketch and change blink PIN to PIN 9.
Because the base of the transistor is connected to PIN 9.
You should see that a motor is spinning when Pin 9 is HIGH.
Problem with controlling DC motor with transistor is that the motor can spin in only one direction.If you want to spin the motor in both directions you will need an H - bridge.
-Go to the next step to learn how to connect simple and cheap H-bridge module to Arduino.
Step 3: Controling Using Cheap L9110S H-bridge Module
This is cheap L9110S H-bridge module , you can find it on ebay.
It can control two dc motors or one stepper motor.
First, you need to connect motor to module, module have two sides (BIG GREEN CONNECTORS), connect your motor to the B side of the module.
You can use A side for another motor
Check picture for connecting instructions.
Upload this code to your arduino board and you will see that motor spins in both directions now (when pin9 is low and pin10 is high motor is spining in one direction, when Pin9 is high and pin 10 is low, motor is spining in other direction) there is also small delay 3 sec between.
void setup() {
pinMode(9,OUTPUT);
pinMode(10,OUTPUT); }
void loop()
{
digitalWrite(9,HIGH);
digitalWrite(10,LOW);
delay(3000);
digitalWrite(9,LOW);
digitalWrite(10,HIGH);
delay(3000);
}