Community project

IoT PPE Compliance Monitor

Photo of IoT PPE Compliance Monitor
Generated with AI

Ardam Kahfi

Published November 19, 2026

This IoT PPE Compliance Monitor uses an ESP32 microcontroller to receive real-time safety status updates from a Raspberry Pi 4 over WiFi and MQTT, displaying compliance state through LED indicators and an audio alarm. The system connects to a networked camera system that monitors PPE usage, translating detection results into immediate visual and audible feedback on the shop floor or work site.

The guide provides a complete wiring diagram showing how to connect the status LEDs, buzzer circuit with transistor switching, and power distribution, along with a full parts list, the Arduino firmware for the ESP32, and step-by-step assembly instructions. Builders will learn how to set up MQTT communication between the Pi and ESP32, configure WiFi credentials, and test the safety state transitions from a remote monitoring application.

Wiring diagram

Wiring diagram for IoT PPE Compliance Monitor
Loading diagram…

Gather all the parts

QtyComponent
1

LED

red

Standard 3mm/5mm through-hole LED. A current-limiting series resistor is added automatically.

1

LED

green

Standard 3mm/5mm through-hole LED. A current-limiting series resistor is added automatically.

1

Resistor

220 ohm

Through-hole resistor (current-limiting in series with an LED)

1

Resistor

220 ohm

Through-hole resistor (current-limiting in series with an LED)

1

Resistor

1k ohm

Through-hole resistor (current-limiting in series with an LED)

1

Resistor

10k ohm

Through-hole resistor (current-limiting in series with an LED)

1

NPN Transistor (2N2222 / BC547)

2N2222

General-purpose NPN bipolar junction transistor (BJT) in TO-92 package. Used as a low-side switch to drive loads (e.g. buzzers) whose current exceeds ESP32 GPIO source capability (~12 mA). A ~1 kΩ base resistor is placed between the ESP32 GPIO and the transistor base. The collector connects to the load negative terminal (buzzer –), and the emitter connects to GND. When the GPIO goes HIGH (3.3 V), the transistor saturates and switches the load on. Compatible with both 2N2222/2N2222A and BC547/BC547B variants. Add a flyback diode (e.g. 1N4148) across inductive load terminals.

1

1N4007 Diode

General-purpose silicon rectifier diode in DO-204AL (DO-41) axial through-hole package. Rated 1A average forward current and 1000V peak reverse voltage (VRRM). Forward voltage drop ~0.7V at typical load (up to 1.1V at full 1A). Used here in series with LM7805 Vout for reverse polarity protection: anode to LM7805 output, cathode to 5V rail, resulting in ~4.3V on the output rail. Not suitable for high-frequency switching (reverse recovery ~2µs–30µs); intended for DC or 50/60Hz rectification only.

1

5V active buzzer, maximum 20mA

Two-terminal internally driven DC buzzer. Select a verified maximum current of 20mA or less at 5V; not a passive transducer. Diode included for magnetic types.

1

USB-C 5V Adapter

Regulated 5V 4A supply with suitable separate output leads

USB-C wall adapter delivering regulated 5 V to the board's USB or VBUS rail. Default wired power source for desktop / stationary projects.

1

Raspberry Pi 4 Model B

Runs trained YOLO inference and MQTT broker; USB-C power and USB webcam. No GPIO connection to ESP32.

1

USB UVC webcam

USB-powered Linux-compatible camera; the only sensor. USB_HOST connection represents the complete USB cable including power and ground.

Assemble it in 4 steps

1. Connect the two indicator lights

Connect GPIO25 through its own 220-ohm resistor to the red LED long leg. Connect GPIO26 through the other 220-ohm resistor to the green LED long leg. Connect both short legs to ESP32 GND.

2. Build the buzzer switch

Connect GPIO23 through 1k ohm to the transistor base. Connect 10k ohm between base and ground. Connect emitter to ground and collector to buzzer minus. Connect buzzer plus to regulated 5V. Put the diode across the buzzer, banded cathode to plus and anode to minus.

  • Check the exact 2N2222 package datasheet for base, collector and emitter; lead order varies. Use a 5V active buzzer rated at no more than 20mA. Never wire the buzzer directly to GPIO23.

3. Connect regulated power

Use an enclosed regulated 5V 4A supply with suitable separate leads. Feed Pi power through its USB-C connector, ESP32 through its 5V input, and buzzer through the 5V rail. Connect supply negative to ESP32 ground and Pi power ground. The supply must maintain 5V under computer and camera load.

  • Unplug external ESP32 5V power before connecting PC USB for Deploy to prevent backfeeding. Do not connect 5V to 3V3 or any GPIO. Do not handle mains wiring.

4. Connect the only sensor

Plug the Linux-compatible USB webcam into a Pi USB host socket. Aim it at the monitored work area. Pi and ESP32 communicate over the local network, not GPIO wires.

  • This is an advisory prototype, not a certified safety interlock. Occlusion and missed people can cause incorrect results; keep independent workplace safety procedures.

Review all connections

1. Connections between "rred" and "ESP32"

FunctionrredESP32
digitalP1GPIO 25
digitalP2 → LED ANODEEXT

2. Connections between "red" and "ESP32"

FunctionredESP32
groundGNDGND

3. Connections between "rgreen" and "ESP32"

FunctionrgreenESP32
digitalP1GPIO 26
digitalP2 → LED ANODEEXT

4. Connections between "green" and "ESP32"

