Connect L298N IC to Arduino

Introduction: Connect L298N IC to Arduino

I recently got a L298N IC and I was searching the internet for connecting it with an arduino, but I found no tutorials that worked. I tried many options and finally found it. I hope you enjoy reading this!

Supplies

You will need the following components −

  • 1 × L298 bridge IC
  • 1 × DC motor
  • 1 × Arduino UNO
  • 1 × breadboard
  • 6 × jumper wires
  • 1 × 9v or more battery

Step 1: Fit the IC in the Breadboard

At first when you try fitting the IC to the breadboard it doesn't fit. As the pins are flexible you can adjust them to fit into the breadboard.

Step 2: Connections

Connection Steps:

1. Connect Logic supply voltage and the ground of the IC to 5V and the ground of Arduino, respectively.

2. Connect the motor to pins 2 and 3 of the IC.

3. Connect IN1 of the IC to pin 8 of Arduino.

4. Connect IN2 of the IC to pin 9 of Arduino.

5. Connect ENA of IC to pin 2 of Arduino.

6. Connect SENS A pin of IC to the ground.

7. Connect the 9V battery's positive to Supply voltage and the battery's negative with the ground you connected with the Arduino.

Step 3: Program the Arduino

The code for the Arduino is :

<p>const int pwm = 2 ; //initializing pin 2 as pwm<br>const int in_1 = 8 ;
const int in_2 = 9 ;
//L298 IC to choose the direction of the DC motor</p><p>void setup() {
   pinMode(pwm,OUTPUT) ; //we have to set PWM pin as output
   pinMode(in_1,OUTPUT) ; //Logic pins are also set as output
   pinMode(in_2,OUTPUT) ;
}</p><p>void loop() {
   //For Clock wise motion , in_1 = High , in_2 = Low
   digitalWrite(in_1,HIGH) ;
   digitalWrite(in_2,LOW) ;
   analogWrite(pwm,255) ;
   /* setting pwm of the motor to 255, we can change the speed of rotation
   by changing pwm output*/
   //Clockwise for 3 secs
   delay(3000) ;
   //For brake
   digitalWrite(in_1,HIGH) ;
   digitalWrite(in_2,HIGH) ;
   delay(1000) ;
   //For Anti Clock-wise motion - IN_1 = LOW , IN_2 = HIGH
   digitalWrite(in_1,LOW) ;
   digitalWrite(in_2,HIGH) ;
   delay(3000) ;
   //For brake
   digitalWrite(in_1,HIGH) ;
   digitalWrite(in_2,HIGH) ;
   delay(1000) ;
}</p>

Step 4: Result.

The motor will run first in the clockwise (CW) direction for 3 seconds and then counter-clockwise (CCW) for 3 seconds.

Be the First to Share

    Recommendations

    • Metal Contest

      Metal Contest
    • Fandom Contest

      Fandom Contest
    • DIY Summer Camp Contest

      DIY Summer Camp Contest

    2 Comments

    0
    seamster
    seamster

    1 year ago

    Good info, thank you for sharing : )

    0
    nieljosiah
    nieljosiah

    Reply 1 year ago

    You're welcome