Lesson 16 Photo-interrupter

Share for us


A photo-interrupter is a sensor with a light-emitting component and light-receiving component packaged face to face. It applies the principle that light is interrupted when an object passes through the sensor. Therefore, photo-interrupters are widely used in speed measurement.


– 1 * SunFounder Uno board

– 1 * USB data cable

– 1 * Photo-interrupter module

– 1 * 3-Pin anti-reverse cable

Experimental Principle

Basically a photo-interrupter consists of two parts: transmitter and receiver. The transmitter (e.g., an LED or a laser) emits light and then the light goes to the receiver. If the light beam between the transmitter and receiver is interrupted by an obstacle, the receiver will detect no incident light even for a moment and the output level will change. In this experiment, we will turn an LED on or off by using this change.

Experimental Procedures

Step 1: Build the circuit

Step 2: Program (Please refer to the example code in LEARN -> Get Tutorial on our website)

Step 3: Compile

Step 4: Upload the sketch to SunFounder Uno board

Now, stick a piece of paper in the gap of the sensor, and the LED attached to pin 13 on the SunFounder Uno will go out; remove the paper, and then the LED will light up again.


With paper interrupting


const int photoPin = 7; //the number of the key pin
const int ledPin = 13;//the number of the led pin
void setup()
  pinMode(ledPin,OUTPUT);//initialize the led pin as output
void loop()
  boolean Value=digitalRead(photoPin);
  //if it is,the state is HIGH
  if(Value ==HIGH )
    digitalWrite(ledPin,LOW);//turn on the led
    digitalWrite(ledPin,HIGH);//turn off the led