Go Down

Topic: Control stepper motor position with Hall sensor (Read 266 times) previous topic - next topic

PhoenixSheen

Good afternoon everyone  :D ,

I need help to control a unipolar stepper motor.
I confess I do not know anything about programming!
Basically, I'm trying to control the motor stop position with a hall sensor.
In fact, I will use 3 sensors for three different stop positions.
But I do not know if there is a command to stop the engine speed as soon as you change the signal of the hall sensor. It is possible?
Please, I really need help! If anyone can help I would be very grateful!

MarkT

Stepper motors are explicitly moved in steps - so if you stop stepping, its stopped.

Some stepper libraries allow setting a speed, but all allow explicit step-by-step movement.
Which library / example(s) have you looked at?
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

Robin2

In simple terms your code should do something like this
Code: [Select]
  move one step
  read the hall-sensor
  if you are not there yet, repeat


...R
Stepper Motor Basics
Two or three hours spent thinking and reading documentation solves most programming problems.

PhoenixSheen

Thank you for answering!

Allow me to elaborate:

In my project I will have 4 push buttons and 3 Hall sensors as signals.
4 push buttons combined allow 16 combinations, so each combination requires me to stop the motor at a different point.

I'm wondering, for example:

if (S1==HIGH && S2==HIGH && S3==LOW && S4==HIGH)

do [this is the command I do not know, a command that makes the engine rotate]

while [this is other command do not know, I thought the engine stopping when finding the Hall sensor signal in LOW level]

But do not know how to do ... :(

Thanks for your time!

PhoenixSheen

I will test this way:

#include <Stepper.h>

Stepper MP = Stepper(48, 10, 11, 12, 13);

int motorPin1 = 10;
int motorPin2 = 11;
int motorPin3 = 12;
int motorPin4 = 13;
int delayTime = 1;
int S1 = A5;
int S2 = A4;
int S3 = A3;
int S4 = A2;
int H1 = 5;
int H2 = 6;
int H3 = 7;

  void setup() {
  MP.step(1);
  pinMode(motorPin1, OUTPUT);
  pinMode(motorPin2, OUTPUT);
  pinMode(motorPin3, OUTPUT);
  pinMode(motorPin4, OUTPUT);
  pinMode(S1, INPUT);
  pinMode(S2, INPUT);
  pinMode(S3, INPUT);
  pinMode(S4, INPUT);
  pinMode(H1, INPUT);
  pinMode(H2, INPUT);
  pinMode(H3, INPUT);
}

    void loop() {
    S1 =digitalRead(A5);
    S2=digitalRead(A4);
    S3=digitalRead(A3);
    S4=digitalRead(A2);
    H1=digitalRead(5);
    H2=digitalRead(6);
    H3=digitalRead(7);
 
if(S1==HIGH && S2==HIGH && S3==HIGH && S4==HIGH) //0

{
  do
  {
    MP.step(48);
      digitalRead(H1);
  }
        while (H1==HIGH);
          delay(delayTime);
}


At least compiled :D

MarkT

No!  You have an infinite loop - you must call digitalRead() to sense any change, variables like H1 don't
change if you don't assign them new values.

Lose the while loop if you can, it blocks all the other logic in your program.
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

PhoenixSheen

#6
Oct 20, 2015, 12:51 am Last Edit: Oct 20, 2015, 02:51 am by PhoenixSheen
Oh my God, I do not know anything about programming and do not know what to do.

I was so happy and hope, would test right now.

I found that the variable H1 (Hall sensor) change when approaching the electromagnetic field.

Well, thanks for your time.

Robin2

#7
Oct 20, 2015, 10:27 am Last Edit: Oct 20, 2015, 10:28 am by Robin2
Oh my God, I do not know anything about programming and do not know what to do.
Look again at Reply #2 and think about how to include that concept in your program.

Post a link to the datasheet for your stepper motor and to the datasheet for your stepper motor driver board.

And please use the code button </>
Code: [Select]
so your code looks like this
 and is easy to copy to a text editor

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

PhoenixSheen

I'm sorry for not having used the code button
I would like to thank you for trying to help
I could make it work as I need
I will share, if someone else needs it one day:

Code: [Select]
if(S1==HIGH && S2==HIGH && S3==HIGH && S4==HIGH && H1==LOW) //0
{
  {
 while(digitalRead(5)==1);
    (MP.step(0));
  }
      delay(delayTime);
}
if(S1==HIGH && S2==HIGH && S3==HIGH && S4==HIGH && H1==HIGH) //0
{
  {
 while(digitalRead(5)==0);
    (MP.step(1));
  }
      delay(delayTime);
}

MarkT

#9
Oct 22, 2015, 09:48 am Last Edit: Oct 22, 2015, 09:50 am by MarkT
Code: [Select]

 while(digitalRead(5)==1);


This waits till pin 5 reads low.  the ';' is an empty statement to be looped.

What you meant is:
Code: [Select]

  while (digitalRead (5))   // note digitalRead () result is compatible with bool
  {
    MP.step (1) ;               // you must actually step at least one step!
    delay (delayTime) ;     // delay between each step to set the step rate to something finite.
  }
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

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