help with stepper..

Hello, Im trying to control a stepper motor from an old epson printer(EM-483 is the model of the stepper). I couldn't find the datasheet so i've measured the ohm of the coils and i found how to connect it. I connect it with a L298N bridge and i wrote the code above.

int motorPin1 = 2;
int motorPin2 = 4;
int motorPin3 = 3;
int motorPin4 = 5;
int delayTime = 0;

void setup() {
  pinMode(motorPin1, OUTPUT);
  pinMode(motorPin2, OUTPUT);
  pinMode(motorPin3, OUTPUT);
  pinMode(motorPin4, OUTPUT);
}

void loop() {
  digitalWrite(motorPin1, HIGH);
  digitalWrite(motorPin2, LOW);
  digitalWrite(motorPin3, LOW);
  digitalWrite(motorPin4, HIGH);
  delay(delayTime);
  digitalWrite(motorPin1, HIGH);
  digitalWrite(motorPin2, HIGH);
  digitalWrite(motorPin3, LOW);
  digitalWrite(motorPin4, LOW);
  delay(delayTime);
  digitalWrite(motorPin1, LOW);
  digitalWrite(motorPin2, HIGH);
  digitalWrite(motorPin3, HIGH);
  digitalWrite(motorPin4, LOW);
  delay(delayTime);
  digitalWrite(motorPin1, LOW);
  digitalWrite(motorPin2, LOW);
  digitalWrite(motorPin3, HIGH);
  digitalWrite(motorPin4, HIGH);
  delay(delayTime);
}

My problem is that i cant control the speed. If a use 0msec delay it's turning but if put a greater value than zero it turns a bit and stop and then again the same and the l298n getting very hot..im trying to solve this problem all day but i couldnt find a solution so any help would be appreciated.

Without a schematic showing how you hooked things up, it's almost impossible to give you any advice.

and the l298n getting very hot

It might surprise you to know this is nothing to do with your software. It is probably due to you feeding it too much current.

It sounds like it is wired up wrong.

Ok thanx for the answers im posting the schematic.

Apply ohms law to that 12v x 3.8 ohms = 3.15A That's why its getting hot it's probably a 1.5 - 2 volt stepper you need to use pwm to limit the current to drive it at higher voltages.

12v x 3.8 ohms = 3.15A

And remember that is just for one coil so in total you are taking 6.3A. Best bet is to feed the L298 with 5V or even smaller.

you need to use pwm to limit the current to drive it at higher voltages.

This can't really be done with the arduino directly. It is a technique used by stepping motor drive chips as part of a feedback loop to cut off the voltage when the current reaches a certain value.

It is probably this heat that is causing the motor to cut out, the L298 might be going into thermal shut down.

Thanks Mike I could of put that a bit better I've done loads of work with stepper motors.

Thanx for the answers. I still have that problem..i changed the supply to the stepper with 5v from an old pc PSU. Im trying this code now

#include <Stepper.h>

#define STEPS 100

Stepper stepper(STEPS, 2, 3, 4, 5);


void setup()
{

  stepper.setSpeed(100);
}

void loop()
{

  stepper.step(100);


}

the motor goes left-right all the time, sometimes it go for some seconds in one direction but later start again to go left-right very fast and as a result of this the bridge gets hot.. Any ideas of whats going on here? :-/

the l298n will do 4 amps in total that's 2 amps each phase with a heat sink its okay to run it at half the power without the heat sink else it will get hot and the internal thermal cut out will shut it off. I've ran that code you've posted and it works. try it at 1.5 - 2 volt I'm sure it will be okay have a look at my solid state H-Bridge I made without any current limiting I do have some current limiting chips that I got free from a place in weymouth I could send you one and we could try them together if you like I haven't used them yet here's my vid on you tube. Mach3 CNC + Arduino Driving a Discreet H-Bridge - YouTube