The ESP8266 IoT sensor node reads temperature and humidity from a DHT11 sensor and computes vibration from an MPU6050 accelerometer, then publishes all three values to ECE-BOT every two seconds via an encrypted MQTT connection. This page covers hardware wiring, vibration calculation, required libraries, and the steps to flash the firmware.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Kr-Yogsa/ECE-BOT/llms.txt
Use this file to discover all available pages before exploring further.
Hardware required
| Component | Purpose |
|---|---|
| NodeMCU ESP8266 | Microcontroller with built-in Wi-Fi |
| DHT11 | Temperature and humidity sensor |
| MPU6050 | 3-axis accelerometer used to derive vibration |
| 10 kΩ resistor | Pull-up for bare 4-pin DHT11 (module variant already includes it) |
| Jumper wires | Connections |
Wiring connections
All three components share the ESP8266’s 3.3 V rail and a common ground.DHT11
| DHT11 pin | NodeMCU pin |
|---|---|
| VCC | 3V3 |
| GND | GND |
| DATA | D4 (GPIO2) |
If you have the bare 4-pin DHT11 (not the ready-made module), place a 10 kΩ pull-up resistor between DATA and 3V3. Module variants already include this resistor on the breakout board.
MPU6050
| MPU6050 pin | NodeMCU pin |
|---|---|
| VCC | 3V3 |
| GND | GND |
| SDA | D2 (GPIO4) |
| SCL | D1 (GPIO5) |
| AD0 | GND |
| INT | Not connected (not required for this version) |
How vibration is calculated
The firmware computes vibration entirely on the ESP8266 before publishing. The server receives only the final scalar value, not raw accelerometer axes. The algorithm inreadVibrationRms():
- Collect 50 accelerometer samples from the MPU6050 with a 20 ms delay between each.
- Convert each raw acceleration reading to g (divide by 9.80665 m/s²).
- Compute the vector magnitude for each sample:
√(x² + y² + z²). - Calculate the mean magnitude across all 50 samples.
- Compute the RMS of deviations from that mean:
√(Σ(magnitude − mean)² / N). - Publish the resulting
vibrationvalue to MQTT.
0. Increasing mechanical activity raises the value proportionally.
MQTT payload format
Each publish sends a JSON object to the topicfactory/machine/<machine_id>/telemetry:
The
timestamp field is currently uptime-based, not real UTC. The ESP8266 has no real-time clock and starts counting from the Unix epoch on each boot. For production use, add NTP sync so the timestamp reflects actual wall-clock time.Arduino libraries required
Install all four libraries through the Arduino IDE Library Manager (Sketch → Include Library → Manage Libraries):| Library | Purpose |
|---|---|
PubSubClient | MQTT client for the ESP8266 |
DHT sensor library | Reads temperature and humidity from DHT11 |
Adafruit MPU6050 | Reads accelerometer data from MPU6050 |
Adafruit Unified Sensor | Dependency for the Adafruit MPU6050 library |
Setup and flash
Install Arduino IDE
Download and install Arduino IDE 2. Version 2 is recommended for its improved library manager and board package support.
Add ESP8266 board support
Open File → Preferences and paste the following URL into the Additional boards manager URLs field:Then open Tools → Board → Boards Manager, search for
esp8266, and install the ESP8266 by ESP8266 Community package.Install required libraries
Open Sketch → Include Library → Manage Libraries and install:
PubSubClientDHT sensor library(by Adafruit)Adafruit MPU6050Adafruit Unified Sensor
Configure Wi-Fi and MQTT credentials
Open
esp8266_mqtt_sensor.ino and edit the credential constants near the top of the file:MACHINE_ID must match the machine ID configured in ECE-BOT. MQTT_TOPIC must follow the pattern factory/machine/<machine_id>/telemetry.Select the board and port
Connect the NodeMCU to your computer via USB. In Arduino IDE, go to Tools → Board and select NodeMCU 1.0 (ESP-12E Module). Then go to Tools → Port and select the serial port for your device.