Hall Effect helping

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:

}

I don't think the program does even what you described it doing. For example
delayMicroseconds (2000);
waits 2 milliseconds, not 2 seconds as you want. In order to have continuous repetition, you need to call the motion function in 'vod loop ()'. Now you call it in 'void setup ()' and it is executed only once.
Whether your motion function does what you want is another matter entirely.

Hi, @dudilevi85
To add code please click this link;

A circuit diagram will help with your pin allocations.
Please include power supplies, component names and pin labels and how you have wired your limit switch?

You need to add serial monitoring to view your variables.
Have you proved with simple code that the Hall Effect is being read correctly?
Have you proved with simple code that you can control your motor fwd/rev?
All those while.. statements are not necessary, an if.. test in a loop as you drive your motor will be easier, setting a flag when you detect the home position.

Thanks.. Tom... :grinning: :+1: :coffee: :australia:

What motor controller are you using?
What model Arduino are you using?

Thanks.. Tom... :grinning: :+1: :coffee: :australia:

Hey Tom first of all Thanks! Im very appreciate that.
The motor is DC - High, High - stop the operation. High- Low RIGHT direction .
I have checked the hall sensor and it works perfect. Usually is 1 with magnet changed for 0.
The motor connected to pins number 10 - 11 .
I add the hall sensor to pin number 3.
Before working with the hall sensor I work with delay functions.

right (HIGH, LOW) , delay (100000) > stop for 2 seconds (HIGH, HIGH) > changing sides (LOW,HIGH).

With the hall sensor I would like to change the code:
right (HIGH, LOW) > Magnet > stopping for 2 seconds > change sides ** the magnet still there (0 value).
My main problem is with the code- I need code without looping > checking each condition >starting the operation > the magnet's triger > stop and change sides.

It should be combination of while or and if condition.

Thanks!

Maybe It will help me to explain exactly what Im looking for.

Now Im working with that script: I would like to replace each place with HIGH-HIGH status at the script with hall sensor indication wich defined in pin 3 and the digital read is 1 without magnet and 0 when the magnet is activated. the problem with the delay option is that the motor cant find the home position..

void setup()
{
pinMode(10,OUTPUT);
pinMode(11,OUTPUT);
}

void loop()
{

digitalWrite(10,HIGH);
digitalWrite(11,HIGH);
delay(10000);
digitalWrite(10,LOW);
digitalWrite(11,HIGH);
delay(87000);
digitalWrite(10,HIGH);
digitalWrite(11,HIGH);
delay(7000);
digitalWrite(10,HIGH);
digitalWrite(11,LOW);
delay(87000);
digitalWrite(10,HIGH);
digitalWrite(11,HIGH);
delay(2000);
digitalWrite(10,HIGH);
digitalWrite(11,LOW);
delay(7000);
digitalWrite(10,HIGH);
digitalWrite(11,HIGH);
delay(2000);
digitalWrite(10,LOW);
digitalWrite(11,HIGH);
delay(7000);
digitalWrite(10,HIGH);
digitalWrite(11,HIGH);
delay(60000000);

}

Hi,
Thanks for the info;
To add code please click this link;

We will need a circuit diagram.
Can you post links to your motor data/specs.

The motor is DC - High, High - stop the operation. High- Low RIGHT direction .

Doesn't mean a lot.
Your code in post#5 does not check the HallEffect sensor.

Thanks.. Tom... :grinning: :+1: :coffee: :australia:

Hi,
A couple of questions to get things clear.

  1. Does pin 3 go from HIGH (5V) to LOW (0v) when magnet is at home position?
  2. How long does it take the motor to do one full turn from home to home?

Thanks.. Tom... :grinning: :+1: :coffee: :australia:

So much redundancy... makes it hard to see what is going on. I'm not going to do the whole thing, but you really have:

digitalWrite(10,HIGH);
digitalWrite(11,HIGH);
delay(10000);
digitalWrite(10,LOW);
delay(87000);
digitalWrite(10,HIGH);
delay(7000);
digitalWrite(11,LOW);
delay(87000);

for example.

  1. Yes
  2. About 87 seconds but it isn't accurate and changing all time. That is the reason that I would like to change the delay option with the hall magnet. When it is in the 'home position' it should delay for 2 seconds and changing sides.

Please post your latest code in code tags. Do not edit previous posts, it makes the replies seem wacko.