This is an extremely cheap IR proximity sensor you can make with a few cheap parts and an AVR programmer. I use an Arduino as my programmer in this Instructable.
This sensor only has a range of about 3 inches. You can easily add more LEDs or brighter ones to extend the range. You can also easily re-arrange the LEDS to detect when a beam is broken as well.
The design takes advantage of a cheap AVR (computer on a chip). The computer pulses the IR LEDs off and on and compares the analog readings from the sensor in each state. When the reading with the lights on is above the reading with the lights off the sense pin goes high indicating the sensor is seeing it's own (reflected) light. There is an LED on the sense indicator in this design so you can see when the sensor engages. You can connect the signal right to a microcontroller like an Arduino or Picaxe.
This design moves some processing out of your main robot brain and into it's own node. You may want to debounce the signal, but you don't have to flash the leds and take the readings. You can also use just one digital pin to take the reading. The sketch is around 700K out of 1024 available.
Why I built this
I'm way out of high school, but this is part of a series of designs related to bringing the robots from the game Robot Oddysey into the real world. I want to allow grade schoolers the same chance to learn robotics I had. So I am working on building really inexpensive robots that can move in 8 directions without turning. The "bumpers" are complete now.
Follow @dustin1970
Remove these ads by
Signing UpStep 1: Gather Materials
|
Quantity |
Digikey Part Number
|
Description
|
Cost
|
|
1
|
475-1439-ND
|
PHOTOTRANSISTOR NPN W/FILTER 5MM
|
$0.53
|
|
1
|
ATTINY13A-PU-ND
|
IC MCU AVR 1K FLASH 20MHZ 8PDIP
|
$0.95
|
|
3
|
CF14JT220RCT-ND
|
RES 220 OHM 1/4W 5% CARBON FILM
|
$0.24
|
|
1
|
CF14JT1M00CT-ND
|
RES 1M OHM 1/4W 5% CARBON FILM
|
$0.08
|
|
1
|
2N3904FS-ND
|
IC TRANS NPN SS GP 200MA TO-92
|
$0.18
|
|
2
|
754-1241-ND
|
EMITTER IR 3MM 940NM WATER CLEAR
|
$0.44
|
|
|
|
TOTAL
|
$2.42
|
You will also need
- Electrical tape
- plastic drinking straw
- scissors
- Wire snippers
- breadboard and/or soldering iron
- Jumper wires
- An AVR programmer (any Ardunio compatible will do)
- Ardunio 1.0 software with modifications to program Attiny and the Atiny13 core












































Visit Our Store »
Go Pro Today »




In order to solve that problem, watching the behavior of the readings on my PC, I programmed my Picaxe to read the value of the phototransistor on the ADC0 (leg 7) with a 8bit resolution and add some to the reading (4 to be specific); the microcontroller takes a first reading of the phototransistor with the IR led (only one), adds 4 to it, takes a second reading of the prototransistor with the led on and compares, if the second is bigger than the first the indicator led goes on. This is reliably working for me between 4" and 1/2" even working next to the window!!! :D
Here is the program I downloaded on my Picaxe:
main:
low 5
readadc 0,b1
debug
high 5
readadc 0,b2
debug
let b3=b1+4
if b2>b3 then high 4
else low 4
pause 5
endif
goto main
The IR LED is connected on the output 5 and the indicator LED is connected on the output 4. I'm not familiar with Arduino, so I hope Picaxe people can use this too, this is really helping my little robot so, thanks again!
The datasheet for the phototransistor used says that, starting from the long pin side, the pins are: BASE, COLLECTOR, EMITTER (long, long, short).
So, actually, the circuit has the BASE connected to GRN through 1M Resistor (and also to the ATTiny input) while the EMITTER goes to +5V.
I'm very new to circuits/transistors, but that setup doesn't make any sense to me. Why does it work? Am I misreading the datasheet? (This is the datasheet I'm looking at: http://catalog.osram-os.com/media/_en/Graphics/00045426_0.pdf)
Mine works by ignoring the first long pin and putting the short pin to the 1M resistor (and Pin 3) and the middle pin to +5vcc - so if anyone orders the part from DigiSpark and it's not working the way you think it should - I would try this!
You are right! I have the wrong PN! It's 475-1493-ND. Curse my dyslexia!
http://www.digikey.com/scripts/DkSearch/dksus.dll?vendor=0&keywords=%09475-1439-ND is the correct link. I'll update the instructable!
If it helps anyone else, feel free to check it out here
Make sure you set the output to the IR led to 38Khz using something like;
irsend.enableIROut(38);
irsend.mark(0);
online they can be had under $,1 at radio shack they are about $4.
http://www.arcfn.com/2009/08/multi-protocol-infrared-remote-library.html
-Go to your sketches folder
-most likely there is a folder called 'hardware' if not, create that.
-open the hardware folder
-create a folder called 'attiny13'
open that folder
-create a new folder called 'core13'
-open that folder and unzip the attiny core files as found in the link in the beginning of this article
-go back to your /hardware/attiny13 folder
-create a text file called 'boards.txt'
open that file.
paste the following text in that file:
###########################################################################
attiny13.name=Attiny13 @ 128 KHz (internal watchdog oscillator)
attiny13.upload.using=arduino:arduinoisp
# attiny13.upload.protocol=avrispv2
# attiny2313at1.upload.using=pololu
attiny13.upload.maximum_size=1024
attiny13.upload.speed=250 # important for not losing connection to a slow processor
attiny13.bootloader.low_fuses=0x7B
attiny13.bootloader.high_fuses=0xFF
attiny13.bootloader.unlock_bits=0x3F
attiny13.bootloader.lock_bits=0x3F
attiny13.build.mcu=attiny13
attiny13.build.f_cpu=128000
attiny13.build.core=core13
###############################################################
attiny13at4.name=ATtiny13 @ 4.8MHz (internal 4.8 MHz clock)
attiny13at4.bootloader.low_fuses=0x69
attiny13at4.bootloader.high_fuses=0xff
attiny13at4.upload.maximum_size=1024
attiny13at4.build.mcu=attiny13
attiny13at4.build.f_cpu=600000
attiny13at4.build.core=core13
###############################################################
attiny13.name=ATtiny13 @ 9.6MHz (internal 9.6 MHz clock)
attiny13.bootloader.low_fuses=0x7a
attiny13.bootloader.high_fuses=0xff
attiny13.upload.maximum_size=1024
attiny13.build.mcu=attiny13
attiny13.build.f_cpu=9600000L
attiny13.build.core=arduino:arduino
attiny13.build.variant=tiny8
###########################################################################
save it.
restart your Arduino IDE (if you had it open, close it and then start it again)
check if you can see the newly added Attiny13 board under 'tools-boards'
Can you please describe the problem that you experienced with the timer and I will look for a solution and try to incorporate it permanently.
-#if defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)
+#if defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny13__)
SIGNAL(TIM0_OVF_vect)
This page describes changing wiring.c at the end of the post.
http://tekstop.wordpress.com/2011/12/30/programming-attiny13-using-arduino-isp-and-all-the-hacking-involved/
No modifications should be necessary. I will check it out.
Anyway, I have it working now so I will write up something in a seperate ibble
http://www.instructables.com/id/Installing-Attiny13-core-files/
the boards.txt file from the website had a couple of other peculiarities, but this shld make it all clear
I just can't get over how dirt cheap the Attiny is at Digikey. I pay 3 times that price over here in Western Europe. Might be worth going to digikey if my order is big enough to offset the shipping cost
What/where is trimPin? Did you have a potentiometer connected to another pin to tune the behavior at one point?