How to build IR proximety sensor?

I tried to build this sensor and the IR led didn’t even turned on! so I made one of my baby orangutan I/O pins an output and connected only the phototransistor (the fototransistor has 2 legs) with the 10K resistor and the output exit I connected to an input pin in the baby O. this is the code:

int main(void)
{
//make pins input and output
DDRD |=(1<<PD0);
DDRB |=(1<<PB5) | (1<<PB4);
DDRD &=~(1<<PD2);

//enable PD2 pullup resistor
PORTD |= (1<<PD2);
//endless loop
for (;;)
{
//turn IR led on using the output pin PD0
PORTD |=(1<<PD0);
//give power to the fototransistor connected to pin PB4
PORTB |=(1<<PB4);
//delay for 0.5 second
delay_sec(1);

//check the input from the fototransistor
if((PIND & (1<<PD2))>0)
{
//turn red led connected to pin PB5
PORTB |=(1<<PB5);
}
else
//turn red led off
{
PORTB &=~(1<<PB5);
}
}
}

the IR led is working just fine, I think that my problem us that I don’t know how to read the output of the fototransistor…

thanks

Arbel
[/code]

I got it! it’s ok!

arbel, might posting diagram of your sensors and the code you finished out? Would be helpful to us, the noobsters :smiley:

P.S.: Yeah, 1 year+ old topic :frowning: