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
