ESP8266 LDR Sensor With KiwisIoT Dashboard
by kirusokumar in Circuits > Microcontrollers
68 Views, 1 Favorites, 0 Comments
ESP8266 LDR Sensor With KiwisIoT Dashboard
I wanted to try a simple IoT project where I can read the light level from an LDR sensor and see the value on an online dashboard.
For this project, I used a NodeMCU ESP8266, an LDR sensor module, Arduino IDE and KiwisIoT. The ESP8266 reads the LDR value from its analog pin and sends it to the KiwisIoT dashboard through Wi-Fi.
The basic flow is:
LDR Sensor → ESP8266 → Wi-Fi → KiwisIoT → Dashboard
This type of step-by-step format is similar to the project style commonly used on Instructables, where the build is divided into parts such as components, connections, code, uploading and testing
What I Used
These are the things I used for this project:
Hardware Components
- NodeMCU ESP8266
- LDR Sensor Module
- Jumper Wires
- USB Cable
- Computer/Laptop
Software Components
- Arduino IDE
- KiwisIoT Platform / Account
- Wi-Fi Connection
The LDR module gives an analog value that changes depending on the amount of light detected.
Connect the LDR
I connected the LDR module to the NodeMCU.
The important connection is the analog output of the LDR to A0 of the ESP8266.
Connection
LDR Module -VCC ,GND ,A0
NodeMCUESP8266 -3.3V , GND ,A0
The exact pin labels can vary between LDR modules, so I checked the labels on my module before connecting it.
For an ESP8266 LDR setup, the analog output is normally connected to A0 so that the changing light level can be read as an analog value.
Install Arduino IDE
I used Arduino IDE to write and upload the program.
First I opened Arduino IDE and selected my ESP8266 board.
From the Arduino IDE, I selected:
Tools → Board → ESP8266 → NodeMCU 1.0 (ESP-12E Module)
Then I selected the correct COM port.
ESP8266 board support needs to be installed in Arduino IDE before the NodeMCU can be programmed. This is also a common setup step in ESP8266 projects.
Create the KiwisIoT Dashboard
Next I created a dashboard in KiwisIoT.
I created a panel and added a Gauge widget.
I used the Gauge to display the LDR value.
My dashboard looked like this:
LDR = 507
The value changes when the amount of light falling on the LDR changes.
Get the KiwisIoT Topic ID
After creating the dashboard, I copied the Topic ID.
In my Arduino code, I used the Topic ID like this:
I also entered my Wi-Fi name and password.
Important: If this code is published publicly, I should not publish my real Wi-Fi password. I should replace it with a placeholder such as YOUR_WIFI_PASSWORD.
Install KiwisIoT Library
I installed the KiwisIoT Arduino library because my ESP8266 needs it to communicate with the KiwisIoT dashboard.
Then I included the library in my code:
Write the Code
#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);
// Start KiwisIoT
kiwisiot.begin();
}
void loop() {
// Keep KiwisIoT connection running
kiwisiot.run();
// Read LDR value
int ldrValue = analogRead(LDR_PIN);
// Send LDR value to KiwisIoT Channel ID 1
kiwisiot.send("1", ldrValue);
// Serial monitor
Serial.print("LDR Value = ");
Serial.println(ldrValue);
delay(1000);
}
Understanding the Code
First I included the KiwisIoT library:
Then I entered my Wi-Fi details and dashboard Topic ID:
Then I created the KiwisIoT object:
I defined the LDR analog pin:
Inside setup(), I started Serial communication:
Then I started KiwisIoT:
Read the LDR Value
Inside the loop(), I read the sensor:
The ESP8266 reads the analog value from A0.
Then I send the value to KiwisIoT:
Here, "1" is the KiwisIoT channel I used for the LDR.
I also print the value in the Serial Monitor:
Upload the Program
After completing the code, I connected my NodeMCU to the laptop using USB.
Then I selected:
Tools → Board → NodeMCU 1.0 (ESP-12E Module)
Then:
Tools → Port → COM8
The COM port can be different on another computer.
Finally, I clicked the Upload button.
After uploading, Arduino IDE showed that the program was successfully written to the ESP8266.
Check Serial Monitor
After uploading, I opened:
Tools → Serial Monitor
I selected:
9600 baud
Then I started getting values like:
So I knew that the ESP8266 was successfully reading the LDR.
Check the KiwisIoT Dashboard
After the ESP8266 connected to Wi-Fi and started sending data, I checked my KiwisIoT dashboard.
The Gauge started showing the LDR value.
For example:
When I changed the light around the sensor, the value also changed.
This means the complete communication was working:
LDR → A0 → ESP8266 → Wi-Fi → KiwisIoT → Gauge
Testing the Sensor
I tested the sensor by changing the amount of light falling on it.
More Light
When I exposed the LDR to more light, the analog reading changed.
Less Light
When I covered the LDR or reduced the light, the reading changed again.
The exact direction and numerical range can depend on the particular LDR module and its circuit, so I mainly checked that the value changed consistently when I changed the light.
Analog LDR readings are commonly used to represent changing light intensity.
My Final Result
Finally, I was able to monitor the LDR from the KiwisIoT dashboard.
Hardware
- NodeMCU ESP8266
- LDR module
- Jumper wires
- USB cable
Software
- Arduino IDE
- KiwisIoT Arduino Library
- KiwisIoT Dashboard
Output
The LDR sensor gives an analog value, the ESP8266 sends the value through Wi-Fi, and the KiwisIoT Gauge displays it.
My final dashboard:
LDR → 507
I recommend KiwisIoT for beginners and students who want to build IoT projects easily.
It provides simple drag-and-drop dashboards to display live sensor data.
It supports boards like Arduino, ESP8266, ESP32 and Raspberry Pi.
It is useful for learning, testing, and presenting IoT projects without building a dashboard from scratch.