Industrial Grade Project

1. IoT-Based Industrial Machine Health Monitor (Vibration & Temperature)

  • Objective: Monitor continuous vibration (via MPU6050) and bearing temperature (via DS18B20) on rotating machinery, uploading data to an MQTT broker with local threshold alerts.
  • Component List:
    • ESP32 Development Board
    • MPU6050 Accelerometer/Gyroscope Sensor
    • DS18B20 Waterproof Temperature Sensor + $4.7\text{k}\Omega$ pull-up resistor
    • 0.96-inch OLED Display (I2C)
    • Buzzer & Status LEDs
  • Implementation Plan:
    1. Wire the sensors via the I2C and OneWire buses.
    2. Read raw accelerometer values and calculate vibration magnitude ($RMS$).
    3. Publish telemetry payloads via MQTT to an IoT dashboard (e.g., Node-RED or HiveMQ).
    4. Trigger a local buzzer alarm if vibration exceeds safe operating thresholds.

Firmware (Arduino IDE / ESP32)

C++

#include <Wire.h>
#include <WiFi.h>
#include <PubSubClient.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_MPU6050.h>
#include <OneWire.h>
#include <DallasTemperature.h>

const char* ssid = "YOUR_SSID";
const char* password = "YOUR_PASSWORD";
const char* mqtt_server = "broker.hivemq.com";

WiFiClient espClient;
PubSubClient client(espClient);
Adafruit_MPU6050 mpu;

#define ONE_WIRE_BUS 4
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

void setup() {
  Serial.begin(115200);
  Wire.begin(21, 22);
  sensors.begin();
  
  if (!mpu.begin()) {
    Serial.println("Failed to find MPU6050 chip");
    while (1) delay(10);
  }
  
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  client.setServer(mqtt_server, 1883);
}

void reconnect() {
  while (!client.connected()) {
    if (client.connect("ESP32MachineMonitor")) {
      Serial.println("Connected to MQTT");
    } else {
      delay(5000);
    }
  }
}

void loop() {
  if (!client.connected()) {
    reconnect();
  }
  client.loop();

  sensors.requestTemperatures();
  float tempC = sensors.getTempCByIndex(0);

  sensors_event_t a, g, temp;
  mpu.getEvent(&a, &g, &temp);
  float vibrationMagnitude = sqrt(sq(a.acceleration.x) + sq(a.acceleration.y) + sq(a.acceleration.z));

  String payload = "{\"temperature\":" + String(tempC) + ", \"vibration\":" + String(vibrationMagnitude) + "}";
  client.publish("factory/machine/status", payload.c_str());

  delay(5000);
}

2. IoT Smart EV Charger Sub-Meter & Overload Protector

  • Objective: Monitor voltage, current, and energy consumption of an EV charger using a PZEM-004T module, with remote cutoff capability via an electromagnetic relay.
  • Component List:
    • ESP32 Development Board
    • PZEM-004T V3.0 AC Power Meter Module
    • 5V 1-Channel Electromagnetic Relay Module
    • Current Transformer (CT) coil (included with PZEM)
    • AC Power Plug & Socket terminal blocks
  • Implementation Plan:
    1. Interface the PZEM module via SoftwareSerial pins on the ESP32.
    2. Continuously query active power, voltage, and current.
    3. Expose a web server endpoint on the ESP32 to remotely toggle the relay or trip automatically if current exceeds $16\text{A}$.

Firmware

C++

#include <WiFi.h>
#include <WebServer.h>
#include <PZEM004Tv30.h>

PZEM004Tv30 pzem(Serial2, 16, 17); // RX, TX
WebServer server(80);

const int relayPin = 23;
const char* ssid = "YOUR_SSID";
const char* password = "YOUR_PASSWORD";

void handleRoot() {
  float voltage = pzem.voltage();
  float current = pzem.current();
  float power = pzem.power();
  float energy = pzem.energy();

  String html = "<h1>EV Charger Dashboard</h1>";
  html += "<p>Voltage: " + String(voltage) + " V</p>";
  html += "<p>Current: " + String(current) + " A</p>";
  html += "<p>Power: " + String(power) + " W</p>";
  html += "<p>Energy: " + String(energy) + " kWh</p>";
  server.send(200, "text/html", html);
}

