ESP8266 Smart Office IoT Monitoring System Using LDR, DHT11, ACS712 and KiwisIoT

by ananthi rk in Circuits > Arduino

18 Views, 0 Favorites, 0 Comments

ESP8266 Smart Office IoT Monitoring System Using LDR, DHT11, ACS712 and KiwisIoT

ESP8266 Smart Office IoT Dashboard.png

Introduction

  1. A Smart Office IoT Monitoring System helps monitor environmental conditions and electrical usage using Internet of Things (IoT) technology.
  2. In this project, we use a NodeMCU ESP8266 microcontroller, an LDR sensor module, a DHT11 temperature and humidity sensor, and an ACS712 5A current sensor.
  3. The NodeMCU ESP8266 reads the sensor values and sends the data to the KiwisIoT platform through Wi-Fi. The readings are displayed on an online dashboard, allowing users to monitor lighting conditions, room temperature, humidity, current consumption, and estimated energy consumption.
  4. This project is suitable for students, beginners, and final-year engineering projects because it demonstrates sensor interfacing, wireless communication, data monitoring, and IoT dashboard integration.

Objectives

  1. Monitor lighting conditions using an LDR sensor.
  2. Measure temperature and humidity using a DHT11 sensor.
  3. Measure current flowing through a low-voltage DC load using an ACS712 5A sensor.
  4. Estimate electrical power and energy consumption.
  5. Display sensor readings on the KiwisIoT dashboard.
  6. Understand how IoT can be used for smart office monitoring.

Supplies

Components Required

The following hardware and software components are used in this project.

  1. NodeMCU ESP8266 development board
  2. 3-pin LDR sensor module
  3. DHT11 temperature and humidity sensor module
  4. ACS712 5A current sensor module
  5. Jumper wires
  6. USB cable
  7. Computer with Arduino IDE
  8. Wi-Fi connection
  9. KiwisIoT account
  10. Low-voltage DC power supply and DC load for current measurement

Software Requirements

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

Circuit Connections

LDR Sensor Connections

The LDR module detects changes in light intensity and provides a digital output through its DO pin.

LDR Module Pin NodeMCU ESP8266 Pin
VCC ---> 3V3
GND ---> GND
DO ---> D5

When the light condition changes, the digital output of the module may change between HIGH and LOW. The exact logic depends on the LDR module and its threshold adjustment.

DHT11 Sensor Connections

The DHT11 sensor measures temperature and humidity.

DHT11 Module Pin NodeMCU ESP8266 Pin
VCC ---> 3V3
GND ---> GND
DATA ---> D2

The sensor sends digital data to the NodeMCU, which reads the temperature and humidity values using the DHT library.

ACS712 5A Current Sensor Connections

The ACS712 current sensor measures the current flowing through a conductor.

ACS712 PinConnection
VCC --> Supply voltage specified for the module
GND --> Common GND with NodeMCU
OUT --> NodeMCU A0
IP+ --> One side of the DC load circuit
IP− --> Other side of the DC load circuit

The IP+ and IP− terminals must be connected in series with the load so that the load current passes through the sensor.

Important safety precautions:

  1. Use a low-voltage DC load only.
  2. Never connect mains electricity to this beginner project.
  3. Verify the NodeMCU board's A0 input voltage range before connecting the ACS712 output.
  4. The ACS712 module output can exceed the safe input voltage of the ESP8266 ADC. Use a correctly calculated voltage divider or suitable signal-conditioning circuit.
  5. Ensure that the sensor supply, voltage divider, and ADC calibration match the actual hardware.

Explain the Working Principle

The project works in the following sequence.

Step 1: Detect Lighting Conditions

  1. The LDR module detects the surrounding light level. Its digital output is connected to pin D5 of the NodeMCU.
  2. The program reads the digital signal and identifies the lighting status as Dark or Bright according to the configured logic.

Step 2: Measure Temperature

  1. The DHT11 sensor measures the surrounding temperature and sends the reading to the NodeMCU through pin D2.
  2. The program reads the value in degrees Celsius.

Step 3: Measure Humidity

  1. The DHT11 also measures relative humidity. The program reads the humidity value as a percentage.

Step 4: Measure Current

  1. The ACS712 sensor measures current flowing through the low-voltage DC load. Its analog output is read through the NodeMCU A0 pin.
  2. The program uses the sensor's sensitivity and zero-current calibration to estimate the current in amperes.

Step 5: Estimate Power

  1. The program estimates power using the measured current and the configured DC supply voltage.
  2. Power is calculated using:
  3. Power (W) = Current (A) × Voltage (V)
  4. This calculation assumes a suitable DC load and the correct supply voltage.

