PDA

View Full Version : Sharp sensor problem!



rohitkondekar
09-08-2009, 12:56 AM
Hello Everyone!

Stuck in a problem here. I am using a Sharp IR sensor 2D120X for first time but not able to make it work.

I didn't had a sensor connector so I just soldered the wires according to configuration to the back of it where the three pins were rising.

[img]http://img403.imageshack.us/img403/2677/gp2d120back.jpg (http://www.imagehosting.com/)

Is this soldering right?

Then i had it connected to adc0; and 2 leds at PA7 and PA6.
But nothings working. Plz help me out.


#include<avr/io.h> //HEADER FILE FOR AVR INPUT OUTPUT
#include<compat/deprecated.h> //HEADER FILE FOR FUNCTIONS LIKE SBI AND CBI
#include<util/delay.h> //HEADER FILE FOR DELAY
#include<avr/interrupt.h> //Header for interrupts

/*----------------------------------------------------------------
-----------------MAIN PROGRAM-------------------------------------
-----------------------------------------------------------------*/
int main(void)
{
DDRA=0b11111111;
ADMUX=(1<<REFS0);// AVCC reference
ADMUX=(1<<ADLAR);//LEFT adjuct ADC result

ADCSRA=(1<<ADEN)|(1<<ADPS1)|(1<<ADPS0)|(1<<ADATE);//prescalar factor 128 and in free running mode
ADCSRA=(1<<ADIE);//Enable Interrupt
sei();
ADCSRA=(1<<ADSC);//start convertion

for(;;)
{
}


}



ISR(ADC_vect)
{
if(ADCH < 128)
{
sbi(PORTA,7);
sbi(PORTA,6);
}
else
{

cbi(PORTA,7);
cbi(PORTA,6);
}
}

allbits
09-08-2009, 09:51 AM
DOnt know about the code... I aint an AVR guy

but the connection is right.