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.

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
| Part | Type |
|---|---|
| Start | Push button |
| Stop | Push button |
| Overload trip | Push button |
| Contactor and motor | Relay 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.
| # | Colour | From (part and leg) | To (header pin) |
|---|---|---|---|
| 1 | Coloured | Start - Signal | Pin 13 (GPIO27) |
| 2 | Black | Start - GND | Pin 6 (GND) |
| 3 | Coloured | Stop - Signal | Pin 29 (GPIO5) |
| 4 | Black | Stop - GND | Pin 9 (GND) |
| 5 | Coloured | Overload trip - Signal | Pin 31 (GPIO6) |
| 6 | Black | Overload trip - GND | Pin 14 (GND) |
| 7 | Coloured | Contactor and motor - IN | Pin 11 (GPIO17) |
| 8 | Black | Contactor and motor - GND | Pin 20 (GND) |
| 9 | Red | Contactor and motor - VCC | Pin 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
- Press and release Start. The motor keeps running because the MOTOR contact in parallel with START feeds the rung from the output itself. This is called a seal-in or holding contact.
- Press Stop: the NC contact opens, the rung loses power, and the motor drops out. Releasing Stop does not restart the motor. You must press Start again.
- The overload trip is also NC in series. Click it to latch it: the motor stops and cannot start until you click it again.
- The Python line "run = (start or motor) and not stop and not overload" is the same rung as the diagram.
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.
| # | Item | Qty | Buy / compare |
|---|---|---|---|
| 1 | Raspberry Pi 4 Model B about 4000 to 9000 INR | 1 | Robu.in Amazon.in ThinkRobotics |
| 2 | Official 15 W USB-C power supply (5.1 V, 3 A) Do not use an old phone charger | 1 | Robu.in Amazon.in ThinkRobotics |
| 3 | microSD card 32 GB, class 10 / A1 (with Raspberry Pi OS) And a card reader to write it | 1 | Robu.in Amazon.in ThinkRobotics |
| 4 | Tactile push button (12 mm, with cap) | 2 | Robu.in Amazon.in ThinkRobotics |
| 5 | Latching push button switch | 1 | Robu.in Amazon.in ThinkRobotics |
| 6 | 1-channel 5 V relay module with optocoupler 10 A 250 V AC contacts | 1 | Robu.in Amazon.in ThinkRobotics |
| 7 | 230 V AC small fan | 1 | Robu.in Amazon.in ThinkRobotics |
| 8 | Closed ABS enclosure (IP54) for the mains side | 1 | Robu.in Amazon.in ThinkRobotics |
| 9 | 3-way screw terminal block (rated 10 A) | 1 | Robu.in Amazon.in ThinkRobotics |
| 10 | MCB 6 A single pole and RCCB 30 mA (by an electrician) Mains protection | 1 | Robu.in Amazon.in ThinkRobotics |
| 11 | Dupont jumper wires, male-to-female, 20 cm (pack of 40) | 1 | Robu.in Amazon.in ThinkRobotics |
| 12 | Breadboard 830 points For resistors and shared GND / 5 V | 1 | Robu.in Amazon.in ThinkRobotics |
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.