Provided a high-sensitivity ITR9909 photo-reflector, Grove - IR Distance Interrupter v1.2 can be used to detect if there is an object presenting in front of it. The photo-reflector consists of a GaAs infared light emitting diode and a silicon planar phototransistor. When an object is placed right in front of the sensor, the reflective infrared light emitted from the emitter will be picked up by phototransistor and then outputs logical HIGH or logical LOW according to the distance between the reflection surface and the sensor.
By adjusting the potentiometer, you can set the detection threshold value in a range from about 90mm to 300mm if the reflection surface is a piece of white paper. An indicator LED is used to visualize the result of measurement as it will lights up bright red when an object is detected, and go off when there is nothing.
Features
-
Easy to use
-
Integrated indicator LED
-
Digital output
-
Adjustable detecting range
Specification
-
Power supply: 5V DC
-
Reflective photo sensor: ITR9909
-
Digital output mode: TTL (High when black is detected, Low when white is detected)
-
Connector: 4 pin Buckled Grove interface
-
Dimension: 20mm*20mm
Software Drivers
Arduino
void setup() { Serial.begin(9600); pinMode(6,INPUT); } void loop() { while(1) { delay(500); if(digitalRead(6)==LOW) { Serial.println("Somebody is here."); } else { Serial.println("Nobody."); } } }
Raspberry Pi
#!/usr/bin/env python
#
#
# SwitchDoc Labs, August 2019
#
import RPi.GPIO as GPIO
import sys
import time
MouseDetectionPin = 4
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
def SetupMouseDetector():
GPIO.setup(MouseDetectionPin, GPIO.IN)
def CheckMousePresent():
MousePresent = GPIO.input(MouseDetectionPin)
return MousePresent
SetupMouseDetector()
while (True):
if (MouseDetector.CheckMousePresent() == 0):
print ('Mouse Detected')
else:
print ('Mouse NOT Detected')
time.sleep(0.3)