Having played around with my Arduino for a few months, I was able to make the speaker beep and the LEDs blink, but I really couldn’t think of a practical use for it.
Then I purchase a 21 foot long Ford F-150 pickup. My driveway is only 22 feet long and I didn’t want the city to come after me for blocking the sidewalk. My concern was when I pull into the driveway I can’t see how close the front of the pickup was to my garage door. I certainly didn’t want to put a dent in my garage door or the grill of my new truck.
So after searching around a bit for an infrared proximity sensor that would interface directly with the Arduino, I found the Sharp GP2Y0A21YK0F to be just what I was looking for. It will measure distance from 10cm-80cm with a non-linear output of between 0 and 3 volts…perfect for the Arduino analog input.
It was a simple as waterproofing and installing the IR sensor and hooking up to the Arduino along with a miniature piezo speaker.
Here’s the simple sketch I used:
/*
Sharp GP2Y0A21YK0F IR Sensor proximity detector
created 20 May 2013
Measures distance from 0-80cm and progressively increases
the frequency of the beeps, in steps, as the object gets closer
* Miniature piezo speaker on digital pin 11
* IR sensor output to analog pin A0
* 5V power and ground to sensor
*/
void setup() {
// initialize serial communications (for debugging only):
Serial.begin(9600);
}
void loop() {
// read the sensor:
int sensorReading = analogRead(A0);
// print the sensor reading so you know its range
Serial.println(sensorReading);
// map the analog input range in steps (>100, >150, >180, >300)
// increase frequency and tone of output correspondingly
if (sensorReading > 300)
{
tone(11, 1500, 100);
delay(100);
noTone(11);
delay(100);
}
else if (sensorReading > 180)
{
tone(11, 1000, 500);
delay(500); // delay .5 sec If(sensorReading < 1000)
noTone(11);
delay(500);
}
else if (sensorReading > 150)
{
tone(11, 800, 1000);
delay(1000);
noTone(11);
delay(1000);
}
else (sensorReading > 100);
{
noTone(11);
}
}
How did you waterproof the infrared proximity sensor?
I just placed it all in a small plastic case and sealed it with silicon seal.