Arduino Hot/Cold Range Finder

I am interested in measuring distance for a project I am working on. I made this from a Parallax ultrasonic range sensor, an Arduino UNO, two LEDs, two resistors and some plans and code I found online at MAKE’s website: Sensing Hot and Cold with Weekend Projects. (“Hot” and “Cold” here refer to an object being ‘close to’ or ‘far from’ the sensor, not to actually measuring an object’s temperature.)

The circuit sends out an ultrasonic chirp and then listens for the response. The time required for the echo is used to estimate the distance to the closest object in front of the sensor. When there is nothing within a few feet of the device, only the green light on the range finder lights. When your hand (or any other object) moves in front of the sensor, the blue LED lights. When you get closer, both LEDs light. And when you get very close (within a couple of centimeters), only the red LED lights.

hot-cold-range-finder

Here are instructions for assembly:

  • Pin 5 of the Arduino attaches to the long leg of a red LED, which attaches to a 150 Ohm (brown, green, brown, gold band) resistor, which goes to Ground.
  • Pin 6 of the Arduino attaches to the long leg of a blue LED, which attaches to a 51 Ohm (green, brown, black, gold) resistor, which goes to Ground.
  • Pin 7 of the Arduino goes to the ‘Sig’ (signal) pin of the range finder.
  • The 5V (5 volt) pin of the range finder goes to the Arduino’s 5V pin.
  • The ‘GND’ (Ground) of the range finder goes to the Arduino’s GND pin.

Unfortunately, the 5V and GND pins on the Arduino and the range finder are positioned in such a way that it takes a little creativity in laying out the wires so that everything fits. Also, there’s a big chip running down the Arduino board that I didn’t think about when I placed the red LED, so much of the project was actually getting everything to physically fit into place.

Overall, this project was simple to make, and I made the range sensor (the input device) removable, so that I can use the rest of the circuit as an output device for other projects.

// Hot/Cold LEDs v1
// using a PING))) Sensor
// Basic “hot/cold” program will blink blue until you get close, then change
// (c) 2012 julius@urgu.de

// define pins
int SensorPin=7;
int RedLedPin=5;
int BlueLedPin=6;

int distance;
unsigned long pulseDuration=0;

void setup() {}

void loop() {

// measure distance: send “Ping”
pinMode(SensorPin, OUTPUT);
digitalWrite(SensorPin, HIGH);
delayMicroseconds(5);
digitalWrite(SensorPin, LOW);

// measure distance: listen for “Ping”
pinMode(SensorPin, INPUT);
pulseDuration=pulseIn(SensorPin, HIGH);

// divide by two (back/forth for a single trip), divided by speed of sound = distance in cm
pulseDuration=pulseDuration/2;
distance = int(pulseDuration/29);

// light up red led: inverted linear of 0-25cm to 0-255 eq. off to max. brightness
if (distance > 0 && distance < 25) {

int RedValue=(25-distance)*10.2;

analogWrite(RedLedPin, RedValue);

} else {

analogWrite(RedLedPin, 0); }

// light up blue led: 0-25cm ^= 0-255, 25-50cm ^= 255-0 on BlueLedPin if (distance > 10 && distance <= 25) {

int BlueValue = (distance-10)*17;

analogWrite(BlueLedPin, BlueValue);

} else if (distance > 25 && distance < 50) {
int BlueValue = (50-distance)*10.2;
analogWrite(BlueLedPin, BlueValue);
} else {
analogWrite(BlueLedPin, 0);
}

// wait a little…
delay(20);

}

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



%d bloggers like this: