Fareed Mohmed← Project library

Engineering · Raspberry Pi · Project 22 of 47 · Industrial automation · Intermediate

Motor start/stop with a seal-in circuit

The most common PLC circuit in industry. A momentary Start button latches the motor on, and Stop or an overload trip drops it out. Watch the ladder diagram light up as you press.

▶ Open in the simulator

Raspberry Pi simulator drawing of the circuit for Motor start/stop with a seal-in circuit: 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
StartPush button
StopPush button
Overload tripPush button
Contactor and motorRelay module

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)
1ColouredStart - SignalPin 13 (GPIO27)
2BlackStart - GNDPin 6 (GND)
3ColouredStop - SignalPin 29 (GPIO5)
4BlackStop - GNDPin 9 (GND)
5ColouredOverload trip - SignalPin 31 (GPIO6)
6BlackOverload trip - GNDPin 14 (GND)
7ColouredContactor and motor - INPin 11 (GPIO17)
8BlackContactor and motor - GNDPin 20 (GND)
9RedContactor and motor - VCCPin 2 (5V)

Python code (gpiozero)

from gpiozero import Button, OutputDevice
from time import sleep

start = Button(27)                       # momentary, normally open
stop = Button(5)                         # real stop buttons are normally closed
overload = Button(6)                     # click it to latch the overload trip
motor = OutputDevice(17, active_high=False)   # contactor coil

# The ladder rung, written in Python:
#   run = (START or MOTOR) and not STOP and not OVERLOAD
# "or MOTOR" is the seal-in: once running, the motor holds itself on.
while True:
    run = (start.is_pressed or motor.value) and not stop.is_pressed and not overload.is_pressed
    if run != bool(motor.value):
        motor.value = run
        print("Motor RUNNING" if run else "Motor STOPPED")
    sleep(0.02)

How the code works

You will learn

  • The seal-in (latching) circuit
  • Normally open (NO) and normally closed (NC) contacts
  • Reading a ladder diagram next to the code

Try this

  • Press Start, release it, and watch the ladder. Why does the motor stay on?
  • Hold Stop and press Start. Does the motor start?
  • Add a second Start/Stop pair (a remote station) in parallel and series.

On a real Pi

  • Real stop buttons and overload relays use NC contacts, so a broken wire stops the machine (fail-safe). This simulator treats them as pressed = 1 to keep it simple.
  • The contactor coil is switched by the relay. Size the contactor for the motor current and use the motor protection relay, not code, for overload.
  • Safety stops (e-stops) must be hard-wired as in project 20.

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
4Tactile push button (12 mm, with cap)2Robu.in Amazon.in ThinkRobotics
5Latching push button switch1Robu.in Amazon.in ThinkRobotics
61-channel 5 V relay module with optocoupler
10 A 250 V AC contacts
1Robu.in Amazon.in ThinkRobotics
7230 V AC small fan1Robu.in Amazon.in ThinkRobotics
8Closed ABS enclosure (IP54) for the mains side1Robu.in Amazon.in ThinkRobotics
93-way screw terminal block (rated 10 A)1Robu.in Amazon.in ThinkRobotics
10MCB 6 A single pole and RCCB 30 mA (by an electrician)
Mains protection
1Robu.in Amazon.in ThinkRobotics
11Dupont jumper wires, male-to-female, 20 cm (pack of 40)1Robu.in Amazon.in ThinkRobotics
12Breadboard 830 points
For resistors and shared GND / 5 V
1Robu.in Amazon.in ThinkRobotics
← 21. Conveyor sorter with a diverter gateAll projects23. Sequenced conveyor start and stop →

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.