DC Motor with Arduino:

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.

Dc motor

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.

L298n Pinout

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

1 Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

Facebook
YouTube
× Contact us