2

I am trying to get the L298N to work with a simple DC motor.

For now, I have simplified the setup and the code to the basics to try to get it to work. I am using the following wiring setup with no button or pot: enter image description here

Only 1 motor, I am using a 2S lipo which I measured the voltage to be 7.8V which should be enough. The DC motor works when directly powered from the battery and when power with ~5V from an Arduino so I know it is not the issue.

My code, simplified from this tutorial: https://howtomechatronics.com/tutorials/arduino/arduino-dc-motor-control-tutorial-l298n-pwm-h-bridge/

#define enA 9
#define in1 6
#define in2 7

void setup() {
  pinMode(enA, OUTPUT);
  pinMode(in1, OUTPUT);
  pinMode(in2, OUTPUT);
  // Set initial rotation direction
  digitalWrite(in1, LOW);
  digitalWrite(in2, HIGH);
}
void loop() {
  analogWrite(enA, 255); // Send PWM signal to L298N Enable pin
}

I can measure the voltage at the input, it is good 7.8V. No voltage on motor output pins. In1 has voltage of 3.0V and In2 has 0V which corresponds to the code. However, Enable1 has 0V which doesn't make sense. So I attached the jumper for Enable 1 to give it the 5V, measured to confirm and still the motor is not working. I also tried a 2nd L298N with the exact same setup it and does not work. So I suspect it is something in my code or setup.

I feel like I am doing something stupid but I do not know what else to check. I checked continuity on the back of the board and it seems okay.

1
  • 1
    hint: you are mising a wire between the arduino and the L298N module
    – jsotola
    Dec 12, 2019 at 6:38

2 Answers 2

0

Give have to apply 5V to the 5V pin. The L298N's needs power supply for its logic circuitry, so you have: - voltage for the motor - voltage for the L298N - signal lines

3
  • Ah yes, this fixed the problem. Maybe I interpreted the tutorial wrong but it implied that for supplying a voltage greater than 7V the onboard regulator would supply the 5V for the logic circuity. Thanks! Dec 13, 2019 at 1:37
  • I though a regulator converts 12V into 5V and supply for logic, isn't it true? I confirmed 5V with a digital multi meter.
    – Watanabe.N
    Jan 27, 2021 at 14:30
  • 1
    @Watanabe.N L298N is only the H-bridge IC and it does not have a voltage regulator included, so you need to provide 5V yourself. Though, there are many different L298N modules and it's possible that some of those include a voltage regulator onboard
    – Sim Son
    Feb 1, 2021 at 13:36
2

I found this thread for a similar problem, I realized that my scratch (taken from here) wasn't able to works.. After many and many tries, I found that: the scratch works only using Serial Plotter, and not using Serial monitor.

In my case it was not necessary to connect 5vout of L298N with arduino, (clearly you need to connect ground to battery supply and to arduino ground too).

I don't know why the scratch works properly (make motors turn) only by Serial Plotter and it doesn't work by Serial monitor. I really would like to understand it!! (if someone could explain this oddity I would be very grateful).

Hope this could help.

UPDATE: I found why it doesn't work on Serial monitor.. In the serial monitor, by using:

int inByte = Serial.read();

you must select "no line ending".

:)

it's always human error!

NOTE: the 5V pin let to power Raspberry and this is it use. I don't know if that solution should be risky.. In the Datasheet it's said:

A non-inductive 100nF capacitor must be connected between this pin and ground

I searched about this solution on Raspberry but, after many readings, I just don't know if this could be a safe solution to power it. I can't suggest it as a secure way.

Your Answer

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

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