Proximity Sensor for Arduino MCU Using 555 Timer IC
by AraviChow in Circuits > Arduino
5280 Views, 24 Favorites, 0 Comments
Proximity Sensor for Arduino MCU Using 555 Timer IC
![PicsArt_09-25-12.05.50.jpg](/proxy/?url=https://content.instructables.com/F0Q/TWT5/J7UQYJ43/F0QTWT5J7UQYJ43.jpg&filename=PicsArt_09-25-12.05.50.jpg)
Hi friend I'm Aravind Chowdary and today we're going look into the building of an IR proximity sensor. This was my contest entry so if you like my project don't forget to vote me for the contest. Let's get started!
After setting up
your robot’s motors and letting it run, one of the first things
you’ll realize, is that most likely it will run straight into a wall.
How do get your robot to detect obstacles, you may wonder. Well, there are
a number of different solutions for this problem, such as radar, sonar
(sometimes SODAR in air), bump switches, and one of the most widely used
solutions, Infrared obstacle detection. This type of sensor is called a
proximity sensor, because it can only detect if an obstacle is within
or without a set range. If your application needs an actual distance
returned, then you probably should use sonar or DIRRS (digital
infrared rangefinding system). An infrared proximity detector (IRPD),
works by illuminating in front of the robot with infrared light, this
type of light is invisible to the human eye, but your home camcorder
can
see this type of light quite well. When the light is reflected by an obstacle
in front of the robot, your IR detectors will register that light, and, an
obstacle. Variables such as texture, surface, color , and reflectivity
affect reliability. The type of infrared light used is called near
infrared, and operates at 800 – 1000 nm, as opposed to the IR light
used in security systems or night vision goggles, which is called the
far infrared type of light, and operates from 2000 – 10,000 nm. The
type of detectors used in this type of IRPD
only allows a certain frequency of light to pass, usually from 35 to
40 kHz. Since there are very few sources of IR light at these frequencies
there is very little interference. In the system we will be building,
we will us a 555 timer to produce the desired frequency. There are
many other type of frequency generating circuits, but the 555 is the
easiest. This frequency can be tuned using a potentiometer.
Get Your Parts
![IMG_20170925_103037557.jpg](/proxy/?url=https://content.instructables.com/F47/C4J7/J7UQYJC1/F47C4J7J7UQYJC1.jpg&filename=IMG_20170925_103037557.jpg)
![IMG_20170925_103205117.jpg](/proxy/?url=https://content.instructables.com/FCO/A4N5/J7UQYJC6/FCOA4N5J7UQYJC6.jpg&filename=IMG_20170925_103205117.jpg)
![IMG_20170925_104101725.jpg](/proxy/?url=https://content.instructables.com/F4I/YDVR/J7UQYJCA/F4IYDVRJ7UQYJCA.jpg&filename=IMG_20170925_104101725.jpg)
![IMG_20170925_103102334.jpg](/proxy/?url=https://content.instructables.com/FDV/7JJW/J7UQYJCF/FDV7JJWJ7UQYJCF.jpg&filename=IMG_20170925_103102334.jpg)
prototyping (very highly recommended!)
1 – 555 timer
1 – 1-10k potentiometer (value is not imperative)
1 – 0.01 uF cap
2 – 1k resistors
2 – IR receivers (preferably Panasonic 4602 available a Digi-Key.
If you buy Radio Shack detectors don’t expect it to work well at all)
2 – IR LEDs
2 – 470 ohm resistors
2 – 0.1 uF caps
If you're ready with the parts let's get started!
Circuit Diagram
![IRPDp2schematic.gif](/proxy/?url=https://content.instructables.com/FH4/BECU/J7UQYJD4/FH4BECUJ7UQYJD4.gif&filename=IRPDp2schematic.gif)
parts, first, we set the 555 circuit to produce the desired frequency,
then, we set up the IR detectors, and LEDs, and write the
code. We will cover part one this month, and part
two next month.
The first step in building this circuit is to place all the
components on your bread board using the schematic above.
Program Your Controller
![IMG_20170923_142712604.jpg](/proxy/?url=https://content.instructables.com/FFG/LA0U/J7UQYJKC/FFGLA0UJ7UQYJKC.jpg&filename=IMG_20170923_142712604.jpg)
program your controller using the code below. If you are using something
other than a Basic Stamp, you should have some sort of display, or
oscilloscope so you can tune the circuit to the required frequency.
‘Frequency count Basic Stamp code
frequency var word
high 5 ‘turn on oscillator unless vdd
is connected to the reset pin
start:
count 6,100,frequency
‘count frequency on pin 6
debug dec5 frequency*10,cr
goto start
Once your processor has been programmed you then should
turn the potentiometer until the debug screen, o-scope, or LCD display shows
38,000 (or the correct frequency for your detectors). Once your
circuit is set to the correct frequency, then we can move on to the next
section of our project…
{mospagebreak}
Let's Recape What We Done
![IMG_20170925_115833948.jpg](/proxy/?url=https://content.instructables.com/FGE/80JI/J7UQYJEV/FGE80JIJ7UQYJEV.jpg&filename=IMG_20170925_115833948.jpg)
Lets recap what we’ve done
so far. First, we created a 555 timer circuit to produce a 38-40khz pulse.
We did this so that the detectors would be able to recognize the infrared
light coming from our robots LEDs and no other type of IR light. After
setting up the circuit we then fine tuned it using a simple Basic Stamp
program. At this point in the process we need to put in the LEDs IR
detectors, and write some code to utilize our infrared proximity detection
circuit.
Infrared Detection
![IMG_20170925_105830992.jpg](/proxy/?url=https://content.instructables.com/FUM/8U6T/J7UQYJGG/FUM8U6TJ7UQYJGG.jpg&filename=IMG_20170925_105830992.jpg)
![IRPDp2schematic2.gif](/proxy/?url=https://content.instructables.com/F1A/SSN5/J7UQYJIQ/F1ASSN5J7UQYJIQ.gif&filename=IRPDp2schematic2.gif)
all your components on your circuit board or bread board according to the
schematic.
Before setting up the detectors first find out if the IRLEDs are doing
anything. You can do this by either using you home video cassette recorder
or using a IR an IR detector card from Radio Shack. Although using the
card is probably easier, it’s a bit pricey at $5.00 US. Camcorders are
able to pick up the higher wavelength light than a human eye, so therefore
you can "see" the IR LEDs by looking through your viewfinder. If
you DON’T see any light from the LED’s then you need to verify that your
circuit is receiving power, and that the output pin is outputting. Next
you need to wire up your detectors using the schematic below. The physical
setup of the detectors and IRLEDs are at a 45 degree angle. The picture
below gives a good representation, with detectors in yellow and IRLEDs in
red. Follow the above circuit to build the detector.
Coding
![Proximity sensor part-1 Demo video](/proxy/?url=https://content.instructables.com/FN5/H48W/J7UR0K00/FN5H48WJ7UR0K00.jpg&filename=Proximity sensor part-1 Demo video)
Got your detectors set up? Verify the pin
connections and fire up your stamp using the code below.
‘Basic Stamp Code
‘Basic Proximity Detection Part 2
INPUT 0
INPUT 9
start:
debug In0
debug In9,home
goto start
Once you have this
code running, try and put your hand down in front of you detector and LED.
Depending on what detector you have at which pin, on of the debug number
should change from 1 (high) to 0 (low), and remain that way as long as
your hand is in front of it. Now try the other detector, and then both at
the same time.
Once both of your detector and LED pairs are functioning correctly then
try out the code below.
x var
nib
RIRdetect var nib
LIRdetect var nib
INPUT 0
INPUT 9
start:
RIRdetect = 0
LIRdetect = 0
‘check 10 times
for right detection
for x = 1 to 10
RIRdetect =
RIRdetect + in0
LIRdetect =
LIRdetect + in9
next
if (RIRdetect <
4) and (LIRdetect < 4) then center
if RIRdetect <
4 then rdetection
if LIRdetect <
4 then ldetection
goto start
rdetection:
debug
"A right collision was detected!"
goto start
ldetection:
debug
"A left collision was detected!"
goto start
center:
debug
"Center collision!"
goto start
Note: I have NOT
tested this code as of yet. It came all FROM MY HEAD. If it doesn’t work
correctly check for errors. My IRPD circuit is disassembled at the
moment, and I haven’t had time to put it back together.
Lastly
![IRPDp2.gif](/proxy/?url=https://content.instructables.com/FLL/3U9B/J7UQYJJG/FLL3U9BJ7UQYJJG.gif&filename=IRPDp2.gif)
This
is just some basic code that checks for a greater than 60% hit ratio.
Since an output low (0) signals a hit, we test for a value lower than 4.
You can put any code you want into the r and l detection and center
subroutines. Once you have it working congratulations! You now have a
working, albeit, simple obstacle detector.
Thanks for spending your time in reading my instructable.