Step 6: Estimate Energy

  1. The program accumulates estimated power over time to calculate energy consumption.
  2. Energy (Wh) = Power (W) × Time (hours)
  3. The displayed energy value is an estimate and depends on the accuracy of the current measurement and the configured voltage.

Step 7: Send Data to KiwisIoT

  1. The NodeMCU connects to Wi-Fi and sends the readings to KiwisIoT using five channel IDs.
  2. Users can then monitor the latest available readings through the dashboard.

Installing and Preparing the Arduino IDE

Step 1: Install Arduino IDE

Download and install the Arduino IDE on your computer if it is not already installed.

Step 2: Install ESP8266 Board Support

  1. Open the Arduino IDE and install the ESP8266 board package using Boards Manager.
  2. Select the appropriate NodeMCU ESP8266 board and the correct serial port.

Step 3: Install the Required Libraries

Install the libraries required by the program:

  1. KiwisIoT library
  2. DHT sensor library
  3. Any additional dependency required by the installed DHT library

Step 4: Connect the NodeMCU

  1. Connect the NodeMCU ESP8266 to the computer using a suitable USB cable.
  2. Select the correct board and port before uploading the program.

KiwisIoT Platform Setup

Step 1: Open KiwisIoT

  1. Open the KiwisIoT platform and sign in to your account. https://kiwisiot.in/login
  2. Create an account if you do not already have one.

Step 2: Create a Dashboard

  1. Create a new dashboard for the project.
  2. Use the dashboard name: Smart Office Monitoring System

Step 3: Create the Five Widgets

Create five widgets and assign the channel IDs exactly as shown below.

Channel ID -- Widget Name -- idget Type -- Unit or Value
0 --> Lighting Status -->LED or Label --> 0 = Dark, 1 = Bright
1 --> Temperature --> Value Display --> °C
2 --> Humidity --> Gauge --> 0–100%
3 --> Current Consumption --> Gauge --> A
4 --> Energy Consumption --> Value Display --> Wh

Configure the display ranges according to your expected operating conditions.

For the current gauge, use a suitable range for your actual DC load rather than assuming that the load always reaches 5 A.

Step 4: Copy the Topic ID

  1. Copy the Topic ID associated with the dashboard.
  2. Paste it into the Arduino program where the Topic ID is defined.
  3. Keep your Topic ID private when sharing screenshots publicly.

Step 5: Configure Wi-Fi Credentials

  1. Enter your Wi-Fi name and password in the Arduino program.
  2. The NodeMCU uses these credentials to connect to the network.

Step 6: Verify the Channel Mapping

  1. Confirm that each widget uses the same channel ID as the corresponding value sent by the program.
  2. Incorrect channel assignments may cause the values to appear in the wrong widgets.

Arduino Program

The following is the program structure used for this project. Use your successfully tested version of the code and verify the ADC settings for your particular hardware before running the current sensor.

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

// Wi-Fi details
const char* ssid = "YOUR_WIFI_NAME";
const char* pass = "YOUR_WIFI_PASSWORD";

// KiwisIoT dashboard Topic ID
const char* topic = "dash_XXXXXXXXXXXXX";

KiwisIoT kiwisiot(ssid, pass, topic);

// Sensor pins
#define LDR_PIN D5
#define DHT_PIN D2
#define ACS_PIN A0
#define DHTTYPE DHT11

DHT dht(DHT_PIN, DHTTYPE);

// Change this if your LDR logic is reversed
const int DARK_LEVEL = LOW;

// ACS712 5A nominal sensitivity
const float ACS_SENSITIVITY = 0.185;

// Example external divider: 10k and 2.7k
const float DIVIDER_RATIO = 2.7 / 12.7;

// Set this to the actual full-scale voltage
// at the NodeMCU A0 terminal.
const float ADC_FULL_SCALE = 3.30;

// Set this to the actual DC load supply voltage
const float LOAD_VOLTAGE = 12.0;

float zeroSensorVoltage = 0.0;
float energyWh = 0.0;

unsigned long lastSend = 0;
unsigned long lastEnergyTime = 0;

float readSensorVoltage() {
long total = 0;

for (int i = 0; i < 30; i++) {
total += analogRead(ACS_PIN);
delay(5);
}

float adcValue = total / 30.0;

float a0Voltage =
adcValue * ADC_FULL_SCALE / 1023.0;

return a0Voltage / DIVIDER_RATIO;
}

