A3144 Hall effect sensor won't detect LOW in while loop - (if button high, start motor, while hall is high)

Hello there,

my testproject in general:

A RF Remote sends a signal to a RF Receiver to an Arduino, this trigger a 24 byj 48 stepper motor and the motor should spin, while the a3144 hall effect sensor signal is high.

RF signal is pulled down by resistor.
Hall effect sensor signal is pulled down by resistor.

THE PROBLEM:

The arduino won't detect when the hall sensor signal is low (when a magnet enters) if the condition is in a while true loop.
I plotted out the serial signal and everytime the rf remote is pressed (going high) the monitor output of the hall sensor signal breaks down for some reason.

Here the code that won't work:

//motor pin setup
const int dirPin = 3;
const int stepPin = 2;
//const 

// RF RC pin setup

const int buttonPinA = 6;  // lauter Knopf


const int digitalHallLeft = 4;     //linker Hall sensor setup


// RF RC state setup
int buttonStateA = 0;  


int digitalHallLeftState = 0;


void setup() {
  // Declare pins as Outputs
  pinMode(stepPin, OUTPUT);
  pinMode(dirPin, OUTPUT);
  pinMode(digitalHallLeft, INPUT);

   Serial.begin(9600);

}
void loop() {

// Überprüfung der LOW / HIGH States  
Serial.print(digitalRead(digitalHallLeft));
Serial.print("    Button: ");
Serial.print(digitalRead(buttonPinA));
Serial.print("  \n ");


  buttonStateA = digitalRead(buttonPinA);


 digitalHallLeftState = digitalRead(digitalHallLeft);

//
//  LOOP BUTTON A LAUTSTÄRKE ERHÖHEN
//

 if (buttonStateA ==  HIGH) {

  // Set motor direction 
  digitalWrite(dirPin, HIGH); // muss noch herausgefunden werden

  // Spin motor slowly
  while(1){

    if (digitalHallLeftState == HIGH){
    
    digitalWrite(stepPin, HIGH);
    delayMicroseconds(1000);
    digitalWrite(stepPin, LOW);
    delayMicroseconds(1000);
 }

 else{		}

  }

   delay(10); // Wait 
}

else {
  
 }

}

I tried my code with && the if condition of the rf signal and the hall sensor signal. This works but is not really what i want for my project.

//motor pin setup
const int dirPin = 3;
const int stepPin = 2;
//const 

// RF RC pin setup

const int buttonPinA = 6;  // lauter Knopf


const int digitalHallLeft = 4;     //linker Hall sensor setup


// RF RC state setup
int buttonStateA = 0;  


int digitalHallLeftState = 0;


void setup() {
  // Declare pins as Outputs
  pinMode(stepPin, OUTPUT);
  pinMode(dirPin, OUTPUT);
  pinMode(digitalHallLeft, INPUT);

   Serial.begin(9600);

}
void loop() {

// Überprüfung der LOW / HIGH States  
Serial.print(digitalRead(digitalHallLeft));
Serial.print("    Button: ");
Serial.print(digitalRead(buttonPinA));
Serial.print("  \n ");


  buttonStateA = digitalRead(buttonPinA);


 digitalHallLeftState = digitalRead(digitalHallLeft);

//
//  LOOP BUTTON A LAUTSTÄRKE ERHÖHEN
//

 if (buttonStateA ==  HIGH && digitalHallLeftState == HIGH) {

  // Set motor direction 
  digitalWrite(dirPin, HIGH); // muss noch herausgefunden werden

  // Spin motor slowly
     
    digitalWrite(stepPin, HIGH);
    delayMicroseconds(1000);
    digitalWrite(stepPin, LOW);
    delayMicroseconds(1000);
 


  }

  else {
  
 }

   delay(10); // Wait 
}




Here is my schematic, I hope i did not forget anything:

I hope someone has an idea what i could change to get it to work!

Thanks alot.

greets

test it with simple sketch

pinMode(13,OUTPUT);
digitalWrite(13,digitalRaed(4));

What you mean with pin 13?

this is secret pin

nevermind, ignored the problem by switching my rf receiver into self lock mode

When buttonStateA is HIGH, your code goes to while(1) and inside this while it no longer reads the hall value, it only uses a previously read value.

Place a new hall sensor reading inside while(1).

thank you! that fixed it, now i could implement more features :slight_smile:

I see "5volt power supply" next to an A4988.
I think you forgot that an A4988 needs 8volt absolute minimum.
Why this chip anyway. Those stepper motors usually come with an ULN board.
Leo..

Hey, it works just perfectly fine with 5v power. I had an ULN2003 but did't get the motor to working and I tried every possible cable combination.

The A4988 was just more straight forward

Greets

So you think parts work as they should when using them outside their specifications?
You obviously still have a lot to learn.
Leo..