# Direction Detection

Hello,

I have 2 Inductive Sensor A and B.

When First A goes HIGH and then B goes HIGH, it should print “FORWARD”
when First B goes HIGH and then A goes HIGH, it should print “BACKWARD”

I am not getting any proper logic for this.

Thank you

Ignore me. Can't help without not just doing it.

Hi,

Tom....

Hi,

http://forum.arduino.cc/index.php?topic=420046.msg2892637#msg2892637

Tom…

Hi Tom,

Can not open the link you just posted

Hi,

Tom...

Yes

this is the same thread I inquired before

Hi,

Can you tell us your electronics, programming, arduino, hardware experience?

Thanks… Tom…

I am trying to undernstand it.

My experience with Arduino is not that good.

Basically I am a PLC programmer and somehow need to develop a logic with Arduino first time.

I just started learning Arduino a week before

Thats why I am asking very basic questions.

Thank you for your kind support

Hi,
What you are doing is looking at the output that a quadrature encoder would supply.

You need to poll input A,
when it goes HIGH,
you poll input B,
if it is LOW then you must be going forwards, because it hasn't gone HIGH yet.
if it is HIGH, then you must be going backwards, because it must have gone HIGH before A went HIGH.

You need to detect the change in state of A from LOW to HIGH, when it does then check level of B.

Tom...
Hope it helps, I'm off to bed...

The encoder library for Arduino is pretty good for this. It will use interrupts, so if you put input A onto a pin that has a pin-change interrupt (only pin 2 and 3 on the Uno, others have more interrupt pins) then the library will use that and your code doesn't need to keep polling input A.

Hi, i had the same problem

The way to look at it is at the moment when A goes High if B is High also then CW Else if B is Low then CCW

@Mandalas, let us know how the answers above have failed to help you. What have you tried, what worked differently to how you expected? If you have the same problem then I have already given my answer to that problem.

@zhomeslice, With 295 posts and 66 karma points, I can't imagine why you would be asking that basic question. Translation problem? "State" means the existence of HIGH or LOW on the pin.

MorganS:
@zhomeslice, With 295 posts and 66 karma points, I can't imagine why you would be asking that basic question. Translation problem? "State" means the existence of HIGH or LOW on the pin.

Not a question just a way of saying what I already know...
Thanks for pointing this out I Restated it without the "How I look at it" part

Checking the motors direction is easy

At the moment when A goes High if B is High then the motor is turning one way.
Else if B is Low then the motor is turning the other way.

You can also do this assessment when A goes Low
in addition B changes voltage half way between when A voltage change. and so when b changes from low to high you can look at a to see what voltage it is in.

OK, sorry. It looked like a question.