I am using a arduno mega with l298n and a motor. the l298n is powered with 12V power source and arduino mega is connected to laptop usb. now when I switch on the power supply the motor rotates for a instance like 1 rotation and then stops. when i reset the arduino board it again rotates for a instance and stops. i i keep the reset button pressed the mottor rotates. this is the code i am using.
const int IN1 = 8;
const int IN2 = 9;
void setup() {
// put your setup code here, to run once:
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
digitalWrite(IN1, HIGH); // Set IN1 HIGH
digitalWrite(IN2, LOW); // Set IN2 LOW
}
void loop() {
// put your main code here, to run repeatedly:
}
Show how your Arduino Mega, L298N, power supply are connected, with a clear picture and a drawing of the connections and pins. Get a close picture of the L298N, too.
If all your connections are correct, your sketch should be turning RIGHT in a circle, with the left motor (IN1) driving forward (HIGH) and the right motor (IN2) not driven (LOW).
The surge-then-stop is probably a bad connection... is the JUMPER for the VSS/VS inserted?