L298n module not working

Hello! I am working on a steering wheel with force feedback that needed a motor and a motor controller that could rotate the motor in both directions at any speed. I picked the l298n to do the job, and it doesn't work. It isn't broken because I had a another one and the same thing keeps happening. Nothing works. The small red led doesn't turn on, the motor doesn't turn nothing. I changed the arduino and it still didn't work. Here is the schematic and the code:

image

#include "Joystick.h"

//X-axis & Y-axis REQUIRED
Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID,
                   JOYSTICK_TYPE_GAMEPAD, //JOYSTICK, GAMEPAD, MULTI_AXIS
                   4, 0,                     //Button Count, Hat Switch Count
                   true, true, true,         //X,Y,Z
                   false, false, false,      //Rx,Ry,Rz
                   false, false, false,      //Rudder,Throttle,Accelerator
                   false, false);            //Brake,Steering

Gains mygains[2];
EffectParams myeffectparams[2];
int32_t forces[2] = {0};

void setup() {
  pinMode(A3, INPUT);
  pinMode(10, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);

  //Joystick.setXAxisRange(0, 1023);
  //Steering wheel
  Joystick.setXAxisRange(0, 1023);
  //set X Axis gains
  mygains[0].totalGain = 100;//0-100
  mygains[0].springGain = 100;//0-100
  //enable gains REQUIRED
  Joystick.setGains(mygains);
  Joystick.begin();
  Serial.begin(9600);
  digitalWrite(8,HIGH);
  digitalWrite(7,HIGH);
analogWrite(10,25);
delay(50);
analogWrite(10,255);
delay(5000);
analogWrite(10,0);
  digitalWrite(8,LOW);
  digitalWrite(7,LOW);
}

void loop() {
  int value = analogRead(A3);
  //set X Axis Spring Effect Param
  //myeffectparams[0].springMaxPosition = 1023;
  //myeffectparams[0].springPosition = value;//0-1023
  //Steering wheel
  myeffectparams[0].springMaxPosition = 512;
  myeffectparams[0].springPosition = value - 512; //-512-512

  //Send HID data to PC
  //Joystick.setXAxis(value);

  //Recv HID-PID data from PC and caculate forces
  //Steering wheel

  Joystick.setXAxis(value);
  Joystick.setEffectParams(myeffectparams);
  Joystick.getForce(forces);
  if (forces[0] > 0) {
digitalWrite(6, HIGH);
digitalWrite(7,LOW);
    analogWrite(9, abs(forces[0]));
  } else {
digitalWrite(6, LOW);
digitalWrite(7,HIGH);

    analogWrite(9, abs(forces[0]));
  }
  Serial.println(digitalRead(7));
}

what are your pins connected to?
helpful names would be ENA, IN34

1 Like

How much is the voltage for DC motor?

1 Like

Is the 5V Enable jumper in place?

24 volts.

It is a bit different but pretty much the same. Pin 6 is connected to in4, pin 7 is connected to in3.Enb is of no use to me because I bridge it to max voltage using the included jumper.

Which one? I am using voltage above 12 volts and in the tutorials it said that to use it if you have 12 volts.

This is my second l298n. The first one died because of the motor inrush current, but while it was still working I was using the exact same schematic and code.

Then, so will the second and any L298N that you use.
What is the stall current of the motors?
What is the motor winding resistance?
If it draws more that 3A then you will burn out the L298N

Follow this tutorial to check that your UNO-Driver-Motor is ok.
1. Connect Motor 1 (M1) as per Fig-1.


Figure-1:

2. Operational/Programming Truth Table for M1 (Motor 1)

ENA  IN1  IN2      Function
5V   5V   0V       Forward Rotation
5V   0V   5V       Reverse Rotation
5V   PWM  0V       Variable speed at Forward Rotation

3. Test Sketch:(not tested)

byte data8 = 100;

void setup()
{
    pinMode(2, OUTPUT);
    pinMode(3, OUTPUT);
    analogWrite(9, 0);       //Motor 1 is Off
}

void loop()
{
    data8 = data8 + 5;
    analogWrite(9, data8);
    delay(1000);
}

4. Upload sketch of Step-3 and check that M1 is turing and speeding up slowly.

5. If M1 works, then check M2.

Yes all that is true, but it still doesn't work. The l298n just doesn't get power and it isn't broken.I bought an another l298n and still the same.

Post a picture showing connection details.

I used a higher power motor when it died. Before I used bit weaker one and it was fine.The first attempt I tried with the higher power motor it died. I switched to the weaker one. Now the inrush current is within limits

How do you know?

A picture of the schematic or?

Before I connected the motor to the l298n I did a test without the motor and yet nothing. There is no voltage between the motor lines.

You need to have a load connected.
Put a 1K resistor between the motor ouputs and measure the voltage

if not sure, you can provide power to the L298 module, put a voltmeter on the motor output and drive the Enable and IN pins to verify that the unit works, as well as the function of the control pins.

use @GolamMostafa 's table

1 Like

If you want to control motor "force" (torque), you have to control current (Amps) not volts.

If you want to control motor "force" (torque), you have to control current (Amps) not volts.

Can you explain how that helps @azur123123 diagnose his problem?