3

I am trying to control a single DC motor using a L298N DC Motor Driver. I have a 12V motor plugged into Out1 and Out2, a 7.4 volt battery wired to the 12v in and common ground, a m/m common ground going from the arduino grnd to the L298N common ground, and I have IN1 and IN2 connected to digital pins 2 and 3. I am powering the Uno with USB. I am also running a m/m wire from the Uno 5v to the L298N (I shouldn't have to) in order to power the L298Nenter image description here

enter image description here

I am using a basic code to test the motor

    int motor1pin1 = 2;
int motor1pin2 = 3;

void setup() {
  // put your setup code here, to run once:
  pinMode(motor1pin1, OUTPUT);
  pinMode(motor1pin2, OUTPUT);
 
}

void loop() {
  // put your main code here, to run repeatedly:   
  digitalWrite(motor1pin1, HIGH);
  digitalWrite(motor1pin2, LOW);

  delay(1000);

  digitalWrite(motor1pin1, LOW);
  digitalWrite(motor1pin2, HIGH);

  delay(1000);
}

If I wire the 7.4v lipo battery directly to the L298N the red led doesn't go on. It only goes on when I run a 5V wire from the Uno to the L298N. Yet still I get no reaction out of the motor. However if I run a ground from the arduino directly to the out1 or out2, the motor turns in that one direction. Anyone have an idea what I am doing wrong?

2 Answers 2

1

I don't see any problem in your wiring and code. The only thing that's not exactly optimal is that the voltage provided by the battery is not just high enough. The L298N's supply voltage is supposed to be at least 2.5V above the logic supply voltage (the logic HIGH level to be precise). That would make 7.5V - you only have 7.4V.

That sounds like a tiny gap, but the battery voltage might drop further under load.

"run a ground from the arduino directly to the out1 or out2" - you should not do that as this can create a short circuit, depending on the state of the EN and IN pins.

2
  • According to my datasheet, the L298N only requires that the input voltage be above 6V when the 5V regulated output is being used - otherwise it is 5-35V
    – starship15
    Feb 8, 2022 at 19:36
  • It sounds like you don't have the +5V regulator output enabled, which means you DO need the +5V from the UNO. From the datasheet: "The module includes an onboard regulator. When enabled by the jumper, +5V is provided as an output. When disabled, a separate +5V input is required to control the logic level circuitry of this module"
    – starship15
    Feb 8, 2022 at 19:45
0

Assuming you have the ENABLE jumper in place to enable motor control, then you should be able to drive the motor full-speed forwards or backwards without the UNO code at all - just use the +5V and GND lines from the UNO as 'logic level probes'.

According to my logic table a LOW (GND) on L1 and a HIGH (+5v) ON L2 will cause a motor connected to OUT1/2 to rotate one way, and reversing the logic on L1/2 will cause it to rotate in the other - at full speed (full speed being whatever the battery supply voltage can provide).

Once you have the motor(s) turning properly, THEN you can add the complexity of trying to control the speed and direction programmatically. The code you showed does exactly the same as just using the +5 & GND leads as probes - with a 1 second delay between reversals.

Hope this helps

Frank

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.