I just want to control stepper motor with Arduino mega and l289n.
this is what I did it.
this is the code what I use.
#include <Stepper.h>
const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution
// for your motor
// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);
void setup() {
// set the speed at 60 rpm:
myStepper.setSpeed(60);
// initialize the serial port:
Serial.begin(9600);
}
void loop() {
char read_data;
int i;
if(Serial.available())
{
read_data = Serial.read();
if(read_data =='1')
{
Serial.println("clockwise rotation");
for(i=0;i<400;i++) //control motor angle
{
myStepper.step(1);
delay(10); //control motor speed
}
}
else if(read_data == '2')
{
Serial.println("counterclockwise rotation");
for(i=0;i<400;i++) //control motor angle
{
myStepper.step(-1);
delay(10); //control motor speed
}
}
}
}
if you type 1 in serial monitor then turn clockwise rotation, and type 2 turn reverse.
actually I type 1 and 2 continuously then the l298n exploded!
when I typed 1,2, ... the motor operate as error robot. it looks like the motor try to rotate both clockwise and counterclockwise at the same time.
is it reason for burn?
and can I still use Arduino mega?
this is the motor data sheet
l298n datasheet
this is SMPS power supply
actually the wires make me confused. I thought that black and green are part of same coil. red and blue also do. did I misunderstood? did I wire it wrong? why green and red wire twisted.
after l298n passed away. I unplugged Arduino, turn off power supply.