Line Detection – Photodiodes and IR LEDs


The exact values of the resistors to use will depend what the IR sensor is being used for. Use a 150 – 500 Ohm (I use a 330 Ohm) resistor for the IR emitter. Use a 100 KOhm resistor for the receiver.

int sensor1 = A0; //connected to analog 0
int ledPin = 9;    // LED connected to digital pin 9

void setup()

void loop(){

  digitalWrite(ledPin, HIGH);         
  int sensor1pin = analogRead(sensor1);

When working with an IR transmitter/receiver pair it is very easy to be confused about which LED is the transmitter and which is the receiver.

To check that the transmitter is transmitting, power it through 5V with a 330Ohm resistor (or higher) and place it in front of a camera lens (note: Apple iPhones often have an IR filter so will not work). The naked eye cannot see if an IR LED is powered, but camera lenses will show the light as purple. I use my old laptop’s built-in camera lens to check.

To check that a receiver is a receiver, one only needs a multimeter. Measure the resistance of the photodiode and see if covering the diode increases its resistance. If it does, then its a receiver.