Build an IoT Smart Building Monitor Using ESP8266 and KiwisIoT Dashboard

by Keerthana Dass in Circuits > Electronics

21 Views, 0 Favorites, 0 Comments

Build an IoT Smart Building Monitor Using ESP8266 and KiwisIoT Dashboard

cover image.png

Smart buildings can use connected sensors to monitor electrical current, indoor temperature, humidity, and human movement. This project demonstrates a simple IoT-based smart building monitoring system using an ESP8266 NodeMCU, an ACS712 current sensor, a DHT11 temperature and humidity sensor, and a PIR motion sensor.

The ESP8266 collects sensor readings and sends them to a KiwisIoT dashboard over Wi-Fi. The dashboard displays five values: current, temperature, humidity, motion status, and overall building status.

This project is suitable for students, electronics enthusiasts, and beginners who want to explore IoT-based building monitoring.

Supplies

Hardware Components

  1. ESP8266 NodeMCU development board
  2. ACS712 current sensor module (30A version)
  3. DHT11 temperature and humidity sensor
  4. PIR motion sensor module
  5. DC motor and suitable power source for a low-voltage current-monitoring demonstration
  6. Breadboard and jumper wires
  7. USB cable for programming the ESP8266

Software and Platforms

  1. Arduino IDE 1.8.19
  2. ESP8266 board package
  3. KiwisIoT Arduino library
  4. DHT sensor library
  5. KiwisIoT dashboard

Understand How the Project Works

The system monitors three main aspects of a building:

  1. Electrical current: The ACS712 measures current flowing through the monitored load.
  2. Environmental conditions: The DHT11 measures temperature and relative humidity.
  3. Occupancy indication: The PIR sensor detects movement within its sensing range.

The ESP8266 reads the sensors every five seconds and sends the collected data to KiwisIoT.

When the PIR sensor detects motion, the dashboard displays MOTION DETECTED, and the building status changes to OCCUPIED. When motion is not detected, both status messages change accordingly.

Note that this is a demonstration of sensor-based monitoring. The motion sensor indicates detected movement, not guaranteed human occupancy, and the current sensor does not directly measure total energy consumption.

Make the Circuit Connections

smart_building_circuit_832x551.png

Connect the components to the ESP8266 NodeMCU as follows.

ACS712 Current Sensor

VCC → VIN
GND → GND
OUT → A0

Connect the monitored load through the ACS712 module's current-carrying terminals according to the module's wiring diagram. The load current must pass through the sensor for it to be measured.

DHT11 Temperature and Humidity Sensor

VCC → 3.3V
GND → GND
DATA → D5

PIR Motion Sensor

VCC → 3.3V
GND → GND
OUT → D6

Make sure the sensor outputs are compatible with the ESP8266's input voltage limits.

Important: The code assumes that the voltage at A0 ranges from 0 to 3.3V. NodeMCU boards differ in their A0 input circuitry, so verify your specific board's permitted A0 voltage and the ACS712 output range before connecting them. Use appropriate signal conditioning if required. Never connect mains voltage directly to a breadboard or an exposed sensor circuit.

Set Up Arduino IDE

Install and configure Arduino IDE for the ESP8266 NodeMCU.

  1. Open Arduino IDE.
  2. Install the ESP8266 board package if it is not already installed.
  3. Select NodeMCU 1.0 (ESP-12E Module) under Tools → Board.
  4. Install the required libraries through Sketch → Include Library → Manage Libraries.

Install the DHT sensor library and any dependencies it requests. The ESP8266 Wi-Fi library is included with the ESP8266 board package, and KiwisIoT must be installed separately.

Create the KiwisIoT Dashboard

  1. Log in to your KiwisIoT account.
  2. Create a new panel named Smart Building Monitoring.
  3. Open the panel and copy its Topic ID.
  4. Add five widgets to display the data channels.
  5. Configure each widget to use the corresponding channel.

Use this channel mapping:

Channel Data Example widget
CH0 Current in amperes Gauge
CH1 Temperature in °C Gauge
CH2 Relative humidity in % Gauge
CH3 Motion status Label
CH4 Building status Label

Set suitable display ranges and units for the numeric widgets. The labels should display text values such as MOTION DETECTED, NO MOTION, and OCCUPIED.

Save the panel configuration before testing the system.

Configure the Arduino Code

Create a new Arduino sketch and add the project code.

#include <ESP8266WiFi.h>
#include <KiwisIoT.h>
#include <DHT.h>
#include <math.h>

const char* ssid = "YOUR_WIFI_NAME";
const char* pass = "YOUR_WIFI_PASSWORD";

const char* topic = "YOUR_DASHBOARD_TOPIC_ID";

KiwisIoT kiwisiot(ssid, pass, topic);

#define CURRENT_SENSOR_PIN A0
#define DHT_PIN D5
#define PIR_PIN D6
#define DHT_TYPE DHT11

DHT dht(DHT_PIN, DHT_TYPE);

const float ACS712_SENSITIVITY = 0.066;

