Arduino Nano and L298n hbridge module

Hi All,
i am using arduino nano and l298 with 12V poer supply to control the speed and direction of two motors.Part of code is as under

int w, x, y, z;
int value;
void setup() {
  pinMode(A0, INPUT);
  pinMode(A2, INPUT);
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(6, OUTPUT);
  Serial.begin (9600);
}
void forward1(int value1) {
  digitalWrite(8, HIGH);
  digitalWrite(9, LOW);
  analogWrite(6, value1);
  digitalWrite(10, HIGH);
  digitalWrite(11, LOW);
  analogWrite(3, value1);
}
void loop() {
  w = (pulseIn (A2, HIGH));
  y = (pulseIn (A0, HIGH));
  if (y > 1700) {
    w = (pulseIn (A2, HIGH));
    value = map(w, 1085, 1910, 0, 255);
    forward1(value);
  }
}

I have connected PWM pin 3 and 6 to ENA and ENB of l298N and other 4 pins to IN1-4.The problem is with controling the speed.
When the w=1085 and value=0 the motor output is 0V and for w=1910, value=255 and motor output is 12V.These are right value BUT the problem is that between 0 and 255 i am not getting the right motor output.At value=1 motor output is 7V, but it is supposed to be maybe 0.2V. I want range from 0-12V but right now i am getting 7-12V output range.

I am stucked at this point.Your help will be appreciated.
Thanks

DON’T CROSS POST!!!
http://forum.arduino.cc/index.php?topic=545565
I HAVE REPORTED THIS THREAD TO THE MODERATORS

Please use code tags (</> button on the toolbar) when you post code or warning/error messages. The reason is that the forum software can interpret parts of your code as markup, leading to confusion, wasted time, and a reduced chance for you to get help with your problem. This will also make it easier to read your code and to copy it to the IDE or editor. If your browser doesn’t show the posting toolbar then you can just manually add the code tags:
[code]``[color=blue]// your code is here[/color]``[/code]
Using code tags and other important information is explained in the How to use this forum post. Please read it.

Please always do a Tools > Auto Format on your code before posting it. This will make it easier for you to spot bugs and make it easier for us to read. If you’re using the Arduino Web Editor you will not have access to this useful tool but it’s still unacceptable to post poorly formatted code. I recommend you to use the standard IDE instead.

Please remove unnecessary blank lines from your code before posting to the forum. One or two to separate code into logical sections is fine but large spaces for no reason or random blank lines just make for more scrolling when we’re trying to read your code.

Other thread removed.

pert:
DON’T CROSS POST!!!

Ok.Got it

I have modified my post.Can you please answer

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html t

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Can you please tell us your electronics, programming, Arduino, hardware experience?

Thanks.. Tom.. :slight_smile:

Have you tried a test program, which only does the forward1(value);? Forget the analog inputs and just do the output. Change value and measure the output voltage. Do you still get only 7 V - 12 V?

yes i have done that.Same result
I have also used other l298N but still getting same result

TomGeorge:
Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html t

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Can you please tell us your electronics, programming, Arduino, hardware experience?

Thanks.. Tom.. :slight_smile:

TomGeorge:
Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html t

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Can you please tell us your electronics, programming, Arduino, hardware experience?

Thanks.. Tom.. :slight_smile:

i have vast experience of circuits and programming.Please see the attached Picture with 1st post

When the w=1085 and value=0 the motor output is 0V and for w=1910, value=255

Ok, so all the w=1085 stuff has nothing to do with your problem. You can reproduce the error with a single line outputting something to the L298N. Then that is what we should help you with, not all the rest you show in the code.

What board are you using? Are you sure it does PWM on pins 3 and 6?

So are you getting all values between 7 V and 12 V? Smoothly, while you change the output from 0 to 255, step by step? 0 gives 7V, 64 gives 8.25 V 128 gives 9.5 V etc? Or does the 7 V correspond to output values from 0 to some 140?

Johan_Ha:
Ok, so all the w=1085 stuff has nothing to do with your problem. You can reproduce the error with a single line outputting something to the L298N. Then that is what we should help you with, not all the rest you show in the code.

What board are you using? Are you sure it does PWM on pins 3 and 6?

So are you getting all values between 7 V and 12 V? Smoothly, while you change the output from 0 to 255, step by step? 0 gives 7V, 64 gives 8.25 V 128 gives 9.5 V etc? Or does the 7 V correspond to output values from 0 to some 140?

yes 0 gives 0 1 gives 7 and so on
initally i was just checking the voltage at output without motors connected.Now i checked with all the connections,That problem has been solved but maximum voltage i am getting is 9.3V and the voltage at the input of motor driver is 11.7V.
Why i am getting less voltage at the output?

Hi,
Keep adding info in new posts, please don’t edit old ones.
OPs diagram.
0394304ef0aadc70fc7710ecf9719a9b5059e0ab.jpg
Have you got the gnd of the arduino connected to the gnd of the L298 SHIELD/MODULE.

What model shield/module is it?
Can you post a picture of the 298 and your project please?

Thanks…Tom… :slight_smile:

Hi Tom
i was checking voltages without motors connected to output terminals but when i connected motors the problem solved but a new problem arises
I am getting 9.3v output but the input to motor driver is 11.7V.I want to get 11.7V at output.
how is this possible?
i am using l298n and yes i have common ground

saad555:
I am getting 9.3v output but the input to motor driver is 11.7V.I want to get 11.7V at output.
how is this possible?

Look at the L298 datasheet.
~9.3volt on the motor on a 12volt supply is normal.

There are two losses in H-bridge mode. Vsat(hi) and Vsat(low).
They add up to 2,55volt (typical) at 1Amp motor current, and ~3.7volt@2Amp.

Modern mosfet based drivers can do much better than that dinosaur.
Leo..

For my 4 wheel robot I am using two 12V motors (120 rpm, torque unknown). Weight of robot is 3kg. Weight of each tyre is 290g and are made of vulcanised rubber. Motor driver is L298n.
One motor control one side of a robot (2 tyres) and 2nd motor controls the other side of the robot. 2 tyres of each side are connected with belt.
The robot moves backward and forward with no issue and at reasonable speed.
But the problem is that is does not make turn. For turn I am rotating motors in opposite direction. Motors do turn when the robot is in the hand but as I place it on the ground. It tries to turn but don't have enough power to rotate.
So what is the problem? Is it with the driver or with the torque of the motor? If it is with the driver plz suggest me some other driver
Thanks

It's the driver. Search on this site what people say about that driver. You will find suggestions for a better one.

3 kg robot is rather heavy and over 1 kg is in the tyres. And you don't know the torque of the motors. Try connect them directly to the 12 V source without driver or Arduino. See if it can rotate.

No total weight of the vehicle with tyre is 3kg.
And I just checked. Motors can easily be stopped with the hand and there is a voltage drop from 12.7 to 6.5V when motors are stopped by hand.
So is this the driver issue? If it is then plz name some other drivers.
I will be thankful for your time

saad555:
So is this the driver issue?

If it is then plz name some other drivers.

You have already been told that in your other thread.

You have to do the seaching, because we don't know which motors you have.
Find a driver that can handle the stall current of the motor.
Pololu.com could be a starting point.
Leo..

Hi,

2 tyres of each side are connected with belt.

You will need quite a bit of torque as you are trying a SKID TURN like tank tracks.
You have quite a significant contact surface with the belt.

Take the belts OFF and see what happens.

I would bin the 298 motor driver and get a decent MOSFET driver.

Tom.... :slight_smile:

Threads merged.

(I do grow tired of this, @saad555.)