Time and interferences measuring distance.

Hi guys!! :slight_smile:

I have some troubles working with arduino and an IR sensor and I would like to know if you could help me.

This is what I'm doing:

I'm measuring distance with an IR sensor (and it's already working) and here's the logic:

If distance is from 4cm to 8cm:
print "Closed door"

If distance is 0 or bigger than 9cm:
print "Door open"

And here's the thing:
What would happen if the door is open or there is an interference? Like, let's say, my cat passes by and blocks the signal? Then the distance measured would be found between 4 to 8cm...

What I would like to do but haven't been able to is something like "if the measured distance changes rapidly then nothing happened, keep printing the door is open"

That's my problem, could anyone help me? :confused:

Thanks in advance!!! ;D

@LauraMU1294: Welcome to the forum!

Could you share you current program (sketch) with us? Just edit your 1st post and use the "</>’ icon in the upper left of the tool bar and paste your code from the ArduinoIDE between the two markers that will be placed in your post. Use the auto-format option of the ArduinoIDE becore you copy the sketch into the buffer and then the paste will be nicely formatted.

And yes, we can help… there is just so many ways to do something like this … it is really helpful to understand your current style and logic.

Ray

Ray’s Projects

You need a "low pass filter". This ignores things that change rapidly.
There are various implementations. Search for "moving average", "sliding window" or "smoothing".

Keep an array of values gathered over time and use a running average as your output.

-jim lee

Are you sure that you are using a IR (PIR?) sensor, not US (ultrasonic) sensor? Datasheet?

IR sensors do not normally allow to measure distances.

IR distance sensors

Last time, when I looked up such sensors, the price was above $80. Good to know that they are much cheaper now :slight_smile: