Quantity | 3+ units | 10+ units | 30+ units | 50+ units | More |
---|---|---|---|---|---|
Price /Unit | $11.15 | $10.92 | $10.58 | $10.13 | Contact US |
Arduino L298N Motor Drive Module H Bridge L298P Current Detection
Features:
- Motor drive voltage: external input: 3-35V, external input: 6-12V
- Logic terminal current: <30mA
- Drive current: 2A
- Drive peak current: 4A
- Max power: 25W
- Working temp: -25℃-130℃
- Can be directly used by pluging in ArduinoUNO、leonardo、mega2560, the programme has four pins on the mainboard:
PWMA:D5(~)pin
DIRA:D4 pin
PWMB:D6(~)pin
DIRB:D7 pin
Arduino reference code:
int E1 = 5; //PWMA
int M1 = 4; //DIRA
int E2 = 6; //PWMB
int M2 = 7; //DIRB
int Val = 0;
int ChangeValue = 20; //the speed value ,changevalue from 0-255
void setup()
{
pinMode(M1, OUTPUT);
pinMode(M2, OUTPUT);
}
void foward()
{
digitalWrite(M1,LOW);
analogWrite(E1, Val); //the speed value of motorA is 20
digitalWrite(M2,LOW);
analogWrite(E2, Val); //the speed value of motorB is 20
Val = Val + ChangeValue;
if (Val == 0 || Val == 255)
{
ChangeValue = -ChangeValue;
}
delay(100);
}
void back()
{
digitalWrite(M1,HIGH);
analogWrite(E1, Val); //PWM调速
digitalWrite(M2,HIGH);
analogWrite(E2, Val); //PWM调速
Val = Val + ChangeValue;
if (Val == 0 || Val == 255)
{
ChangeValue = -ChangeValue;
}
delay(100);
}
void loop()
{
foward();
delay(500);
back();
delay(500);
}