Poor Man’s Linear Distance Sensor

I’d like to use a linear distance sensor in an upcoming project, but the commercially available sensors seem a bit overpriced (probably because they are targeted at precision machining applications).  Given the parts I have on hand, it seemed worthwhile to try to make one out of just an led, a CdS sensor, a drinking straw, electrical tape and a microcontroller:

linear distance sensor prototype
Pay no attention to the circuit on the left side of the breadboard; it’s unrelated.

A drinking straw is wrapped in electrical tape (to keep the ambient light out), and then a CdS sensor is inserted into one end:

parts

The led is inserted into the other end of the straw.  I had to use a 3mm led, since a 5mm wouldn’t fit.  Then, as the led is moved inside the straw, the reading on the CdS sensor changes.  A simple Arduino sketch shows very approximate granularity of 48 units per inch (as reported by the ADC).

#define CDS_PIN 0

void setup()
{
  Serial.begin(9600);
}

void loop()
{
  Serial.println(analogRead(CDS_PIN));
  delay(500);
}

I followed this guide on the Arduino site for hooking up the CdS sensor.

In the end, I’m not sure whether this implementation will be practical for my use case.  I’ll have to wait for more parts to arrive to determine whether the mechanics will work out.  It was a fun little experiment, though!  You can find more photos of the circuit here.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s