float readCurrent() {
float voltage = readSensorVoltage();

float current =
(voltage - zeroSensorVoltage)
/ ACS_SENSITIVITY;

return fabs(current);
}

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

pinMode(LDR_PIN, INPUT);
dht.begin();

Serial.println("Smart Office IoT Starting");

// Keep the measured DC load OFF
// during zero-current calibration.
delay(2000);
zeroSensorVoltage = readSensorVoltage();

Serial.print("Zero-current voltage: ");
Serial.println(zeroSensorVoltage, 3);

kiwisiot.begin();

lastEnergyTime = millis();
}

void loop() {
kiwisiot.run();

unsigned long now = millis();

if (now - lastSend >= 3000) {
lastSend = now;

// Channel 0: Lighting Status
int ldrRaw = digitalRead(LDR_PIN);

int lightingStatus =
(ldrRaw == DARK_LEVEL) ? 0 : 1;

// Channel 1: Temperature
float temperature = dht.readTemperature();

// Channel 2: Humidity
float humidity = dht.readHumidity();

// Channel 3: Current
float current = readCurrent();

// Estimate power for a DC load
float power = current * LOAD_VOLTAGE;

// Channel 4: Estimated energy
unsigned long energyNow = millis();

float elapsedHours =
(energyNow - lastEnergyTime) / 3600000.0;

energyWh += power * elapsedHours;
lastEnergyTime = energyNow;

// Send five values to KiwisIoT
kiwisiot.send("0", lightingStatus);

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

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

kiwisiot.send("3", current);
kiwisiot.send("4", energyWh);

// Print readings to Serial Monitor
Serial.println("---- SMART OFFICE ----");

Serial.print("Lighting: ");
Serial.println(
lightingStatus == 0 ? "DARK" : "BRIGHT");

Serial.print("Temperature: ");
Serial.println(temperature);

Serial.print("Humidity: ");
Serial.println(humidity);

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

Serial.print("Estimated Power: ");
Serial.print(power, 2);
Serial.println(" W");

Serial.print("Estimated Energy: ");
Serial.print(energyWh, 4);
Serial.println(" Wh");
}
}



Code Explanation

Library Inclusion

  1. The program includes the KiwisIoT library for dashboard communication, the DHT library for temperature and humidity readings, and the math library for absolute-value calculations.

Wi-Fi and Dashboard Configuration

  1. The Wi-Fi credentials and dashboard Topic ID allow the NodeMCU to connect to the configured KiwisIoT dashboard.
  2. Replace the example placeholders with your actual credentials before uploading the code.

Sensor Pin Definitions

  1. The LDR digital output is connected to D5, the DHT11 data pin to D2, and the ACS712 output to A0 through the appropriate input circuit.

Sensor Initialization

  1. The setup() function starts serial communication, initializes the DHT11 sensor, calibrates the ACS712 zero-current reading, and initializes KiwisIoT.

Lighting Status

  1. The program reads the LDR digital output and converts it into a numerical status value.
  2. A value of 0 represents Dark and a value of 1 represents Bright in this example. Reverse the configured logic if your module behaves differently.

Temperature and Humidity

  1. The program obtains temperature and humidity values using the DHT library. Invalid readings are not sent to the dashboard.

Current Measurement

  1. The program averages multiple ADC readings, estimates the sensor output voltage, and calculates current using the nominal ACS712 sensitivity.
  2. For accurate results, the analog voltage scaling and zero-current calibration must be correct. The nominal sensitivity should also be checked against the actual module.

Power and Energy Calculation

  1. The program estimates power using current multiplied by the configured DC voltage.
  2. It accumulates the estimated energy over time in watt-hours.

Dashboard Communication

  1. The program sends the five readings to channel IDs 0, 1, 2, 3, and 4. The dashboard must use the same channel mapping.

Uploading the Program

  1. Connect the NodeMCU ESP8266 to your computer.
  2. Open the Arduino IDE.
  3. Select the correct ESP8266 board.
  4. Select the correct COM port.
  5. Enter your Wi-Fi credentials.
  6. Enter your KiwisIoT Topic ID.
  7. Verify the sensor connections and analog input voltage range.
  8. Compile the program.
  9. Upload it to the NodeMCU.
  10. Open the Serial Monitor at 115200 baud.

After startup, check that the board initializes and that the sensor readings are displayed.

Serial Monitor Output

arduino_serial_monitor_832x551.jpg

The Serial Monitor provides a local view of the values calculated by the NodeMCU.

The program prints:

  1. Lighting status
  2. Temperature in degrees Celsius
  3. Humidity percentage
  4. Estimated current in amperes
  5. Estimated power in watts
  6. Estimated energy in watt-hours

