PDA

View Full Version : IR micromouse sensors



gates2231
01-15-2009, 08:16 AM
Hai
I want to make distance sensors using IR LED as emitter and IR photodiode as the detector

I connected a 300ohm resistance in series to LED and connected it to PORTC which is always high and connected the photodiode in reverse bias with a 10k in series and gave its signal from the junction of diode and resistor to the adc

i made those values appear on the LCD
i am getting random values wat i need to do now

my requirement is just 3cm
plz anyone help me out
thanks in advance

ashish_agarwal123456
01-15-2009, 03:32 PM
post your circuit and code

gates2231
01-17-2009, 07:02 PM
hai here is my code

/*----------------------------------------------------------------
-----------------HEADER FILES-------------------------------------
-----------------------------------------------------------------*/
#include "lcd.c"
#include "serial.c"
#include "adc.c"

/*----------------------------------------------------------------
-----------------MAIN FUNCTION------------------------------------
-----------------------------------------------------------------*/

void main()
{
unsigned int i,j,a,b,k;
unsigned char del[2]={0x08,0X08}; //for deleting previous reading

//Lcd startups
Init_Ports();
Init_Lcd();

//ADC startups
Init_ADC();
//Read_ADC(void)




b=0;

do
{
a=Read_ADC();
if(a!=b)
{
//first delete the previous values for uart
for(i=0;i<2;i++)
{
TransmitByte(del[i]);
}

//for LCD we require initialiatization
Init_Lcd();
for(i=0;i<12;i++)
Lcd_Send(str[i]);




j=a%10;

k=a/10;
k=k%10;
Lcd_Send((k+0x30));
TransmitByte((k+0x30));

Lcd_Send((j+0x30)); //since both will display ASCII values, we convert decimal to ASCII
TransmitByte((j+0x30));

b=a; //for next value
//delay sometime (1s) otherwise LCD display will run
delay(1000);
}

}
while(1);


}
void Init_ADC(void);
int Read_ADC(void);




void Init_ADC(void)
{


ADMUX|=(_BV(ADLAR) | _BV(REFS1)| _BV(REFS0)) ;
// RFS1 and RFS0 are for Internal Reference voltage of 2.56V AND 8 BIT CONVERSION
ADMUX&=~(_BV(MUX0)|_BV(MUX1)|_BV(MUX2)|_BV(MUX3)|_BV(MUX 4)); //SELECTING CHANNEL0
ADCSRA|=(_BV(ADEN) | _BV(ADPS2) | _BV(ADPS0)) ; //normal conversion without interrupt
ADCSRA&=~(_BV(ADSC)|_BV(ADATE)|_BV(ADIF)|_BV(ADIE)|_BV(AD PS1));//clock/32 speed

}

int Read_ADC(void)
{
ADCSRA|=_BV(ADSC); //start conversion
while(!((ADCSRA&_BV(ADIF))>>ADIF));
return ADCH;
}


[/img]

tijoseymathew
01-19-2009, 01:01 PM
*i didnt go through you code.

How random are the values ?? There will be some minute error, due to electical conditions , power lines, adc precision etc... If the error level is not too much you should not worry.

Another thing is have you properly isolated the led and the photodiode ? Is any stray light falling on the photodiode ?? You can get the correct reading only in a dark room.

So ineffect this sensor is no gud unless u use it in place where there is no light , or u use some clever code.. :roll:

allbits
01-20-2009, 12:46 AM
you are driving (sourcing) an IR led directly from the microcontroller. (you did not mention which) !!

Always use a driver (a simple transistor) to drive an IR LED at high currents.

Make sure the IR LED is glowing enough. use a mobile phone camera.

Connect a pot to the ADC, and rotate the POT and see if the adc values are correct. IF not, correct it.


that will solve it.