Hi Everyone
im having problems driving a 12v motor with the l298n, when 12v supply is supplied to the l298n and the arduino is powered up the motor spins for just a second not even 2 seconds then stops. when i switch the supply off the motor spins the opposite direction for just a milli second then of. the motor voltage jumps from 0v to 4,12v then back to 0v. the code provided below is for arduino uno to test and practice using l298n but still the same thing.
int enA = 9;
int in1 = 8;
int in2 = 7;
void setup() {
// put your setup code here, to run once:
pinMode(enA,OUTPUT);
pinMode(in1,OUTPUT);
pinMode(in2,OUTPUT);
digitalWrite(in1,LOW);
digitalWrite(in2,LOW);
}
void loop() {
DirectionControl();
delay(1000);
speedControl();
delay(1000);
}
void DirectionControl()
{
analogWrite(enA,150);
digitalWrite(in1,HIGH);
digitalWrite(in2,LOW);
delay(2000);
digitalWrite(in1,LOW);
digitalWrite(in2,HIGH);
delay(2000);
digitalWrite(in1,LOW);
digitalWrite(in2,LOW);
delay(2000);
}
void speedControl()
{
digitalWrite(in1,LOW);
digitalWrite(in2,HIGH);
for(int i = 0; i < 256;i++)
{
analogWrite(enA,i);
delay(20);
}
for(int i = 255; i >= 0;i--)
{
analogWrite(enA,i);
delay(20);
}
digitalWrite(in1,LOW);
digitalWrite(in2,LOW);
}