4. Photointerrupter

../_images/photointerrupter-1.jpg ../_images/photointerrupter-2.jpg

A photointerrupter is a transmission type photosensor which is made up of light receiving and emitting elements that are placed facing each other. This Sensor works when an object is placed between these elements resulting in light blockage. An object is detected by measuring the change in the current of the transistor. We observe large flow of current in the absence of an object whereas small flow of current in the presence of an object between the plates.

../_images/photointerrupter-principle.jpg

Source: http://www.rohm.com/web/global/electronics-basics/photointerrupters/what-is-a-photointerrupter/

4.1. Connecting the Sensor

Connect the VCC (middle pin) to a 5V pin.

Connect the ground to a ground pin.

Signal should be connected to a GPIO pin.

In this example:
  • Middle Pin(VCC) is connected to pin 2
  • The ground to pin 6
  • Signal Pin is connected to pin 8

Below are the connections of the sensor:

../_images/photointerrupter.jpg

4.2. Python Program to Show Photointerupter State

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)
Photointerrupter=8
GPIO.setup(LD,GPIO.IN)

while True:
    if (GPIO.input(Photointerrupter)== True):
        print "Object is Detected"

    else:
        print "Not Detected"
    time.sleep(1)