IR Sensor Differentiation Question

General project help for Adafruit customers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
sandysenterprises
 
Posts: 3
Joined: Sun Oct 27, 2013 5:11 pm

IR Sensor Differentiation Question

Post by sandysenterprises »

I have two IR sensors parallel to each other (right & left) but separated by a barrier. I would like to have a green led light up if the right sensor detects an object first and a red led light up if the left sensor detects first. Just for example, green led is pin 9 and red led is pin 10.
Is this even possible and can anyone please help with the code? I have a little experience with code but this is beyond me.thanks

User avatar
adafruit_support_bill
 
Posts: 88088
Joined: Sat Feb 07, 2009 10:11 am

Re: IR Sensor Differentiation Question

Post by adafruit_support_bill »

This should be possible. The first thing to do is to connect both sensors and verify that they both work - and that your barrier isolates them as expected. When you get to that point, we can start working out the detection logic.

User avatar
zener
 
Posts: 4567
Joined: Sat Feb 21, 2009 2:38 am

Re: IR Sensor Differentiation Question

Post by zener »

I don't know that you need isolation. It might depend on what sensors you use. If you have a IR LED on one side and it is shining on two photo detectors on the other side then I don't think there would be interference.

If this is the complete spec then a simple logic circuit would be the easier way to do it probably.

User avatar
adafruit_support_bill
 
Posts: 88088
Joined: Sat Feb 07, 2009 10:11 am

Re: IR Sensor Differentiation Question

Post by adafruit_support_bill »

If you have a IR LED on one side and it is shining on two photo detectors on the other side then I don't think there would be interference.
I suppose we should clarify what kind of sensors you are using first. I was assuming you were using something like the Sharp IR Rangefinders. These can definitely interfere with each other. Zener interpreted it as a discrete photo-sensor. What kind of sensors are you using?

sandysenterprises
 
Posts: 3
Joined: Sun Oct 27, 2013 5:11 pm

Re: IR Sensor Differentiation Question

Post by sandysenterprises »

Yes, sorry, they are the Sharp Sensors. I plan to isolate them so that they don't interfere with eachother. What I am trying to do is determine the angle of a blade passing over the sensors. If the right sensor detects first then I know the angle is pushing left and visa-versa.
I guess I never thought about both passing over the sensor at the same time. or within a specified amount of time, i.e if the sensors detect an object within two hundredths of a second difference, then the blade is straight.
Alright, here is what I would attempt. I would go with an ELSE IF statement

If both sensors detect within two hundredths of a second then light an led at pin 8
ELSE IF IR sensor 1 (pin A0) detects the object first and IR sensor 2 (pin A1) detects after two hundredth of a second have passed, light led at pin 9
ELSE IF IR sensor 2 (pin A1) detects the object first and then IR sensor 1 (pin A0) detects after two hundredth of a second, light led at pin 10.

Please correct me. I just started learning code and this might be a little ambitious for me. I am using the Arduino UNO I recently got from Adafruit

User avatar
adafruit_support_bill
 
Posts: 88088
Joined: Sat Feb 07, 2009 10:11 am

Re: IR Sensor Differentiation Question

Post by adafruit_support_bill »

I think it is better to approach it as an event-driven state machine For each sensor, keep a variable for the detection state (true or false) and another to record the time-stamp of when it transitioned to that state. So if you detect something new on sensor 1, record the time (using the millis() function) and check the state of sensor 2. If it is also "true", you can compare the times and apply the appropriate decision logic.

User avatar
zener
 
Posts: 4567
Joined: Sat Feb 21, 2009 2:38 am

Re: IR Sensor Differentiation Question

Post by zener »

You need to follow the original advice and verify the sensors will work at all. If the blade is shiny then I don't think it will detect it at an angle. You would need to put something on the blade to allow some light to return from different angles of attack. However I don't know what your blade is. You might get better advice if we actually knew what you were doing. I don't know why you are using this kind of sensor when all you want to know is which crossed a line first. It seems like you are only making it about 10 times harder to do. However I may not really understand what you are doing.

sandysenterprises
 
Posts: 3
Joined: Sun Oct 27, 2013 5:11 pm

Re: IR Sensor Differentiation Question

Post by sandysenterprises »

That is exactly what I was looking for. Thank you for the responses!

Locked
Please be positive and constructive with your questions and comments.

Return to “General Project help”