const float ADC_VOLTS_AT_A0_FULL_SCALE = 3.3;

const int ADC_MAX_VALUE = 1023;
const int ZERO_SAMPLES = 500;

float zeroVoltage = 0.0;

const unsigned long SEND_INTERVAL = 5000;
unsigned long lastSend = 0;

float readSensorVoltage() {
long totalADC = 0;

for (int i = 0; i < 20; i++) {
totalADC += analogRead(CURRENT_SENSOR_PIN);
delay(2);
}

float averageADC = totalADC / 20.0;

return averageADC *
(ADC_VOLTS_AT_A0_FULL_SCALE / ADC_MAX_VALUE);
}

void calibrateZeroCurrent() {
Serial.println();
Serial.println("ACS712 zero-current calibration");
Serial.println("Ensure no current is flowing through the sensor.");

float totalVoltage = 0.0;

for (int i = 0; i < ZERO_SAMPLES; i++) {
int rawValue = analogRead(CURRENT_SENSOR_PIN);

float voltage =
rawValue *
(ADC_VOLTS_AT_A0_FULL_SCALE / ADC_MAX_VALUE);

totalVoltage += voltage;
delay(2);
}

zeroVoltage = totalVoltage / ZERO_SAMPLES;

Serial.print("Zero-current sensor voltage: ");
Serial.print(zeroVoltage, 3);
Serial.println(" V");

Serial.println("Calibration complete.");
}

float readCurrentAmps() {
float sensorVoltage = readSensorVoltage();

float current =
(sensorVoltage - zeroVoltage) / ACS712_SENSITIVITY;

current = fabs(current);

if (current < 0.05) {
current = 0.0;
}

return current;
}

void setup() {
Serial.begin(115200);
delay(500);

pinMode(PIR_PIN, INPUT);

dht.begin();

Serial.println();
Serial.println("================================");
Serial.println(" SMART BUILDING MONITORING");
Serial.println("================================");

Serial.println("Initializing KiwisIoT...");
kiwisiot.begin();

calibrateZeroCurrent();

Serial.println("Smart Building monitoring started.");
}

void loop() {
kiwisiot.run();

if (millis() - lastSend >= SEND_INTERVAL) {
lastSend = millis();

float current = readCurrentAmps();

float temperature = dht.readTemperature();
float humidity = dht.readHumidity();

bool motionDetected = (digitalRead(PIR_PIN) == HIGH);

String motionStatus =
motionDetected ? "MOTION DETECTED" : "NO MOTION";

String buildingStatus =
motionDetected ? "OCCUPIED" : "NO MOTION";

Serial.println();
Serial.println("------- SMART BUILDING -------");

Serial.print("Current: ");
Serial.print(current, 2);
Serial.println(" A");

Serial.print("Temperature: ");
if (!isnan(temperature)) {
Serial.print(temperature, 1);
Serial.println(" C");
} else {
Serial.println("DHT11 read error");
}

Serial.print("Humidity: ");
if (!isnan(humidity)) {
Serial.print(humidity, 1);
Serial.println(" %");
} else {
Serial.println("DHT11 read error");
}

Serial.print("Motion: ");
Serial.println(motionStatus);

Serial.print("Building Status: ");
Serial.println(buildingStatus);

kiwisiot.send("0", String(current, 2));

if (!isnan(temperature)) {
kiwisiot.send("1", String(temperature, 1));
}

if (!isnan(humidity)) {
kiwisiot.send("2", String(humidity, 1));
}

kiwisiot.send("3", motionStatus);
kiwisiot.send("4", buildingStatus);

Serial.println("Data sent to KiwisIoT.");
Serial.println("------------------------------");
}

delay(10);
}

Update the following lines with your own Wi-Fi credentials and KiwisIoT Topic ID:

const char* ssid = "YOUR_WIFI_NAME";
const char* pass = "YOUR_WIFI_PASSWORD";

const char* topic = "YOUR_DASHBOARD_TOPIC_ID";

The program uses the following pin assignments:

#define CURRENT_SENSOR_PIN A0
#define DHT_PIN D5
#define PIR_PIN D6
#define DHT_TYPE DHT11

The ACS712 sensitivity is configured as 0.066 volts per ampere, which corresponds to a nominal 66 mV/A sensitivity. Verify the specification of your particular ACS712 version.

The program averages analog readings, calibrates the sensor's zero-current voltage during startup, and calculates the current using the difference between the measured voltage and the calibrated zero-current voltage.

Upload the Code

smart_building_code_832x551.png
  1. Connect the NodeMCU to your computer using a USB cable.
  2. Select the correct board and serial port.
  3. Replace the Wi-Fi credentials and Topic ID.
  4. Verify the sketch and upload it to the board.
  5. Open Serial Monitor and set the baud rate to 115200.

During startup, the program initializes KiwisIoT and calibrates the ACS712 zero-current reading. For accurate calibration, ensure that no current is flowing through the sensor during this stage.