The Serial Monitor is useful for checking sensor operation and comparing local readings with the dashboard.

Test 1: LDR Sensor

  1. Change the surrounding light conditions and observe the Lighting Status widget.
  2. Confirm that the output changes according to the configured LDR logic.

Test 2: DHT11 Sensor

  1. Observe the temperature and humidity readings in the Serial Monitor and KiwisIoT dashboard.
  2. Allow the sensor time to obtain stable readings.

Test 3: ACS712 Current Sensor

  1. Use a suitable low-voltage DC load and verify the current reading with a suitable reference meter.
  2. Ensure that the zero-current calibration and analog voltage scaling are correct.

Test 4: Energy Estimation

  1. Operate the DC load and observe the estimated energy value.
  2. The value should accumulate according to the measured current, configured voltage, and elapsed time. Remember that the value resets after a restart in this implementation.

Test 5: Dashboard Communication

  1. Confirm that all five dashboard widgets receive their corresponding channel values.

KiwisIoT Dashboard Output

kiwisiot_dashboard_832x551 (1).jpg
  1. After the NodeMCU connects to Wi-Fi and sends the readings, open the Smart Office Monitoring System dashboard.
  2. The dashboard contains five widgets to monitor the sensor values.

Output 1: Lighting Status

The Lighting Status widget displays the digital status from the LDR module.

  1. 0 indicates Dark.
  2. 1 indicates Bright.

Changing the light falling on the LDR module should change the displayed status when the sensor output crosses its threshold.

Output 2: Temperature

  1. The Temperature widget displays the temperature measured by the DHT11 in degrees Celsius.
  2. The reading changes according to the surrounding temperature and the sensor's measurement characteristics.

Output 3: Humidity

  1. The Humidity gauge displays relative humidity as a percentage from 0 to 100%.
  2. The value is obtained from the DHT11 sensor.

Output 4: Current Consumption

  1. The Current Consumption gauge displays the estimated current measured by the ACS712 sensor in amperes.
  2. To test this feature, use a suitable low-voltage DC load and compare the reading with an appropriate reference meter.

Output 5: Energy Consumption

  1. The Energy Consumption widget displays the estimated accumulated energy in watt-hours (Wh).
  2. As the DC load operates, the program estimates power and accumulates energy over time. The displayed result depends on the current reading and the configured supply voltage.

Dashboard Result

  1. The five widgets provide a combined view of lighting conditions, temperature, humidity, DC current, and estimated energy consumption.
  2. The dashboard helps demonstrate how sensor readings can be collected by the NodeMCU ESP8266 and monitored remotely through KiwisIoT.

Troubleshooting

Problem 1: Dashboard Values Are Not Updating

Check the Wi-Fi credentials, Topic ID, KiwisIoT library setup, and channel IDs.

Problem 2: LDR Status Is Reversed

  1. Some LDR modules produce a LOW output in bright conditions and others may behave differently depending on their circuit and threshold.
  2. Adjust DARK_LEVEL according to your module's actual output.

Problem 3: DHT11 Shows Invalid Readings

Check the DATA, VCC, and GND connections. Verify that the DHT library is installed and that the correct sensor type is selected.

Problem 4: ACS712 Current Reading Is Incorrect

Check the zero-current calibration, analog voltage divider, board A0 input range, and sensor sensitivity. Compare the result with a suitable reference meter.

Problem 5: Energy Reading Is Incorrect

Check the configured DC supply voltage and the current measurement. Since the program estimates energy from current and voltage, errors in either value affect the result.

Applications

This project can be used as a demonstration of:

  1. Smart office environmental monitoring
  2. Classroom and laboratory monitoring
  3. IoT-based lighting condition monitoring
  4. Low-voltage DC current monitoring
  5. Basic power and energy estimation
  6. Sensor interfacing with NodeMCU ESP8266
  7. Cloud dashboard integration for student projects

Conclusion

  1. The ESP8266 Smart Office IoT Monitoring System demonstrates how a NodeMCU ESP8266 can combine lighting detection, temperature and humidity monitoring, and DC current measurement in a single IoT project.
  2. Using an LDR module, DHT11 sensor, and ACS712 5A current sensor, the system collects sensor readings and sends them to the KiwisIoT platform through Wi-Fi.
  3. The five-widget dashboard provides a convenient way to monitor lighting status, temperature, humidity, current, and estimated energy consumption.
  4. This project offers practical experience with Arduino programming, sensor interfacing, wireless communication, and IoT dashboard configuration. It can also serve as a foundation for developing more advanced smart office monitoring systems.