void setup() {
  Serial.begin(115200);
  pinMode(relayPin, OUTPUT);
  digitalWrite(relayPin, HIGH); // Turn ON relay by default

  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) delay(500);

  server.on("/", handleRoot);
  server.begin();
}

void loop() {
  server.handleClient();
  float current = pzem.current();
  if (!isnan(current) && current > 16.0) {
    digitalWrite(relayPin, LOW); // Trip relay on overload
  }
}

3. Cloud-Connected Industrial LOTO (Lockout/Tagout) Status Tracker

  • Objective: Track safety switch states across plant bays and log authorization stamps to a cloud database whenever maintenance personnel engage a LOTO hasp.
  • Component List:
    • ESP32 Development Board
    • 4x Mechanical Limit Switches / Microswitches
    • 4x $10\text{k}\Omega$ Pull-down Resistors
    • Status LEDs (Red/Green indicators)
  • Implementation Plan:
    1. Connect microswitches to digital input pins with internal/external pull-downs.
    2. Set up HTTP POST requests to send JSON logs to a cloud endpoint whenever a switch state changes.
    3. Provide real-time operational status on an internal web page.

Firmware

C++

#include <WiFi.h>
#include <HTTPClient.h>

const char* ssid = "YOUR_SSID";
const char* password = "YOUR_PASSWORD";
const char* serverUrl = "https://your-cloud-database-api.com/loto-logs";

const int switchPins[] = {12, 14, 27, 26};
bool lastState[] = {HIGH, HIGH, HIGH, HIGH};

void setup() {
  Serial.begin(115200);
  for (int i = 0; i < 4; i++) {
    pinMode(switchPins[i], INPUT_PULLUP);
  }
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) delay(500);
}

void loop() {
  for (int i = 0; i < 4; i++) {
    bool currentState = digitalRead(switchPins[i]);
    if (currentState != lastState[i]) {
      lastState[i] = currentState;
      if (WiFi.status() == WL_CONNECTED) {
        HTTPClient http;
        http.begin(serverUrl);
        http.addHeader("Content-Type", "application/json");
        String payload = "{\"bay\": " + String(i + 1) + ", \"status\": \"" + (currentState == LOW ? "LOCKED" : "UNLOCKED") + "\"}";
        http.POST(payload);
        http.end();
      }
    }
  }
  delay(200);
}

4. IoT Lithium-Ion Battery Pack Thermal & Voltage Telemetry Hub

  • Objective: Monitor individual cell-group voltages and temperature nodes across a 48V EV battery pack and stream metrics via Wi-Fi.
  • Component List:
    • ESP32 Development Board
    • ADS1115 16-bit 4-Channel ADC Module (for precise voltage division reading)
    • TMP36 or NTC 10K Thermistors
    • Optocouplers (PC817) for isolation
  • Implementation Plan:
    1. Connect scaled-down voltage taps through precision resistor dividers into the ADS1115.
    2. Read thermistor values across battery modules using analog inputs.
    3. Publish telemetry data via MQTT with timestamp stamps.

Firmware

C++

#include <Wire.h>
#include <Adafruit_ADS1X15.h>
#include <WiFi.h>
#include <PubSubClient.h>

Adafruit_ADS1115 ads;
const char* ssid = "YOUR_SSID";
const char* password = "YOUR_PASSWORD";
const char* mqtt_server = "broker.hivemq.com";

WiFiClient espClient;
PubSubClient client(espClient);

void setup() {
  Serial.begin(115200);
  Wire.begin(21, 22);
  ads.begin();
  
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) delay(500);
  client.setServer(mqtt_server, 1883);
}

void loop() {
  if (!client.connected()) {
    while (!client.connected()) client.connect("BatteryTelemetryNode");
  }
  client.loop();

  int16_t adc0 = ads.readADC_SingleEnded(0);
  float volts0 = ads.computeVolts(adc0) * 4.0; // Scaled factor for divider

  String payload = "{\"pack_voltage\":" + String(volts0) + "}";
  client.publish("ev/battery/telemetry", payload.c_str());
  delay(10000);
}

