In this tutorial, we will learn about how to use 5V DC motor with Arduino. The Arduino board will provide the current of 5V. So, if you want to use a 9V or 12V DC motor you have to use the motor drivers like: L293D or L298n.
DC stands for Direct Current motor. It is the most common type of motor. DC motor has two connections, 1 positive and 1 negative. If you give the positive side in +ve current and the negative side in -ve current, motor will move clockwise. And if tou give the positive side in -ve current and the negative side in +ve current, motor will move in anti-clockwise direction.
Components :
- Arduino Uno
- Jumper Wires
- DC motor
- L298n (motor driver)
- 9V battery
L298n :
It is a motor driver that is use to operate DC motor. We will set the direction pf motor and also set the speed of motors. We can drive 2 DC motors with L298n.
Circuit Diagram :
Code :
void setup() {
Serial.begin(9600);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
}
void loop() {
analogWrite(9,255);
digitalWrite(10, LOW);
digitalWrite(11, HIGH);
delay(5000);
analogWrite(9,180);
digitalWrite(11, LOW);
digitalWrite(10, HIGH);
delay(5000);
int x=0;
while(1){
if(x<255)
x++;
Serial.println(x);
analogWrite(9,x);
digitalWrite(11, LOW);
digitalWrite(10, HIGH);
delay(100);
}
}
Good day! I just want to offer you a big thumbs up for your excellent information you have got here on this post. Ill be coming back to your blog for more soon.