Go Down

Topic: Tachometer (RPM for a motor) with 28 BYJ 48 (Read 313 times) previous topic - next topic

SimonR

Hello guys,

I wanted to realize a tachometer for my bike. I have a 5V signal input, and with this signal I want to drive a stepper motor to indicate me the RPM of my motor.

I want the motor to move around 270° for the 5V input.

For that I bought a  28BYJ-48 5v (arround 4096 steps for the output) stepper motor which I drive with a ULN2003.

My configuration is like this :

Arduino Pin 8  : Motor pin Blue
Arduino Pin 9  : Motor pin Pink
Arduino Pin 10 : Motor pin Yellow
Arduino Pin 11 : Motor pin Orange

Many problems come to me.

I tried different king of librairies : Stepper.h, CustomStepper.h and AccellStepper.h but I have problem with every one.


To begin this is a test code with stepper.h library

Code: [Select]
#include <Stepper.h>
 
const int stepsPerRevolution = 64; //Input step
 
//Motor definition
Stepper myStepper(stepsPerRevolution, 8,10,9,11);
 
void setup()
{
 //Spped of the motor
 myStepper.setSpeed(60);
}
 
void loop()
{
 //4 moves of 90°
 for (int i = 0; i<=3; i++)
 {
 myStepper.step(-512);
 delay(2000);
 }
 
 //3 moves of 120°
 for (int i = 0; i<=2; i++)
 {
 myStepper.step(682);
 delay(2000);
 }
}


Problem with that : My motor turns only in one side. The 90° movement work well but for the other side the motor vibrates but doesn't move. I tried to move the pin (maybe wrong connection for the coils) but nothing change.


After that I tried the same simple example with the CustomStepper.h library


Code: [Select]
#include <CustomStepper.h> 
   
//Define motor
CustomStepper stepper(8,9,10,11, (byte[]){8, B1000, B1100, B0100, B0110, B0010, B0011, B0001, B1001}, 4075.7728395, 12, CW); 


   
void setup() 

 
  //Define a speed for motor 
  stepper.setRPM(14); 
  //Number of steps to the motor
  stepper.setSPR(4075.7728395); 

   
void loop() 

 
 
   if (stepper.isDone()) 
   { 
     //Intervalo entre acionamentos 
     delay(2000); 
    // Clockwise direction
     stepper.setDirection(CW); 
     //Rotation angle
     stepper.rotateDegrees(720.0); 
     
    } 
    stepper.run(); 

    if (stepper.isDone()) 
    { 
   
     delay(2000); 
    // CounterClockwise direction
     stepper.setDirection(CCW); 
     //Rotation angle
     stepper.rotateDegrees(360.0); 
     
    }

    stepper.run(); 
}
 

I remark that in clockwise direction, we need to double the angle rotation to have the angle that we need : If we want 90° we need to put 180°. In CounterClockWise direction it's fine. The fluidity of the movement is also better in CCW direction.

When I load this code, there is a random functionning. Sequence like that.

- 1 turn CW
- 1 turn CCW
- 1 turn CCW
- 2 turn CW
- 1 turn CCW
- 1 turn CW
- ETC ...

I wanted to manage simple application but I had a lot of trouble with this stepper. Does anyone as solution to just pilot this motor to position correctly.

Thanks a lot



MarkT

You have to connect the wires correctly - a stepper has two coils, A and B, and you need to sequence
them like
A+, B+, A-, B-  (or equivalent).  With unipolar motors like yours there's no easy way to work out
which of the 4 wires corresponds to which winding, and there are 24 ways to connect the wires,
16 of which will not work.
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

TomGeorge

Hi,
How are you providing power for the stepper.
If you are using the 5V from the controller it will probably be causing the arduino to reset.

What arduino are you using?

Tom.... :)
Everything runs on smoke, let the smoke out, it stops running....

MAS3

Hi.

As you can see from the replies above, tell all about your setup when asking questions.
Showing a diagram of how things are wired will also help (that is how you did wire it, not how you planned to wire it, pointing to some instructions found online).


Do you understand how the stepper motor works, and how it is controlled ?
Do you understand the possible settings of the stepper libraries in those sketches ?

It's no huge problem if you don't understand these things yet, but that would be the first things to solve.
It seems to me like you might be missing steps.
This could be caused by steps that are taken too fast.

You do know that that stepper has a gear attached, and that the number of steps per revolution you see is different from that of the actual motor.
Also tell the library the correct properties of your motor, i wonder if this is correct:
Code: [Select]
const int stepsPerRevolution = 64; //Input step
 
//Motor definition
Stepper myStepper(stepsPerRevolution, 8,10,9,11);


Have a look at "blink without delay".
Did you connect the grounds ?
Je kunt hier ook in het Nederlands terecht: http://arduino.cc/forum/index.php/board,77.0.html

SimonR

Hello guys,


Hi,
How are you providing power for the stepper.
If you are using the 5V from the controller it will probably be causing the arduino to reset.

What arduino are you using?

Tom.... :)
I'm providing power from an external power supply.

My arduino board is the UNO SMD model.

Concerning the declaration. I know that my motor  has a gear attached. The 64 for steps I declared concern the steps in entry. That why I put 64 instead of 4096 (64 steps * 64 (gear ratio)).

I put the sequence 8,10,9,11 to feed the coils with the sequence A+ / B+ / A- / B-

That's why I don't understand why it doesn't work properly.

TomGeorge

Hi,

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Can you please post a picture of your project?

Tom..... :)
Everything runs on smoke, let the smoke out, it stops running....

SimonR

Hi,

Actually I just found a problem. I opened the motor and one of the coil wire was cut. So I resoldered the wire and things work better.

The two library I was talking works. Now I will try to make some modifications and try the AccellStepper library to have a better fluidity.

SimonR

Hello guys !

I worked on my project during the weekend and I still have some trouble to fix.

There is my code :

Code: [Select]
#include <CustomStepper.h> 
   
// Pinout motor definition
CustomStepper stepper(8,10,9,11, (byte[]){8, B1000, B1100, B0100, B0110, B0010, B0011, B0001, B1001}, 4075.7728395, 12, CW); 

int value = 0;
int value_degree = 0;
int degree_rotation = 0;
int previous = 0;

int Signal = A0; 
   
void setup() 

  pinMode (Signal,INPUT);                    // Analog Input signal (0 to 5V)
  stepper.setRPM(14);                        // Motor speed
  stepper.setSPR(4075.7728395);              // Number of steps for a revolution (360°)

   
void loop() 
{   
 
 
  value = analogRead(Signal);               // Read analog value : return value between 0 and 1024
  value_degree = value*360.0L/1024L;        // Convert the value in angle. Depends of the angle max we want
 
  if (stepper.isDone()) 
  {
    delay(1000);
    if((value_degree > previous+2))        // Compare to previous+2 to avoid very little change
    {
      degree_rotation = value_degree-previous;
      stepper.setDirection(CW);
      stepper.rotateDegrees(degree_rotation);
    }
    else if(value_degree < previous-2)
    {
      degree_rotation = previous-value_degree;
      stepper.setDirection(CCW);
      stepper.rotateDegrees(degree_rotation);         
    }
  }
  stepper.run();

  previous = value_degree;


The major problem I had is the speed update. In this example I put a delay of 1s to update the analog input. But if I have big change on my analog input (for example 1v to 5V, so 4V gap) the motor will not move 288 degree but less.



I don't know how to fix it. Does anyone has an idea?

Thansk

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy