KY-010 Photo Interrupter Module | Optical Broken Module as a momentary switch with Arduino

This post shows how to trigger your lights or electrical appliance ON or OFF with the working of Photo Interrupter Module or Optical Broken Module as a momentary switch using Arduino.


The Optical Broken Module

The Photo Interrupter Module detects if the pathway is optically broken or not.


You can buy it from here.

Parts Needed

You need to have the following parts

  • Arduino (Any version)
  • 1x KY-010
  • 1x One-Channel Relay module 5V
  • Jumper Wires
  • Light Lamp

For Arduino

Wiring Photo Interrupter Module

Pin Wiring KY-010 to Arduino
OUT Digital Pin – 2

Wiring Relay

Pin Wiring relay to the Arduino
S DIgital Pin – 13
+ 5V

Schematics For Arduino

Assemble all the parts by following the schematics below:


Connect the light lamp to the relay.

Coding Arduino

// constants won't change. They're used here to set pin numbers:
const int buttonPin = 2;     // the number of the Sensor pin
const int ledPin =  13;      // the number of the LED pin

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status

void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT_PULLUP);

void loop() {
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
  if (buttonState == HIGH) {
    // turn LED on:
    digitalWrite(ledPin, LOW);
  } else {
    // turn LED off:
    digitalWrite(ledPin, HIGH);
  • Upload the code to the Arduino.
  • Break the pathway and it will turn on the switch.