Tutorial L298P Motor Driver and IR Sensor

by slametz in Circuits > Arduino

1509 Views, 1 Favorites, 0 Comments

Tutorial L298P Motor Driver and IR Sensor

L298P-Motor-Driver-Shield-Motor-Connections-1.jpg

L298P Shield DC motor driver use high-power motor driver dedicated chip L298P, can directly drive 2 DC motors, the drive current up to 2A. The motor output interfaces use 8 high-speed Schottky diodes as protect. It can be directly plugged into the Arduino. L298P Shield DC motor driver with PWM speed control mode and the PLL mode, using jumper to switch.


L298P Motor Driver Shield Pinout

This motor shield has various connection as follows:

Control of two DC motors connections:

  • VMS: Module voltage
  • GND: Ground
  • MA1: Positive end for motor A
  • MA2: Negative end for motor A
  • MB1: Positive end for motor B
  • MB2: Negative end for motor B
  • PWMA: Speed control signal for motor A – This pin is connected to pin 10 of Arduino
  • PWMB: Speed control signal for motor B – This pin is connected to pin 11 of Arduino
  • ENA: Control signal for motor A – If HIGH, motor is in direct mode and if LOW, motor is rotating in reverse. This pin is connected to pin 12 of Arduino
  • ENB: Control signal for motor B – If HIGH, motor is in direct mode and if LOW, motor is rotating in reverse. This pin is connected to pin 13 of Arduino

Buzzer for make sound:

  • BUZ: Buzzer pin – This pin is connected to pin 4 of Arduino

Connection for control servo motor:

  • SER: PWM pin for control servo motor – This pin is connected to pin 9 of Arduino

Bluetooth connections:

  • BT2: Bluetooth Pins including +(3.3V) pins, (GND), RX (connected to D0) and TX (connected to D1)

Ultrasonic sensor connection:

  • ULT: connection pins to ultrasonic sensor including +(5V), (GND), Return (connected to D9) and Trigger (connected to D8)

RBG LED connection:

  • RGB: RGB: For connection to RGB LED including pins B (connected to D6), G (connected to D5) and R (connected to D3)

Other connections:

  • A/D: Analog and digital pins A0 to A5 for sensor and module use
  • D2: Digital pin 2 for sensor and module use
  • RS: Reset pin
  • GND: Ground
  • VCC: Board power supply – 3V, 5V

You can see the pinout of this module in the image below.

Supplies

l298ir.jpg

Quantity

Arduino Uno +USB = 1

L298P Motor Driver = 1

WAG Cable

Motor Mini MetalGear N20 = 2

Battery 12V

IR Sensor = 2

Code

FTLPY63L79251WQ.jpg
FF805OCL79251VS.jpg

In this tutorial, you need to use this motor driver shield pins stacked on the Arduino Uno. Then, connect the two gear motor to the terminal block of MOTOR Right and MOTOR Left. IR Sensor Right Connect to pin 2 Arduino PWM dan IR Sensor Left to pin 3 Arduino PWM

int IR_Right  =2;
int IR_Left =3;


int E1 = 10;
int E2 =11;


void setup()
{
pinMode(E1, OUTPUT);
pinMode(E2, OUTPUT);




pinMode(IR_Right, INPUT);
pinMode(IR_Left, INPUT);




}
void loop(){
  int DetectionRight = digitalRead(IR_Right);
  int DetectionLeft  = digitalRead(IR_Left);


if(DetectionRight == HIGH)
{
     analogWrite(E2, 0);
}else{
     analogWrite(E2, 200); 
}


  if(DetectionLeft == HIGH)
{
     analogWrite(E1, 0);
}else{
     analogWrite(E1, 200); 
} 

}


Downloads

Code Version 2

/*BY SLAMET NURHADI 
MOTOR DRIVER L289P


The E1, E2 pins on the 2 motors's control chip with speed control function are
connected with the 10,11 interfaces,
*/
int BuzzerPin= 4;
int IR_Right  =2;
int IR_Left =3;


int E1 = 10;
int M1=12;


int E2 =11;
int M2=13;


void setup()
{
pinMode(M1, OUTPUT);
pinMode(M2, OUTPUT);




pinMode(IR_Right, INPUT);
pinMode(IR_Left, INPUT);




}
void loop(){
  int DetectionRight = digitalRead(IR_Right);
  int DetectionLeft  = digitalRead(IR_Left);


          if(DetectionRight == HIGH)
          {
               analogWrite(E2, 50);
               digitalWrite(M2, LOW);
          }else{
                analogWrite(E2, 300); 
                digitalWrite(M2, HIGH);
               
          }
          
            if(DetectionLeft == HIGH)
          {
               analogWrite(E1, 50);
               digitalWrite(M1, LOW);
          }else{
               analogWrite(E1, 300); 
                 digitalWrite(M1, HIGH);
          }   


}

Downloads

Video

L289P Motor Driver and IR sensor
Arduino Line Follower With L298P Motor Driver