Skip to main content
Engineering LibreTexts

Grove IR Interrupter Detector

  • Page ID
    51321
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)

     

    Grove IR Interrupter Detector.png

    The grove infrared reflector sensor is a digital device.

    Therefore it interfaces through a digital port.  The required input voltage is 5 volts.

    It is sensitive to reflected IR from 0 to 4.5 cm (1.77 inches).

     

    #!/usr/bin/python3
    #
    # SwitchDoc Labs, August 2019
    # Modification by Phil H Williams, May 25, 2021
    
    import RPi.GPIO as GPIO
    import time
    
    # Set the digital port (pin)
    pin = 5
    
    GPIO.setwarnings(False)
    GPIO.setmode(GPIO.BCM)           # Set up the GPIO.
    GPIO.setup(pin, GPIO.IN)         # In this example a digital input is used.
    
    while (True):
     if (GPIO.input(pin) == 0):      # Read the condition of the input on the pin and see if it is high (1) or low (0).
       print ('Object Detected')     # The if else block.
     else:  
       print ('Object NOT Detected')  
     time.sleep(0.3)
    

     

     

     


    Grove IR Interrupter Detector is shared under a not declared license and was authored, remixed, and/or curated by LibreTexts.

    • Was this article helpful?