After initialization, the system starts collecting sensor data.

Monitor Electrical Current

The ACS712 provides an analog voltage that changes with the current flowing through the sensor.

The ESP8266 reads the analog input, averages multiple samples, and calculates the current in amperes using the calibrated zero-current voltage.

The measured value is sent to KiwisIoT on CH0 every five seconds.

For example, the captured output shows a current reading of approximately 2.11 A.

The accuracy of this reading depends on the sensor version, calibration, ADC voltage scaling, electrical noise, and the monitored load. Validate the result against a suitable reference meter before using it for any practical electrical measurements.

Monitor Temperature and Humidity

The DHT11 measures the surrounding temperature and relative humidity.

The ESP8266 reads both values and sends them to the dashboard:

  1. CH1: Temperature in degrees Celsius
  2. CH2: Relative humidity in percent

In the captured test output, the temperature is 33.8°C, and the relative humidity is 51.0%.

The program checks for invalid DHT readings and skips sending a channel when its value is unavailable. The DHT11 is intended for general-purpose environmental monitoring rather than high-precision measurements.

Detect Motion

The PIR sensor detects changes in infrared radiation associated with movement within its sensing range.

The ESP8266 checks the digital output of the PIR sensor:

  1. If the output is HIGH, the program reports MOTION DETECTED.
  2. If the output is LOW, the program reports NO MOTION.

The motion message is sent to CH3.

Allow the PIR sensor to complete its initial stabilization period after powering it on. Its sensitivity and hold time may be adjustable, depending on the module.

Determine the Building Status

The program uses the PIR sensor output to generate a simple building status.

String motionStatus =
motionDetected ? "MOTION DETECTED" : "NO MOTION";

String buildingStatus =
motionDetected ? "OCCUPIED" : "NO MOTION";

The resulting status is sent to CH4.

When motion is detected, the dashboard displays OCCUPIED. When the PIR output is LOW, the program displays NO MOTION.

This is a basic occupancy indication. A person who remains still may not continuously trigger the PIR sensor, so the status should not be treated as a reliable count of people or a complete security system.

Test the Project

After uploading the code, perform these tests.

Test 1: Current Monitoring

Run a suitable low-voltage load through the ACS712 current path and check whether the current reading changes.

Test 2: Temperature and Humidity

Allow the DHT11 to collect readings and verify that both values appear in Serial Monitor and on the dashboard.

Test 3: Motion Detection

Move within the PIR sensor's detection range and observe the motion status. Then leave the detection area and check whether the output returns to NO MOTION.

Test 4: Dashboard Updates

Keep the ESP8266 connected to Wi-Fi and confirm that all five channels update on the KiwisIoT panel.

View the Output in Serial Monitor

smart_building_serial_monitor_832x551.png

The Serial Monitor provides a convenient way to check the sensor readings and confirm that data is being sent to KiwisIoT.

The captured output from this project includes:

------- SMART BUILDING -------
Current: 2.11 A
Temperature: 33.8 C
Humidity: 51.0 %
Motion: MOTION DETECTED
Building Status: OCCUPIED
[TX] {"0":"2.11"}
[TX] {"1":"33.8"}
[TX] {"2":"51.0"}
[TX] {"3":"MOTION DETECTED"}
[TX] {"4":"OCCUPIED"}
Data sent to KiwisIoT.

The readings shown here are example values from the captured test, not fixed outputs. Actual values will depend on the load, environment, sensor placement, and calibration.

View the Results on KiwisIoT

smart_building_dashboard_832x551.png

Open the Smart Building Monitoring panel on KiwisIoT.

The dashboard presents the five channels in a visual format:

  1. Current gauge for electrical current
  2. Temperature gauge for ambient temperature
  3. Humidity gauge for relative humidity
  4. Motion status label
  5. Building status label

In the captured dashboard, the current is 2.11 A, the temperature is 33.8°C, and the humidity is 51%. The status widgets display MOTION DETECTED and OCCUPIED.

These values demonstrate how sensor readings from the ESP8266 can be viewed remotely through an IoT dashboard.

Applications and Future Improvements

This project demonstrates a basic approach to connected building monitoring. It can be extended with additional features such as:

  1. Historical charts for temperature, humidity, and current
  2. Threshold-based alerts for unusual readings
  3. A more advanced occupancy detection method
  4. Calibrated current and power measurement
  5. Energy consumption estimation using measured power over time
  6. Additional sensors for air quality, lighting, or door status

For energy monitoring, current alone is not sufficient to determine actual energy consumption. Accurate energy measurement may require voltage and power-factor measurements as well as time integration.

Conclusion

The Smart Building Monitoring System combines an ESP8266 NodeMCU, ACS712 current sensor, DHT11, PIR sensor, and KiwisIoT to demonstrate connected monitoring of electrical current, environmental conditions, and motion.

By sending five data channels to an online dashboard, the project provides a useful starting point for students and makers exploring smart building and IoT applications.

What other sensors would you add to this system to make it more useful for smart building monitoring?