Complete Build Guide: Wiring, Libraries, Steps, Troubleshooting & FAQ

The four industrial IoT projects above share one platform: an ESP32 that reads industrial sensors and publishes data over Wi-Fi using MQTT or HTTP. This section adds what you need to actually build them – pin-to-pin wiring tables that match the code above, the exact Arduino libraries, a step-by-step bring-up procedure, a troubleshooting table and answers to common questions. Build and test each project on the bench before installing it near real machinery.

Safety note: Projects 2 and 4 involve mains AC and high-voltage battery packs. The PZEM-004T measures live 230 V AC, and a 48 V EV pack can deliver very high currents. Work only with power disconnected, use enclosures, fuses and isolation, and have a qualified electrician review any installation. These are learning prototypes, not certified safety equipment – in particular, a LOTO tracker must never replace a physical lockout procedure.

Arduino Libraries Used

Library (Library Manager name)Used InSource / License
ESP32 Arduino core (WiFi, WebServer, HTTPClient, Wire)Allespressif/arduino-esp32 – LGPL-2.1
PubSubClient (Nick O’Leary)1, 4knolleary/pubsubclient – MIT
Adafruit MPU6050 + Adafruit Unified Sensor1adafruit/Adafruit_MPU6050 – BSD
OneWire + DallasTemperature1PaulStoffregen/OneWire; milesburton/Arduino-Temperature-Control-Library – see repos
PZEM004Tv30 (Jakub Mandula)2mandulaj/PZEM-004T-v30 – MIT
Adafruit ADS1X154adafruit/Adafruit_ADS1X15 – BSD

Project 1 Wiring: Machine Health Monitor (MPU6050 + DS18B20)

ModulePinESP32 PinNotes
MPU6050VCC3V3
MPU6050GNDGND
MPU6050SDAGPIO21Wire.begin(21, 22)
MPU6050SCLGPIO22
DS18B20VDD (red)3V3
DS18B20GND (black)GND
DS18B20DATA (yellow)GPIO4ONE_WIRE_BUS 4
4.7 kΩ resistor—between GPIO4 and 3V3OneWire pull-up (required)
OLED (optional)SDA/SCLGPIO21/GPIO22Shares the I2C bus (address 0x3C; MPU6050 is 0x68)

Mount the MPU6050 rigidly on the motor or bearing housing (bolt or epoxy – double-sided tape absorbs vibration). The value published is the total acceleration magnitude, which reads about 9.8 m/s² at rest because it includes gravity; watch how it changes from that baseline rather than its absolute value. Note: the sketch above does not yet include the buzzer/LED alarm mentioned in the plan – add a pinMode(BUZZER_PIN, OUTPUT) on a free pin such as GPIO25 and switch it when the vibration deviation or temperature exceeds your threshold.

Project 2 Wiring: EV Charger Sub-Meter (PZEM-004T v3.0)

ModulePinESP32 PinNotes
PZEM-004T5VVIN / 5VTTL side needs 5 V
PZEM-004TGNDGND
PZEM-004TTXGPIO16 (RX2)PZEM004Tv30 pzem(Serial2, 16, 17) – RX first
PZEM-004TRXGPIO17 (TX2)
Relay moduleVCC / GNDVIN / GND
Relay moduleINGPIO23relayPin = 23
PZEM CT coil—around the live wire onlyDo not clamp live and neutral together

The code writes HIGH to GPIO23 to keep the relay “ON” and LOW to trip it. Check whether your relay board is active-HIGH or active-LOW and swap the levels if needed. Only the TTL side of the PZEM connects to the ESP32; the AC terminals and the relay contacts carry mains voltage. A small hobby relay is not rated to break a 16 A EV charging current – use it to drive a properly rated contactor.

Project 3 Wiring: LOTO Status Tracker

SwitchESP32 PinOther Side of SwitchStatus LED (optional)
Bay 1GPIO12GND—
Bay 2GPIO14GND—
Bay 3GPIO27GND—
Bay 4GPIO26GND—

