Go Down

### Topic: Detecting distance with IR Sensor (Read 399 times)previous topic - next topic

#### tjb2of3

##### Feb 05, 2014, 09:08 pm
Hello everyone, to start off I'm new to the forums and to arduino in general.  I've done a quick search for relevant topics but haven't been able to answer my own question, so here goes:

My goal is to detect changes in distance with an Infrared sensor, and if the distance changes over a period of ~1 minute, to turn on an LED.  Ideally, I would be able to connect ~10 sensors, each connected to its own light.  In practice, my operation would look like this:
1) position materials
2) zero the sensors
3) run system for about  a minute.  Lights would indicate a change in distance read by the sensor over this time interval.

I know this is a general explanation, but I'm just trying to figure out if it's even possible at this point.  I can provide more info if you need it.  Does this seem like a feasible idea?

#### knut_ny

#1
##### Feb 05, 2014, 10:33 pm
make a simple sketch..   It is not very clear to me how you actually think....
Ny

#### Robin2

#2
##### Feb 05, 2014, 11:06 pm
There are plenty of posts here about measuring distances with sonar. But isn't light just too fast?

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

#### tjb2of3

#3
##### Feb 05, 2014, 11:37 pm
Ok, sorry again about the vagueness. I attached a simple diagram.  Basically, I want to be able to zero the sensor at time t1, so that it will use the distance d1 as "zero".  Over the time interval t1 - t2, the sensor will be continuously measuring the distance d.  If that distance changes at any time over that interval (so that d2 > d1), I want the controller to turn on an LED.

The sensor I'm looking at is this: http://www.acroname.com/products/R146-GP2D120.html
My understanding is that it continuously measures distance, and the output signal is a voltage which relates to that distance.

So my questions are: (1) Can I hook up this sensor to an arduino, and will it properly read the voltage output from the sensor? (2) Can I code the controller so that if there is any deviation in that voltage, a light will be switched on?

#### knut_ny

#4
##### Feb 06, 2014, 06:48 pm
If you've got what the datasheet tells - surely this connects directly to an analog input
(maybe a tiny cap can remove ripple)
You will with ease detect changes below 20cm (maybe as small changes as 1mm)
If you plot points into excel, you might find a handy formula for distance. (or use a lookup-table)
Ny

#### JimboZA

#5
##### Feb 06, 2014, 07:07 pm
If you Google that part number + Arduino you'll probably find some code.

Meantime look at this example which reads the output from a potentiometer on an analog pin. That's essentially what you need to do with the sensor: the yellow wire is the same as the pot's middle wire, in that it outputs a voltage.

Then have a look at the world famous  and oft-quoted Blink Without Delay to see how to repeatedly do something. In your case, every second or whatever, read the sensor. Compare the value with the previous one (which you would have saved) and act accordingly.
Johannesburg hams call me: ZS6JMB on Highveld rep 145.7875 (-600 & 88.5 tone)

Go Up

Please enter a valid email to subscribe