IR Light Beam Circuits

Use an IR LED and phototransistor pair to create a light beam switch. Point the components at each other to turn the switch on, then break the beam to turn the switch off. Use to detect when of your machine passes by a particular point. Or, bounce the light from the diode off a part to reflect back onto the detector. If the part is there, light will reach the detector and the signal can be passed to your Arduino. An IR LED/detector pair is exactly how your TV remote works. You can control your TV from across the room because the diode is pulsed briefly at a much higher current which gives off much more light.

IR LED: (e.g. Radio Shack 276-143 or Jameco 106526.) Connect like an ordinary LED using a 330 ohm series resistor to the +5 supply (or to an Arduino pin if you want to switch the source on and off). Current draw is about 11 mA with a 330 ohm resistor. Current runs from anode to cathode. Flat on the case marks the cathode. To determine if the IR LED is the right way around, use a DMM to measure the voltage between the two leads while in the circuit. If it is 5 V, it is the wrong way around. If it is about 1.1 V, it is the right way around.

IR Phototransistor (e.g. Radio Shack 276-145 or Jameco 112168.) A phototransistor is just like a regular transistor except the base lead is disabled or absent and light activates base current. The flat on the case marks the collector, the other lead is the emitter. Connect the collector to one end of a 10K resistor and connect the other end of the resistor to a +5V supply (you can use the +5 pin on the Arduino). Connect the emitter to ground. To view output, use a DMM to measure the voltage at the collector. The voltage should start out at +5V. When pointing the IR diode at the phototransistor, the voltage should drop down to near zero. To interface with the Arduino, make a second connection from the collector to an Arduino pin (for the example below use Pin 4).

Circuit Use the figure below as a guide for connecting the sensor/detector pair. To test, point them directly at each other separated by 2-4 inches.

Telling them apart The IR LED and the IR phototransistor can look exactly alike. If you don't know which is which, try them in the test circuit described above, and swap the pair and flip the orientation of each until it works. There are only four possible combinations so it should not take very long. IR light can be seen by most digital cameras, so another way to tell if the LED is working is to point your cell phone camera at what you think is the LED and look for the beam.


The LED and sensor need to be pointed directly at each other, no more than 4 inches apart, as shown in the figure below. Add a light blocking tube (e.g. a straw) around the sensor so that stray light does not get in the way.

Another configuration is to have the light bounce off a reflective surface (e.g. white paper) on its way to the sensor as shown in the figure below. A black surface (e.g. black non-shiny tape or matte black paper) will block the beam. This can be the basis of a robot that follows a black line.

Test Program

Load this Arduino program which you can use to test the operation of the IR sensor
void setup() {
void loop() {

This is the simplest program you can use to test the operation of your IR sensor. Watch the numbers on the screen change between 1 and 0 as you block and unblock the sensor. If they don't change, measure the voltage at Pin 4 while you block and unblock the sensor. If the voltage does not change, disconnect the wire going to Pin 4 and measure the voltage on the wire (not on the pin). If it doesn't change, there is a wiring error, or the sensor or emmitter is in backwards or the sensor or emitter is bad. Note that the IRLED and phototransistor should be no more than two or three inches apart for this test, and they should be pointed exactly at each other.

Hint: The maximum reliable separation distance is about 3 inches. To increase the distance to around 4 inches, place a second 330 ohm resistor in parallel with the first, which will increase the current through the IRLED to around 22 mA, making a brighter beam.

Usage Example

This is the demo shown in the ME2011 lecture. Wire an LED through a 330 ohm resistor to Pin 2 in the standard manner. Connect the IR beam switch to Pin 4 as described above. The circuit is sensitive to ambient lighting. You can put each component in a dark tube to mask. Warning, if the circuit works perfectly in your room, it may or may not work in another location because the room lighting is different.

Load this program into your Arduino:

IR beam demo
#define LED 2
#define BEAM 4
byte i;
void setup()
void loop()

More Distance

If you need more than 4 inches, you can remove the IR LED and instead shine a red laser pointer directly at the IR phototransistor. Breaking the laser beam turns the switch on and off. This circuit is sensitive to alignment so be sure the laser pointer is pointing straight at the phototransistor. Also, be sure that the laser pointer light can never get into the eyes of spectators.