FunctiongreenESP32
groundGNDGND

5. Connections between "rbase" and "ESP32"

FunctionrbaseESP32
digitalP1GPIO 23
digitalP2 → NPN Transistor (2N2222 / BC547) BASEEXT

6. Connections between "rpulldown" and "ESP32"

FunctionrpulldownESP32
digitalP1 → NPN Transistor (2N2222 / BC547) BASEEXT
groundP2GND

7. Connections between "transistor" and "ESP32"

FunctiontransistorESP32
groundEMITTERGND
digitalCOLLECTOR → 5V active buzzer, maximum 20mA MINUSEXT

8. Connections between "buzzer" and "ESP32"

FunctionbuzzerESP32
powerPLUS5V

9. Connections between "diode" and "ESP32"

FunctiondiodeESP32
powerAnode → 5V active buzzer, maximum 20mA MINUSEXT
powerCathode → 5V active buzzer, maximum 20mA PLUSEXT

10. Connections between "supply" and "ESP32"

FunctionsupplyESP32
power+5V5V
groundGNDGND

11. Connections between "pi" and "ESP32"

FunctionpiESP32
powerUSB_POWER → USB-C 5V Adapter +5VEXT
groundGND → USB-C 5V Adapter GNDEXT

12. Connections between "webcam" and "ESP32"

FunctionwebcamESP32
dataUSB → Raspberry Pi 4 Model B USB_HOSTEXT

Deploy the firmware

#include <Arduino.h>
#include <WiFi.h>
#include <PubSubClient.h>
// Edit these settings before Deploy. Use the Pi's reserved LAN address.
const char* WIFI_SSID = "YOUR_WIFI_NAME";
const char* WIFI_PASSWORD = "YOUR_WIFI_PASSWORD";
const char* MQTT_HOST = "192.168.1.100";
const char* MQTT_USER = "ppe";
const char* MQTT_PASSWORD = "CHANGE_ME";
constexpr uint8_t RED_PIN=25, GREEN_PIN=26, BUZZER_PIN=23;
constexpr uint32_t DATA_TIMEOUT_MS=3500;
WiFiClient transport;
PubSubClient mqtt(transport);
enum class State { SAFE, UNSAFE, EMPTY, UNKNOWN };
State result=State::UNKNOWN;
bool received=false;
uint32_t lastData=0, lastAttempt=0, lastWifiAttempt=0;
String clientId;
void outputs() {
  const uint32_t now=millis();
  State effective=(WiFi.status()==WL_CONNECTED && mqtt.connected() && received &&
    uint32_t(now-lastData)<DATA_TIMEOUT_MS) ? result : State::UNKNOWN;
  digitalWrite(GREEN_PIN, effective==State::SAFE);
  digitalWrite(BUZZER_PIN, effective==State::UNSAFE);
  digitalWrite(RED_PIN, effective==State::UNSAFE ||
    (effective==State::UNKNOWN && ((now/500)%2==0)));
}
void message(char* topic, byte* payload, unsigned int length) {
  if (strcmp(topic,"safety/ppe")!=0) return;
  // Exact uppercase plain-text messages only; malformed data clears SAFE.
  String text;
  if (length<=7) for (unsigned int i=0;i<length;i++) text+=char(payload[i]);
  if(text=="SAFE") result=State::SAFE;
  else if(text=="UNSAFE") result=State::UNSAFE;
  else if(text=="EMPTY") result=State::EMPTY;
  else result=State::UNKNOWN;
  received=true;
  lastData=millis();
  outputs();
}
void setup() {
  digitalWrite(RED_PIN,LOW); digitalWrite(GREEN_PIN,LOW); digitalWrite(BUZZER_PIN,LOW);
  pinMode(RED_PIN,OUTPUT); pinMode(GREEN_PIN,OUTPUT); pinMode(BUZZER_PIN,OUTPUT);
  Serial.begin(115200);
  WiFi.mode(WIFI_STA); WiFi.begin(WIFI_SSID,WIFI_PASSWORD);
  mqtt.setServer(MQTT_HOST,1883); mqtt.setCallback(message);
  mqtt.setSocketTimeout(1); mqtt.setKeepAlive(10);
  clientId="ppe-actuator-"+String((uint32_t)ESP.getEfuseMac(),HEX);
  outputs();
}
void loop() {
  uint32_t now=millis();
  outputs();
  if(WiFi.status()!=WL_CONNECTED) {
    received=false;
    if(mqtt.connected()) mqtt.disconnect();
    if(uint32_t(now-lastWifiAttempt)>=10000) {
      lastWifiAttempt=now; WiFi.reconnect();
    }
  } else if(!mqtt.connected()) {
    received=false;
    if(uint32_t(now-lastAttempt)>=3000) {
      lastAttempt=now;
      // Connection attempts happen with outputs already in UNKNOWN state.
      if(mqtt.connect(clientId.c_str(),MQTT_USER,MQTT_PASSWORD)) {
        if(!mqtt.subscribe("safety/ppe",0)) mqtt.disconnect();
        Serial.println("MQTT connected; waiting for fresh PPE data");
      }
    }
  } else mqtt.loop();
  outputs();
  delay(5);
}

Remix this project

Make it yours in one click

Open a full copy of this project in your own Schematik workspace, diagram, code, parts, and assembly steps included. Swap the sensor, add features, or redesign the whole thing with AI. The author's original stays untouched.

Open in Schematik