
Raspberry Pi 5 Machine Monitor: SW-420 and PCF8574 Proteus Simulation

Hello friends, I hope you all are doing great. Today, I am going to share the Raspberry Pi 5 Machine Monitor: SW-420 and PCF8574 Proteus Simulation, the one hundredth project of our IoT Projects series. If you have searched for a Raspberry Pi machine monitoring system, how to count pulses from an SW-420 vibration sensor, how to use a PCF8574 with a Raspberry Pi, or how to measure machine utilisation, here is a complete one in a Proteus simulation. Factories pay a lot to know one simple number: how many hours a day each machine actually works.
Old machines have no network port, but every running machine shakes. This project screws an SW-420 vibration sensor to each of four workshop machines, a lathe, a mill, a drill and a compressor, and lets a Raspberry Pi 5 count the pulses each sensor gives. No pulses means the machine is idle, a steady stream means it is running, and a flood of pulses means it is running rough: something loose, worn or out of balance. The Pi ignores a single knock on the bench, logs every machine's running time, starts and utilisation, and lights a green or a red LED for each machine through a PCF8574 I/O expander. A dashboard shows it all from a laptop or a phone. In this tutorial, we will go through the circuit, how a vibration switch turns shaking into pulses, how to count them reliably in Python, how the PCF8574 drives LEDs with a single byte, and the code. Then we run a small workshop in the simulation. At the end, you can download the project with the program and every library file.
NOTICE: Our team has put a lot of effort into this project: the circuit, the code and every part in the simulation are our own work, and you get them all free. Your feedback is the fuel that keeps us going, so please tell us what you think in the comments below. And if our free projects help you, you can buy us a coffee. So, let's get started with the Raspberry Pi 5 machine monitor with SW-420 and PCF8574 in Proteus simulation:
What Does This Machine Monitor Do?
- Four machines: a lathe, a mill, a drill and a compressor, each with an SW-420 vibration sensor.
- Three states: IDLE, RUNNING or ROUGH, from the number of pulses each second.
- No false starts: a state counts only after 2 seconds in a row; a knock is reported and ignored.
- The numbers that matter: running time, starts, the longest run and utilisation for every machine.
- Status LEDs: green for running, red for rough, eight LEDs on one PCF8574.
- A dashboard: every machine at a glance, with a RESET for a new shift.
In the simulation, the SW-420 pop-ups shake each machine, and the PCF8574's pop-up shows the byte the Pi writes and which LEDs it sinks.
Components Used in the Proteus Simulation
All the parts come from our Proteus libraries, each with its own tutorial. The project zip at the end includes every LIB and DLL file.
| Part | Proteus device | Library post | Connection |
|---|---|---|---|
| Raspberry Pi 5 | RASPBERRY PI 5 | Raspberry Pi 5 Library for Proteus | PI1, machines.py, Ethernet 192.168.1.51 |
| SW-420 vibration sensor (x 4) | VIBRATIONSW420TEP | SW-420 Vibration Sensor Library for Proteus | U2 - U5: DO on GPIO17, 27, 22, 23 |
| PCF8574 I/O expander | IOEXPPCF8574TEP | PCF8574 IO Expander Library for Proteus | U1 at 0x20 on I2C1; P0 - P7 to the LEDs |
| Resistor network 330 ohm | RESNETSIP9TEP | Resistor Network Library for Proteus | RN1: the common on 3V3, the LEDs' anodes |
| 5 mm LEDs (4 green, 4 red) | LED5MMGREENTEP, LED5MMREDTEP | 5mm LED Library for Proteus | D1 - D8 |
| Laptop WiFi Monitor | LAPTOP WIFI MONITOR | Laptop WiFi Monitor | PC1 |
| Mobile WiFi Monitor | MOBILE WIFI MONITOR | Mobile WiFi Monitor | MOB1 |
Proteus Simulation of the Machine Monitor: the Circuit
| Signal | Raspberry Pi 5 | Goes to |
|---|---|---|
| M1 - M4 | GPIO17, GPIO27, GPIO22, GPIO23 (pins 11, 13, 15, 16) | the DO of the LATHE, MILL, DRILL and COMPRESSOR sensors |
| SDA / SCL | GPIO2 / GPIO3 (pins 3 / 5) | the PCF8574 (0x20) |
| PK1 - PK8 | - | the PCF8574's P0 - P7 to the LEDs' cathodes |
| 3V3 | pin 1 | the sensors, the PCF8574 and the resistor network's common |
Each sensor needs only three wires. The LEDs are wired the way an I/O expander likes them: each anode through one resistor of the network to 3V3, each cathode to an expander pin, so the expander sinks the current to turn an LED on. One SIP-9 network holds all eight resistors.
How the Machine Monitor Works
A Vibration Switch
The SW-420 is a spring switch in a small metal can: at rest the spring touches the centre pin and the switch is closed. Shake it and the spring flicks away for a millisecond or so, again and again. The module's LM393 comparator turns every opening into a clean HIGH pulse on DO, and its trimmer sets how strong a shake must be before the spring opens at all. The pulse rate grows with the vibration: about two dozen pulses a second on a machine running at half a g, around a hundred when something shakes at two g. It is not an accelerometer and it measures nothing exactly, but it tells idle from running from rough, which is all a utilisation monitor needs.
Counting Pulses in Python
A pulse lasts only a few milliseconds, far too short for a program that looks once a second. So the Pi does not poll the pins: lgpio claims each one as an alert line and a callback counts every rising edge in the background. Once a second the program reads the four counts, takes the difference from the last reading and divides by the real time that passed, giving pulses a second per machine. Dividing by the measured time and not the nominal second matters; a busy program never sleeps exactly one second.
From Pulses to States
Under 5 pulses a second the machine is IDLE, from 5 to 70 it is RUNNING, and 70 or more is ROUGH. A real workshop is full of knocks: a part dropped on the bench, a door slammed. Each of those gives one short burst of pulses. The program therefore changes a machine's state only when the new state has been seen two seconds in a row; a single odd second is reported as a short burst and ignored, so the running time stays honest.
Utilisation
Utilisation is the share of time a machine actually works: its running time divided by the time it was watched. A lathe that runs 3 hours in an 8 hour shift is at 37 %. It is the number that tells a workshop whether it needs another machine or just better planning, and it is what the dashboard shows for each machine, together with the starts and the longest run.
Eight LEDs on One Byte
The PCF8574 has no registers at all: the Pi writes one byte and the eight pins follow it. A 0 is a strong low that sinks an LED's current, a 1 is a weak pull-up that leaves it dark and doubles as an input. So the program builds one byte, a bit for each green and each red LED, inverts it because a 0 means on, and writes it only when a machine changes state.
The Python Code Explained
The program is machines.py, written for the Raspberry Pi 5 with lgpio for the GPIO and I2C, and http.server for the dashboard. The machines, their GPIO pins and the limits:
MACHINES = [('LATHE', 17), ('MILL', 27), ('DRILL', 22), ('COMPRESSOR', 23)]
IDLE_BELOW, ROUGH_FROM = 5.0, 70.0 # pulses a second
Each DO an alert line with a counting callback:
lgpio.gpio_claim_alert(chip, g, lgpio.RISING_EDGE)
counters.append(lgpio.callback(chip, g, lgpio.RISING_EDGE)) # (no function: it counts the rising edges)
Once a second, the rate from the real elapsed time:
rate = d / dt if dt > 0 else 0.0 # (the real elapsed time, not the nominal second)
The state, with the two-second confirmation:
return 'IDLE' if rate < IDLE_BELOW else 'ROUGH' if rate >= ROUGH_FROM else 'RUNNING'
change = cand if m['count'] >= CONFIRM else None
A single odd second is reported, not counted:
event('%s: a short burst (%d pulses in 1 s) - ignored, not a run' % (brief[0], brief[2]))
The LEDs: one byte, inverted, written only when it changes:
lgpio.i2c_write_byte(pcf, ~on & 0xFF)
Utilisation for the dashboard:
return 100.0 * m['run_s'] / span if span > 0 else 0.0
The dashboard's links are Refresh and RESET; /data gives every machine's state, rate, running time, starts and utilisation as JSON.
How to Run the Proteus Simulation
- Download the project zip below and install the library files and the TEPPi folder (the steps are under the download button).
- Open Pi-5-Machine-Monitor.pdsprj from the Proteus Simulation folder. Keep machines.py and the DLL files next to it.
- Press Play. Click a sensor (U2 - U5) and press Machine 0.5 g: two seconds later the machine is RUNNING and its green LED lights.
- Press Shaking 2 g on another for ROUGH, and Knock to see a burst ignored.
- Open the Laptop WiFi Monitor (press Go) for every machine's running time and utilisation.
Simulation Results: a Workshop in Proteus
We pressed Play and ran a small workshop: the lathe started, someone knocked the drill's bench, the mill took a heavy cut, the compressor shook loose, the lathe finished its job and the compressor was fixed. Each machine was shaken with its SW-420 pop-up's chips; the PCF8574's pop-up shows every byte the Pi wrote. The times are the program's clock; the whole run took 36.6 simulated seconds.
All Machines Idle
The program reported READY at 0.0 s and wrote 0xFF to the PCF8574: all eight pins weak-high, every LED dark. No sensor gave a pulse; the dashboard showed 0 of 4 machines working.
The Lathe Starts
We set the lathe's sensor to a running machine, 0.5 g. The first second gave 9 pulses, a candidate; the second confirmed it, and at 9.0 s the program reported LATHE RUNNING (23 pulses/s). The byte became 0xFE: P0 low, sinking the current of D1, the lathe's green LED.
A Knock Is Not a Run
Then someone knocked the drill's bench. The sensor's pop-up counted one burst of 20 openings. The program saw 20 pulses in one second, more than the 5 of IDLE, but the next second was quiet, so the state never changed: DRILL: a short burst (20 pulses in 1 s) - ignored, not a run. The drill's running time stayed at 0 s, exactly what the two-second confirmation is for.
A Heavy Cut and a Loose Compressor
The mill started a heavy cut at 1 g: MILL RUNNING (51 pulses/s) at 16.0 s, a busy but normal machine. Then the compressor shook at 2 g, the way a compressor does when its mounting works loose: COMPRESSOR ROUGH (89 pulses/s) - check the mounting and the bearings at 20.0 s. The byte became 0x7C: the green LEDs of the lathe and the mill and the red LED of the compressor. The dashboard: 3 of 4 machines working.
One detail from the pop-ups: the Pi counted somewhat fewer pulses than the sensors counted openings; the compressor gave about 100 openings a second in the model and 78 to 89 pulses a second on the Pi. A pulse rate from a spring switch is a rough measure, which is why the bands are wide: anything from 5 to 70 is running.
The Lathe Stops, the Compressor Is Fixed
The lathe finished its job: LATHE IDLE - that run 17.0 s at 26.0 s, and its green LED went out (0x7D). Then the compressor's mounting was fixed and it ran at a normal 0.5 g: COMPRESSOR RUNNING (21 pulses/s) at 32.0 s, red off, green on: 0xF5. The dashboard summed up 35 seconds of the workshop: the lathe 17.0 s running (49 %), the mill 18.0 s (52 %), the drill 0 s, the compressor 14.0 s (40 %).
The Pi's terminal has the whole run, with a line for all four machines every few seconds:
Download the Project Files
Click the button below to download Raspberry-Pi-5-Machine-Monitor-SW-420-PCF8574-Proteus-Simulation-v1.0.zip (about 14.0 MB, without the source code of the models):
Raspberry Pi 5 Machine Monitor: SW-420 and PCF8574 - Proteus Simulation V1.0- Proteus Simulation: Pi-5-Machine-Monitor.pdsprj, machines.py and copies of the models.
- Python Code: machines.py, the program.
- Proteus Library Files: the LIB files of every part.
- Proteus Model Files: the DLL models and the TEPPi folder (the Raspberry Pi runtime).
- README.txt: the installation steps, the properties, the test results and the links to every library post.
No Proteus yet? Read How to Download and Install Proteus 7 and 8. New to libraries? Follow How to Install a New Library in Proteus.
How to Install the Project Files
- Close Proteus and extract the whole zip file, for example to your Desktop.
- Copy the files from Proteus Library Files into the LIBRARY folder of Proteus.
- Copy everything in Proteus Model Files, the DLL files and the TEPPi folder, into the MODELS folder.
- Start Proteus and open the project from the Proteus Simulation folder.
Changing the Code
machines.py is plain Python; edit it in any editor and keep it next to the project. The machines, their pins and the limits are near the top. On a real Raspberry Pi 5, install python3-lgpio and run it with python3 machines.py.
Ideas to Extend the Project
- Keep a shift log in a CSV file: each machine's running time per hour, ready for a spreadsheet.
- Watch the trend of the pulse rate while running: a machine that slowly shakes more is wearing.
- Add four more machines with a second PCF8574 at 0x21 for their LEDs.
- Replace one SW-420 with an accelerometer on the most important machine for real vibration levels.
- Send a message when a machine runs ROUGH for more than a minute.
- Show the utilisation as bars on the dashboard and compare the shifts of a week.
From Simulation to Real Hardware
- Mounting: screw each sensor to a rigid part of the machine, not to a guard or a cover that rattles on its own.
- The trimmer: set each sensor on its own machine: idle should give no pulses, running a steady stream.
- The limits: machines differ; watch each one for a day and set its IDLE and ROUGH limits from what you see.
- Wiring: long sensor cables in a workshop pick up noise; use shielded cable and keep them away from motor leads.
- Levels: power the SW-420 modules from 3.3 V so their outputs are safe for the Pi's GPIO.
Troubleshooting
- A machine never leaves IDLE: its DO must reach its GPIO, and its vibration must pass the trimmer.
- A machine reads ROUGH while running normally: it pulses faster than most; raise ROUGH_FROM or turn its trimmer down.
- The running time includes knocks: CONFIRM is the number of seconds a new state must last; raise it.
- The LEDs stay dark: the expander must answer at 0x20 and the network's common must be on 3V3.
- No dashboard: the program serves on port 8000; open http://192.168.1.51:8000/.
Limitations of the Simulation
- The SW-420 and the PCF8574 are our libraries' models, built from their datasheets and the parts' behaviour, not every detail of real parts.
- The machines are the SW-420 pop-ups' chips: a machine starts and stops the moment a chip is pressed.
- A real shift lasts hours; the simulation runs a few minutes of a workshop's life.
- Raspberry Pi is a trademark of Raspberry Pi Ltd; this project is not made or endorsed by Raspberry Pi Ltd or by Labcenter.
So, that was all about the Raspberry Pi 5 Machine Monitor: SW-420 and PCF8574 Proteus Simulation. I hope it helps you understand how a cheap vibration switch can tell a machine's state, how to count fast pulses reliably in Python, and how one byte on a PCF8574 drives a row of status LEDs, all tested in a simulation before you mount anything on a machine. This was the one hundredth project of our IoT Projects series: one hundred complete Proteus simulations with the ESP32 and the Raspberry Pi 5, each with its circuit, its code and its download. Thank you for following along. If you have any questions, ask in the comments and I will help you out. Till the next tutorial, take care and have fun!






















Comments
0