Tuesday, November 25, 2008

i have tested my ir-led-photodiode pair for more than 30 different lights and surfaces..... they are just awsome..... awsome but not intelligent (unlike TSOPs).... but you can make them intelligent using your programming skills and some thinking....

with correct technique they can detect presence of white surface (paper in my case) upto 50cm (*conditions applied ) even in the presence of very ir-emitting audience.

The Principle:






in words : Take a reading with IR-led OFF and subtract it from reading when IR-led is ON. This way you get reading because of IR-led only. This principle assumes that the neighbouring IR conditions remains unchanged in between two readings.


Circuit:

  • Atmega8
  • IR-led-Photodiode
  • reflecting surface
  • BC547 or any switching element
  • some discretes



CAUTION: As you can see, there is no resistance in series with IR-led. so if the transistor is kept ON for more than few milliseconds, IR-led will be damaged. By default, the output of atmega pins is high when unprogrammed. So first program the chip and then connect IR-led, or use a toggle switch in between.



Program:

/*Code for controlling IR-led-photodiode sensor using atmega8
internal clock 1MHz
written in AVR Studio 4
*/
#include"avr/io.h"
#include"util/delay.h"

int main(void)
{
DDRB=255; //set port b for output
DDRD=255; //set port d for output
DDRC=0; //set port c for input
ADMUX=0b00100000;
//setting ADC to AREF, left adjusted, ADC0
ADCSRA=0b10000011; //enable ADC, prescale 8
unsigned register char i=0,j=0; //to store ADC results
while(1)
{
PORTB=0b00000001; //turn ON IR-led
_delay_us(20); //wait for turn-ON time
ADCSRA=0b11000000; //start ADC conversion
_delay_us(30); //wait for conversion to complete
//instead of this 30us delay you can use
//while(ADCSRA!=0b10010000);
PORTB=0; //turn OFF IR-led
i=ADCH; //store led-ON value in 'i'
_delay_us(20); //wait for turn-OFF time
ADCSRA=0b11000000; //start ADC conversion
while(ADCSRA!=0b10010000);
//wait for conversion to complete
j=ADCH; //store led-OFF value in 'j'
if(i-j>70)
//compare the difference with threshold value
PORTD=255; //if more than threshold, turn ON LED
else
PORTD=0; //if less than threshold, turn OFF LED
_delay_us(1000); //wait to let IR-LED to cool.
//don't decrease it below 500

}
}



Testing:

here is a video showing my testing results for wall detection at 8-10 cms.



So, how far can it go???thats the question which came in everyone's mind while using ir-sensors. normally, people think that ir-led-photodiode works upto 12-15 cms only. for longer distances we should use TSOP. So here i tested my ir-pair for a distance of 50cms. the main principle is to overdrive the ir-led at higher voltage. with 7V i got 50cms.
(CAUTION : remember, overdriving is risky if not done properly)

Enjoy!!!!