In this project, I connected an LDR sensor to a NodeMCU ESP8266 and sent the sensor readings to a KiwisIoT dashboard.
The LDR changes its output depending on the amount of light falling on it. The ESP8266 reads this value through its analog pin and sends the reading to KiwisIoT over Wi-Fi.
This is a simple project for understanding how a physical sensor can be connected to an IoT dashboard and monitored online. KiwisIoT provides dashboard widgets for viewing sensor data in real time. (KiwisIoT)
Project OverviewThe main idea of this project is:
LDR Sensor → ESP8266 → Wi-Fi → KiwisIoT → Dashboard
The LDR sensor detects the light level and produces an analog value. The ESP8266 reads this value using its A0 analog input.
The ESP8266 then connects to Wi-Fi and sends the sensor value to KiwisIoT. On the dashboard, I can use a widget such as a Gauge to see the current LDR value.
The ESP8266 has one ADC channel available to the user, and analogRead(A0) is used to read an external analog signal. (ESP8266 Arduino Core Documentation)
- NodeMCU ESP8266
- LDR Sensor Module
- Jumper Wires
- USB Cable
- Computer / Laptop
- Arduino IDE
- ESP8266 Board Package
- KiwisIoT Account
- KiwisIoT Arduino Library
- Wi-Fi connection
KiwisIoT supports ESP8266 and provides dashboard tools for visualizing sensor data.
Circuit WiringI used the analog output (AO) of the LDR module because I wanted to read changing light values instead of only detecting light/dark.
Simple connectionLDR Sensor NodeMCU ESP8266
VCC -----------------> 3.3V
GND -----------------> GND
AO -----------------> A0After connecting the wires, I connected the NodeMCU to my laptop using the USB cable.
The exact safe voltage range at A0 depends on the particular ESP8266 board. The bare ESP8266 ADC is specified for 0–1.0 V, while some development boards include a voltage divider on A0. So it is important to check the board being used before applying an external voltage. (ESP8266 Arduino Core Documentation)
Arduino CodeI used the KiwisIoT library to connect the ESP8266 to the platform.
#include <KiwisIoT.h>
const char* ssid = "YOUR_WIFI_NAME";
const char* pass = "YOUR_WIFI_PASSWORD";
const char* topic = "YOUR_TOPIC_ID";
KiwisIoT kiwisiot(ssid, pass, topic);
#define LDR_PIN A0
void setup() {
Serial.begin(9600);
kiwisiot.begin();
}
void loop() {
kiwisiot.run();
int ldrValue = analogRead(LDR_PIN);
kiwisiot.send("1", ldrValue);
Serial.print("LDR Value = ");
Serial.println(ldrValue);
delay(1000);
}Replace the Wi-Fi and topic placeholders with the values from your own KiwisIoT setup.
Kiwistron IoT PanelAfter uploading the code, I created a panel in KiwisIoT.
From My Panels, I created a dashboard and added a widget for the LDR value. KiwisIoT's current dashboard workflow allows users to create a panel, add widgets, and view sensor data in real time. (KiwisIoT)
For this project, I used:
Channel 1 → LDR Sensor
LDR Sensor
↓
ESP8266
↓
Wi-Fi
↓
KiwisIoT
↓
Channel 1
↓
LDR GaugeWhen the ESP8266 sends a new value, the dashboard updates the displayed sensor value.
Working PrincipleThe working of the project is quite simple.
First, light falls on the LDR sensor. The resistance of the LDR changes depending on the amount of light.
The LDR module converts this change into an analog voltage. The ESP8266 reads the voltage through A0 using:
analogRead(A0);The reading is stored in ldrValue.
Then this value is sent to KiwisIoT:
kiwisiot.send("1", ldrValue);Here, I am using channel 1 for the LDR.
The complete process is:
Light
↓
LDR Sensor
↓
Analog Signal
↓
ESP8266 A0
↓
Wi-Fi
↓
KiwisIoT
↓
DashboardApplicationThis simple project can be used as a starting point for bigger IoT systems.
Some possible applications are:
- Automatic street-light monitoring
- Room light monitoring
- Smart home projects
- Garden and agriculture monitoring
- Light-level data logging
- Energy-saving systems
- Day/night detection
- IoT learning projects
For example, the same concept can later be extended by adding a relay. The LDR could detect darkness and the ESP8266 could control a light automatically.
Troubleshoot1. LDR value is not changingCheck the following:
- Make sure AO is connected to A0.
- Check VCC and GND connections.
- Try shining a flashlight directly on the LDR.
- Try covering the LDR with your hand.
Check:
Serial.begin(9600);
Serial.begin(9600);Then open the Serial Monitor and select 9600 baud.
You should see something like:
LDR Value = 564
LDR Value = 576
LDR Value = 598
LDR Value = 578
LDR Value = 564
LDR Value = 576
LDR Value = 598
LDR Value = 5783. KiwisIoT dashboard is not updatingCheck:
- Wi-Fi name and password
- Topic ID
- KiwisIoT library installation
- ESP8266 Wi-Fi connection
- Correct channel number
- Dashboard widget configuration
Also make sure:
kiwisiot.run();
kiwisiot.run();is continuously called inside loop().
Check the LDR wiring and the A0 input range supported by your particular NodeMCU board. ESP8266 boards can differ in how their A0 input is scaled.
OutputAfter completing the wiring and uploading the code, I could see the LDR readings in the Serial Monitor.
At the same time, the value is sent to KiwisIoT Channel 1 and displayed on the dashboard using the LDR widget.
So the final output is:
The dashboard makes it easier to monitor the sensor without continuously checking the Serial Monitor.
FAQWhat is an LDR?LDR means Light Dependent Resistor. Its resistance changes according to the amount of light falling on it.
Why did I use A0?A0 is the analog input used to read the changing output from the LDR module.
Can I use the digital output of the LDR?Yes. Many LDR modules provide both AO and DO. AO gives a changing analog reading, while DO can be used for a threshold-based digital result.
Why use ESP8266?ESP8266 has built-in Wi-Fi, so it can read the sensor and send the data to an online IoT platform without requiring a separate Wi-Fi module.
Why use KiwisIoT?KiwisIoT provides a dashboard where sensor data can be visualized and monitored online. It also supports ESP8266-based IoT projects.
Can I add more sensors?Yes. The same basic idea can be extended with sensors such as temperature, humidity, motion, or other suitable sensors, depending on the available inputs and the dashboard configuration.
What can I build next?A good next step would be to connect the LDR to a relay or LED, so the system can automatically turn a light ON/OFF depending on the detected light level.















Comments