Fareed Mohmed← Project library

Engineering · Raspberry Pi · Project 47 of 47 · Industrial automation · Advanced

Light-curtain safety interlock

A conveyor motor may run only while the light curtain is clear and the emergency stop is released. Any interruption stops it, and an operator must press Start again.

▶ Open in the simulator

Raspberry Pi simulator drawing of the circuit for Light-curtain safety interlock: the board, its power supply and the parts wired to the 40-pin header
CAUTION: 230 V single-phase mains. The relay in this project switches a mains load (Live and Neutral, 230 V AC, 50 Hz in India). Mains can kill. Practise with the simulator or a low-voltage lamp. Build the mains side only with a qualified electrician, in a closed insulated box, behind a fuse or MCB and a 30 mA RCCB. Never touch the relay screw terminals while anything is connected.
Machine safety. This project only shows signalling and logic. A real emergency stop must cut power through hard-wired safety-rated contacts and relays and must never depend on software or a Raspberry Pi.

Parts in this circuit

PartType
Light curtainBeam sensor
Emergency stopPush button
StartPush button
Conveyor motorRelay module
RunningLED
Safety stopLED

Wiring, pin by pin

Red = 5 V, orange = 3.3 V, black = GND, other colours = signals. “Pin” is the position on the 40-pin header; the GPIO number is what the code uses. Power the Pi from a 5.1 V supply and wire with the power off.

#ColourFrom (part and leg)To (header pin)
1RedLight curtain - VCCPin 2 (5V)
2ColouredLight curtain - OUTPin 11 (GPIO17)
3BlackLight curtain - GNDPin 6 (GND)
4ColouredEmergency stop - SignalPin 29 (GPIO5)
5BlackEmergency stop - GNDPin 9 (GND)
6ColouredStart - SignalPin 13 (GPIO27)
7BlackStart - GNDPin 14 (GND)
8ColouredConveyor motor - INPin 15 (GPIO22)
9BlackConveyor motor - GNDPin 20 (GND)
10RedConveyor motor - VCCPin 4 (5V)
11ColouredRunning - anode +Pin 16 (GPIO23)
12BlackRunning - cathode -Pin 25 (GND)
13ColouredSafety stop - anode +Pin 18 (GPIO24)
14BlackSafety stop - cathode -Pin 30 (GND)

Python code (gpiozero)

from gpiozero import Button, OutputDevice, LED
from time import sleep

curtain = Button(17)                           # beam broken = pressed
estop = Button(5)                              # latched when pressed
start = Button(27)
motor = OutputDevice(22, active_high=False)
green = LED(23)
red = LED(24)

running = False
tripped = False

while True:
    safe = not curtain.is_pressed and not estop.is_pressed
    if not safe:
        if running or not tripped:
            print("SAFETY STOP: curtain broken or emergency stop pressed")
        running = False
        tripped = True
    elif start.is_pressed:
        if tripped:
            print("Safety circuit is clear again. Motor restarted by Start")
        tripped = False
        if not running:
            print("Motor RUNNING")
        running = True
    motor.value = running
    green.value = running
    red.value = tripped
    sleep(0.02)

How the code works

You will learn

  • An interlock: a condition that must hold for running
  • Latching a fault until the operator acts
  • Why a restart is a deliberate action

Try this

  • Press Start. Then click the beam sensor. The motor must stop and stay stopped.
  • Latch the emergency stop and press Start. Nothing should run.
  • Release the e-stop and press Start again.

On a real Pi

  • This shows the idea only. A real light curtain (Type 2 or 4, EN 61496) and a safety relay with redundant monitored contacts must do the safety job. A Raspberry Pi program must not.
  • Do a risk assessment for the machine before you use any guard.
  • Test the light curtain every shift with a test rod, as the manual says.

Parts to buy

The links open a search on each store, so you see what is in stock today. Check the model, voltage and price before you order.

#ItemQtyBuy / compare
1Raspberry Pi 4 Model B
about 4000 to 9000 INR
1Robu.in Amazon.in ThinkRobotics
2Official 15 W USB-C power supply (5.1 V, 3 A)
Do not use an old phone charger
1Robu.in Amazon.in ThinkRobotics
3microSD card 32 GB, class 10 / A1 (with Raspberry Pi OS)
And a card reader to write it
1Robu.in Amazon.in ThinkRobotics
45 mm LED, red1Robu.in Amazon.in ThinkRobotics
55 mm LED, green1Robu.in Amazon.in ThinkRobotics
6330 ohm resistor, 1/4 W
One per LED
2Robu.in Amazon.in ThinkRobotics
7Tactile push button (12 mm, with cap)1Robu.in Amazon.in ThinkRobotics
8Emergency stop push button, NC contact (22 mm)1Robu.in Amazon.in ThinkRobotics
91-channel 5 V relay module with optocoupler
10 A 250 V AC contacts
1Robu.in Amazon.in ThinkRobotics
10230 V AC small fan1Robu.in Amazon.in ThinkRobotics
11Closed ABS enclosure (IP54) for the mains side1Robu.in Amazon.in ThinkRobotics
123-way screw terminal block (rated 10 A)1Robu.in Amazon.in ThinkRobotics
13MCB 6 A single pole and RCCB 30 mA (by an electrician)
Mains protection
1Robu.in Amazon.in ThinkRobotics
14IR beam / break-beam sensor pair (3.3 V compatible)1Robu.in Amazon.in ThinkRobotics
15Dupont jumper wires, male-to-female, 20 cm (pack of 40)1Robu.in Amazon.in ThinkRobotics
16Breadboard 830 points
For resistors and shared GND / 5 V
1Robu.in Amazon.in ThinkRobotics
← 46. Bottle filling stationAll projects

This is a learning tool. The simulator checks the program logic, not the electrical design. Never put more than 3.3 V on a GPIO pin.