Gravity:Photo Interrupter Module Wiki - DFRobot

Introduction

The photo interrupter is a device that operates by blocking light with an object. Its main components include a light emitter and a light receiver, both arranged face-to-face within the same enclosure. When an object passes through the light path between the emitter and receiver, the receiver's light is obstructed, triggering the operation of the photoelectric sensor. The Gravity Photo Interrupter Module integrates a high-performance ITR9608 photoelectric switch, featuring a compact design and easy operation, making it the ideal choice for your electronic projects and applications. Whether it's for robotics, automation equipment, or counting systems, this module provides precise photoelectric detection and efficient signal processing for your projects.

Feature

Typical Applications

Specification

Pin Description

No. Silkscreen Function Description
1 D Output Signal
2 VCC Power Supply (Positive)
3 GND Power Supply (Negative)

micro:bit Usage Tutorial

Preparation

Hardware

Software

Project Description - MakeCode

Use a Photo Interrupter for detection and display the detected digital value on the micro:bit's LED matrix.

Hardware Connection - MakeCode

Connect the Photo Interrupter to the P2 pin on the IO Extender for micro:bit, as shown in the diagram below.

Example Program - MakeCode

Result

When the program is successfully downloaded, block the Photo Interrupter with an object. The indicator light on the sensor will turn on, and the micro:bit LED matrix will display 1. When the object is removed, the indicator light on the sensor will turn off, and the micro:bit LED matrix will display 0.

Project Description - MindPlus

Control the LED light using the Photo Interrupter. When the Photo Interrupter is blocked, the LED light will turn on; otherwise, the LED light will turn off.

Hardware Connection - MindPlus

Connect the Photo Interrupter to the P1 pin on the IO Extender for micro:bit, and connect the LED light to the P2 pin.

Example Program - MindPlus

Result

After the program is successfully downloaded, the LED light will turn on when the Photo Interrupter is blocked; otherwise, the LED light will turn off.

Arduino Usage Tutorial

Preparation

Hardware

Software

Project Description

Control the LED light with the Photo Interrupter. The LED light will turn on when the Photo Interrupter is blocked; otherwise, it will turn off.

Hardware Connection

Connect the Photo Interrupter to the P7 pin on the I/O Expansion Shield, and connect the LED light to the P4 pin.

Example Program - MindPlus

Example Program - Arduino IED

#define led 4
#define PI 7

void setup() {
  pinMode(led, OUTPUT);   // Set LED pin as output
  pinMode(PI, INPUT);     // Set Photo Interrupter pin as input
}

void loop() {
  int P = digitalRead(PI);   // Read the digital value of the Photo Interrupter
  if (P == 1) {              // Check if the Photo Interrupter is blocked
    digitalWrite(led, HIGH); // If yes (blocked), turn on the LED
  } else {
    digitalWrite(led, LOW);  // If not (not blocked), turn off the LED
  }
}

Result

After the program is successfully downloaded, the LED light will turn on when the Photo Interrupter is blocked; otherwise, the LED light will turn off.

UNIHIKER Usage Tutorial

Preparation

Hardware

Software

Usage Tutorial

Project Description - Graphical Programming

Using a photo interrupter for counting and displaying the accumulated quantity on the UNIHIKER screen.

Hardware Connection - Graphical Programming

Connect the photo interrupter to pin P24 on the UNIHIKER, as shown in the diagram below.

Example Program - Graphical Programming

Result

After the program runs successfully, when an object blocks the photo interrupter, the indicator light on the sensor will illuminate. When the object is removed, the count on the UNIHIKER will increment by 1.

Project Description - Python Code

Control the LED light using the photo interrupter. The LED light will turn on when the photo sensor is blocked; otherwise, it will turn off.

Hardware Connection - Python Code

Connect the photo interrupter to pin P23 on the UNIHIKER, and connect the LED light to pin P24.

Example Program - Python Code

from pinpong.extension.unihiker import *
from pinpong.board import Board, Pin

# Initialize the board
Board().begin()

# Set up the input pin for the photo interrupter
p_p23_in = Pin(Pin.P23, Pin.IN)

# Main loop
while True:
    # Check if the photo interrupter is blocked
    if p_p23_in.read_digital():
        # If blocked, turn on the LED
        p_p24_out = Pin(Pin.P24, Pin.OUT)
        p_p24_out.write_digital(1)  # Turn on the LED
    else:
        # If not blocked, turn off the LED
        p_p24_out = Pin(Pin.P24, Pin.OUT)
        p_p24_out.write_digital(0)  # Turn off the LED

Note: You can refer to the MindPlus Code Programming Tutorial for a better understanding of how to use Python code mode in MindPlus.

Result

After the program runs successfully, cover the photo interrupter with an object, and the LED light will turn on. When the object is removed, the LED light will turn off.

FAQ

More questions and cool idea, please visit DFRobot Forum

More Documents

DFshopping_car1.png Get Gravity: Infrared Light Photo Interrupter Module from DFRobot Store or DFRobot Distributor.

Turn to the Top