Hey,
I would like to use hall sensor in my project. The main purpose is while detecting the magnetic sensor, the triger is to stop the motor for 2 seconds and changing the motor for the other side.
see the code that I have made :
the problem is after the high low direction the triger works fine and stop the motor but after 2 seconds delaying i wont start.
some Ideas to change that code and simplified it?
It should work like this : right direction without the hall effect triger (high,low) >
detect the hall sensor > stop the motor for 2 seconds (low, low) > starting the motor for the opposite direction (low, high) > detect the hall sensor > stop the motor for 2 seconds (low, low) etc...
Thanks!!!!!!!
int motor1pin1 = 3;
int motor1pin2 = 4;
int hallsensorA = 2;
void homefunction() {
while (digitalRead(hallsensorA) == 1){
digitalWrite(motor1pin1, HIGH);
digitalWrite(motor1pin2, LOW);
}
while (digitalRead(hallsensorA) == 0){
digitalWrite(motor1pin1, LOW);
digitalWrite(motor1pin2, LOW);
delayMicroseconds (2000);
}
while (digitalRead(hallsensorA) == 0){
digitalWrite(motor1pin1, LOW);
digitalWrite(motor1pin2, HIGH);
}
while (digitalRead(hallsensorA) == 1){
digitalWrite(motor1pin1, LOW);
digitalWrite(motor1pin2, HIGH);
}
while (digitalRead(hallsensorA) == 0){
digitalWrite(motor1pin1, LOW);
digitalWrite(motor1pin2, LOW);
}
}
void setup() {
// put your setup code here, to run once:
pinMode(motor1pin1, OUTPUT);
pinMode(motor1pin2, OUTPUT);
pinMode(hallsensorA, INPUT);
homefunction();
}
void loop() {
// put your main code here, to run repeatedly:
}