My motors dont work without PWM. Motor driver is L298N
More details required please
Please post your sketch and a schematic of your project. Hand drawn is good enough
Which Arduino are you using and how are the motors and Arduino powered ?
Post schematic, code!
Follow forum rules!
// Motor Pinout
int ena = 5;
int in1 = 6;
int in2 = 7;
int in3 = 8;
int in4 = 9;
void setup() {
pinMode(ena, OUTPUT);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
analogWrite(ena,255);
digitalWrite(in3, HIGH);
digitalWrite(in4,LOW);
}
void loop() {
}
Here's a diagram and the code. The water pump cannot have a PWM because it will weaken its power.
Oh and the battery is also connected with the LK298N too.
Also, my motor works if there is PWM
What exactly do you mean by with and without PWM ?
Please post example code of both situations
If you dont want to use PWM just wire both the enable pins to HIGH (Vcc).
Oh, that's why...
// Motor Pinout
int ena = 5;
int in1 = 6;
int in2 = 7;
int in3 = 8;
int in4 = 9;
int enb = 10;
void setup() {
pinMode(ena, OUTPUT);
pinMode(enb, OUTPUT);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(in3, OUTPUT);
pinMode(in4, OUTPUT);
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
analogWrite(ena, 255);
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);
analogWrite(enb, 255);
}
void loop() {
}
This works.
// Motor Pinout
int in1 = 6;
int in2 = 7;
int in3 = 8;
int in4 = 9;
void setup() {
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(in3, OUTPUT);
pinMode(in4, OUTPUT);
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);
}
void loop() {
}
This doesnt.
I assume that you copied this code from somewhere. There is nothing wrong with that but, as in this case, it often means that you do not understand how or why it works
Take this line of code, for example
analogWrite(ena,255);
Note the name given to the pin, ie ena. That sounds very much to me as though it is connected to the enable pin of motora on the controller. That pin is used to enable or disable the motor being controlled, ie turn it on and off. By using analogWrite() it can be turned on/off very rapidly at different on/off ratios to control the speed of the motor, so to set the motor permanently to full speed you can connecter the controller enable input HIGH
What is a "controller enable input"?
// Motor Pinout
int in1 = 6;
int in2 = 7;
int in3 = 8;
int in4 = 9;
void setup() {
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(in3, OUTPUT);
pinMode(in4, OUTPUT);
digitalWrite(in1, HIGH);
digitalWrite(in2, HIGH);
digitalWrite(in3, HIGH);
digitalWrite(in4, HIGH);
}
void loop() {
}
Would this work?
Pins ENA and ENB on your diagram
digitalWrite(ena, HIGH);
Is this what I have to do?
That should work and set motor A to full speed, or you could just wire the enable pin to 5V as suggested in reply #8
I connected ENA and ENB on 5V on a breadboard and changed the code to
// Motor Pinout
int ena = 5;
int in1 = 6;
int in2 = 7;
int in3 = 8;
int in4 = 9;
int enb = 10;
void setup() {
pinMode(ena, OUTPUT);
pinMode(enb, OUTPUT);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(in3, OUTPUT);
pinMode(in4, OUTPUT);
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);
}
void loop() {
}
It still doesn't work.
Did you disconnect the enable pins on the motor controller from the Arduino pins ?
Post a picture of the hardware setup.
Yes.