The code uses INPUT_PULLUP, so connect each microswitch between its GPIO and GND – the external 10 kΩ pull-down resistors listed in the parts list are not needed with this code. A closed switch reads LOW and is reported as “LOCKED”. GPIO12 is a boot-strapping pin on the ESP32: if the board fails to boot while a bay switch is closed, move Bay 1 to GPIO25 or GPIO33 and update switchPins[]. Replace serverUrl with your own API endpoint.

Project 4 Wiring: Battery Telemetry Hub (ADS1115)

ModulePinESP32 / CircuitNotes
ADS1115VDD3V3
ADS1115GNDGNDMust share ground with the divider reference
ADS1115SDAGPIO21
ADS1115SCLGPIO22
ADS1115ADDRGNDI2C address 0x48 (default for ads.begin())
ADS1115A0Divider mid-pointCode multiplies by 4.0 – use a 3:1 divider (e.g., 30 kΩ top / 10 kΩ bottom)

With the default gain (±6.144 V range) and a ×4 divider, the maximum measurable input is limited by the 3.3 V supply on the ADS1115 inputs, i.e. about 13 V. A full 48 V pack (up to ~54.6 V) needs a much larger ratio, such as 200 kΩ / 10 kΩ (×21), and the 4.0 factor in the code must be changed to match your actual divider. Always keep every ADS1115 input between GND and VDD.

Step-by-Step Bring-Up (All Projects)

  1. Install the ESP32 board package and the libraries in the table above from Arduino IDE Library Manager.
  2. Wire one project on a breadboard exactly as in its wiring table, with no mains or battery connected.
  3. Enter your Wi-Fi SSID and password (and MQTT broker or API URL) in the sketch.
  4. Select ESP32 Dev Module, upload, and open Serial Monitor at 115200 baud.
  5. For MQTT projects, subscribe to the topic (e.g. factory/machine/status) with MQTT Explorer or mosquitto_sub -h broker.hivemq.com -t factory/# to see live data.
  6. Verify each sensor value against a reference (a thermometer, a known load, a multimeter).
  7. Move to a private MQTT broker with username/password (and TLS) before real deployment – public brokers like broker.hivemq.com are visible to everyone.
  8. Mount the electronics in an IP-rated enclosure with strain relief on all cables, then install on the machine.

Troubleshooting

ProblemLikely CauseFix
“Failed to find MPU6050 chip”Wrong I2C wiring or addressCheck SDA=21, SCL=22; run an I2C scanner (expect 0x68).
DS18B20 reads −127 °CMissing 4.7 kΩ pull-up or wrong pinAdd the resistor between DATA and 3V3; confirm GPIO4.
PZEM returns NaNTX/RX swapped or no AC on the PZEMSwap GPIO16/17; the PZEM needs AC voltage connected to answer.
MQTT never connectsWi-Fi OK but broker blockedCheck port 1883 on your network; use a unique client ID per device.
ESP32 will not boot (Project 3)GPIO12 pulled LOW/HIGH at bootMove that switch to another GPIO.
ADS1115 values look wrongDivider factor in code does not match hardwareMeasure the pack and divider with a multimeter and set the correct multiplier.

Frequently Asked Questions

Can these projects run on Arduino Uno?

Not as written – they rely on the ESP32’s Wi-Fi, 3.3 V I/O and libraries such as WebServer and HTTPClient. Use an ESP32 (or an ESP8266 with code changes).

Which MQTT dashboard should I use?

Node-RED dashboard, Grafana with InfluxDB, or Home Assistant all work well. For quick tests, MQTT Explorer shows topics without any setup.

Is this “industrial grade”?

The firmware patterns are the same as in industrial IIoT, but hobby modules are not certified. For real plants, use industrial-rated sensors, an ESP32 in a proper DIN-rail enclosure, watchdog timers and secured MQTT.

How do I add alerts?

Compare readings with thresholds in loop() and drive a buzzer or relay locally, and/or publish to an alert topic that your dashboard turns into a phone notification.