i have on a Arduino Uno connected sensor shield V5.0. From my L298N the pins are connected like this.
EnA on pin 11
EnB on pin 12
Input1 on pin 7
Input 2 on pin 6
Input 3 on pin 5
Input 4 on pin 4
Current voltage delivered by 4x 1,5V AA Battery.
My script looks like
#include <Servo.h>
//our L298N control pins
const int LeftMotorForward = 7;
const int LeftMotorBackward = 6;
const int RightMotorForward = 4;
const int RightMotorBackward = 5;
const int pwmRechts = 12 ; //initializing pin 12 as pwm
const int pwmLinks = 11 ; //initializing pin 11 as pwm
void setup(){
Serial.begin(9600);
pinMode(RightMotorForward, OUTPUT);
pinMode(LeftMotorForward, OUTPUT);
pinMode(LeftMotorBackward, OUTPUT);
pinMode(RightMotorBackward, OUTPUT);
pinMode(pwmRechts,OUTPUT) ; //we have to set PWM pin as output
pinMode(pwmLinks,OUTPUT) ; //we have to set PWM pin as output
}
void loop()
{
digitalWrite(LeftMotorForward, HIGH);
digitalWrite(RightMotorForward, HIGH);
analogWrite(pwmRechts,255) ;
analogWrite(pwmLinks,255) ;
digitalWrite(LeftMotorBackward, LOW);
digitalWrite(RightMotorBackward, LOW);
delay(1000);
digitalWrite(LeftMotorForward, LOW);
digitalWrite(RightMotorForward, LOW);
digitalWrite(LeftMotorBackward, HIGH);
digitalWrite(RightMotorBackward, HIGH);
analogWrite(pwmRechts,255) ;
analogWrite(pwmLinks,255) ;
delay(1000);
}
My problem is that nothing moving with this configurations.
But when i connect the EnA and EnB pins together with a bridge, Car is moving.
Can anyone help please
I don't understand.
To controll my motor speed, i should conect the two pins EnA and EnB to my sensor shield. But i don't know to which pin on my sensor shield. I tryed some pins from 0 to 13. Nothing works.
Exactly. When i conected together in the l298 then its works. Also i can change the speed.
So other question. When i conected the EnA and B in the L298 together how can i change my motor speed?
Befor it was possible with my variable
analogWrite(pwmRechts,255)
I copy it and changed it for my config, and its working only when i conect the two EnA/B pins togehter as bridge.
My target is to change also my speed with the sensor shield. How can o change this speed
So using pwm with the enable pin seems to be alright!
Sorry, to be a little more specific: You say if you bridge the enable pins, it works, ok? Where do you bridge? Did you try to connect just one of the pwm to both l298 pins?
That should work, of course. From what you have written, there is no obvious reason for the misbehavior.
It looks like a wiring or a power supply problem ... I suggest you look up the page I posted above and check you hardware setup carefully using the description, probably use the code to check one motor first, then the second and finally both.
Ok, i have tryed some more test. I have conect only one In1 from the L298 to the sensor shield and tryed so moved one tyre with analogWrite(LeftMotorForward,255); instat of digitalWrite(LeftMotorForward, HIGH);
I found that pin 3 and 5 is possible to rund the motor with controling the speed. Here i changed the value 255 to 150. So we can say that pin 3 and 5 is also a pwm pin on the sensor shield.
The next thing that i tryed is to conect the one of pin EnA from L298 to the pin 3 on the sensor shield which should pwm possible and conect the pin In1 from the L298 to pin 4 on the sensor shield and changed my script like this:
#include <Servo.h>
//our L298N control pins
//const int LeftMotorForward = 13;
//const int LeftMotorBackward = 11;
const int RightMotorForward = 4;
//const int RightMotorBackward = 5;
const int pwmRechts = 3 ; //initializing pin 12 as pwm
//const int pwmLinks = 11 ; //initializing pin 11 as pwm
void setup(){
Serial.begin(9600);
pinMode(RightMotorForward, OUTPUT);
//pinMode(LeftMotorForward, OUTPUT);
//pinMode(LeftMotorBackward, OUTPUT);
//pinMode(RightMotorBackward, OUTPUT);
pinMode(pwmRechts,OUTPUT) ; //we have to set PWM pin as output
//pinMode(pwmLinks,OUTPUT) ; //we have to set PWM pin as output
}
void loop()
{
//digitalWrite(LeftMotorForward, HIGH);
digitalWrite(RightMotorForward, HIGH);
//analogWrite(pwmRechts,255) ;
//analogWrite(pwmLinks,255) ;
//analogWrite(LeftMotorForward,255) ;
analogWrite(pwmRechts,255) ;
//digitalWrite(LeftMotorBackward, LOW);
//digitalWrite(RightMotorBackward, LOW);
//delay(1000);
//digitalWrite(LeftMotorForward, LOW);
//digitalWrite(RightMotorForward, LOW);
//digitalWrite(LeftMotorBackward, HIGH);
//digitalWrite(RightMotorBackward, HIGH);
//analogWrite(pwmRechts,255) ;
//analogWrite(pwmLinks,255) ;
//delay(1000);
}
And this is working also but...
the tyre is not running permanently. Ist run and stops for some seconds and run again. It seems that the sensor shield can not deliver the needed power for the motors.
I`m actually use 4x 1,5 AA Batteries. Could this be the reason why my motors not running permanently? Is it possible to use more Batteries Volt like 9 Volt Batterie?
Can we say that the sensor shield has not enough power to drive a motor?
Hi!
You are asking questions that you didn´t provide enough info for one to answer...
Where are the 4x1,5 AA batteries connected?
How are you powering Arduino?
How are you powering L298N?
Have you already succeeded moving the motors connecting the L298 pins directly to Arduino pins (without the Sensor Shield)?
Is there anything else connected to the sensor shield? (your code includes Servo.h library with no apparent reason)