7 years, 2 months ago.  This question has been closed. Reason: Opinion based - no single answer

How can I use AnalogIn to read my IR photodiode?

I am trying to create a program such that when Infrared Light is shined upon an IR photodiode, it is detected.

Currently I am using a FRDM K64F development board. I have connected a buzzer, an IR LED and a photodiode. The IR LED is shining quite brightly but the photodiode is not picking it up at all. /media/uploads/el14tt/frdm-k64f-pinnout-1.jpg

The Photodiode is connected in reverse bias, so that the long pin goes to ground and the short pin is pulled-up to 5V through a 3k resistor. The short pin is also connected to the microcontroller (Pin PTB10) through a Analog In pin. It is also important to note that the IR photodiode has a clear cover and so does not block out visible light. The link to the datasheet is here -> /media/uploads/el14tt/sfh_203_p-_sfh_203pfa.pdf

The code looks like this; IR Photodetector AnalogIn PD (PTB10);

int main() { initialise the board and serial port init_K64F(); lcd.init(); initialise display set-up the ticker so that the ISR it is called every 1.0 seconds ticker1.attach(&timer1_isr,1.0); each character is 6 pixels wide, screen is 84 pixels (84/6 = 14) so can display a string of a maximum 14 characters in length or create formatted strings - ensure they aren't more than 14 characters long char pdet[14];

while (1) {

check if flag is set i.e. interrupt has occured if (g_timer1_flag) { g_timer1_flag = 0; if it has, clear the flag float v = 5 * PD; sprintf(pdet,"v = %.2f V", v); lcd.printString(pdet,0,2); lcd.refresh(); } } }

So this code is similar to what I wrote for use with an LDR.

Can anyone tell me what it is that I'm doing wrong? The reading always states 5V, whether I block the light completely or place the IR LED in direct contact with the photodiode.

2 Answers

7 years, 2 months ago.

AnalogIn measures between 0V and 3.3V. So connect the resistor to 3.3V, and you hopefully see something changing. Otherwise your resistor is probably too small (yet still I expect some change).

7 years, 2 months ago.

A photodiode produces current in response to light. So you will likely need some signal conditioning before feeding into the analog input of your microcontroller. Although just the tip of the iceberg in terms of information out there on photodiode circuits, here are a couple of links to get you started. Some of the manufacturers that have good op-amps for photodiode applications are Texas Instruments, Analog Devices, Linear Technologies and Maxim.

http://www.hamamatsu.com/resources/pdf/ssd/si_pd_circuit_e.pdf

http://www.ti.com/lit/an/sboa061/sboa061.pdf