Intro: Cheap Obstacle Sensor - With Arduino!
When I started with arduino, and electronics, I always wanted to do things the cheap way.
Nothing has changed.
Step 1: Parts
You will need:
- Infrared LED
- Infrared photodiode
- Wires of some sort
- Electrical tape, duct tape, even hot glue!
- Heat shrink
- Perhaps a breadboard for testing
Step 2: Constructing the Sensor 1, Soldering
First off the sensor will be soldered together.
As you can see in the pictures, both the LED and the photodiode have a long and a short leg. The short legs should be connected to eachother like you can see in the picture. Any questions?
Step 3: Constructing the Sensor 2, Covering
The photodiode will be covered, so any ambient light won't affect the readings. This will be done with some heatshrink tubing, or duct tape. Heat shrink is recommended.
Cut off a section of heat shrink a bit longer the black blob on your photodiode. Put it on and heat it! Easy, right?
Step 4: Finishing, Arduino.
You will now have an LED and a photodiode soldered together. You can either glue these together, tape them together (wich I think is neater) or heatshrink together(neatest).
What results is something like picture
Connect the long pin of the LED with +5v, the short pins to GND and the long photodiode lead to a pin on your Arduino. Preferably an analog pin. Set it as INPUT and write it HIGH to activate the internal pullup resistor. The lower the value analogRead() gives, the closer something is.
an example code, you can upload this to your arduino board. The LED will light as soon as the obstacle comes close. Increasy the integer sensitivity to increase the distance to activate. Watch out though! Too much and you won't be able to sense because of ambient light!
int LED = 13;
int sensor = A0;
int sensitivity = 700
distance = analogRead(sensor);
if (distance < sensitivity)