DEV Community

Cover image for LDR-Based Light Intensity Monitoring Using KiwisIoT
manikanda balamurugan S
manikanda balamurugan S

Posted on Edited on

LDR-Based Light Intensity Monitoring Using KiwisIoT

Introduction

The Internet of Things (IoT) allows physical devices to collect and exchange data through the internet. In this project, an LDR (Light Dependent Resistor) sensor is used to monitor changes in surrounding light intensity.

The sensor reading is collected by a microcontroller and monitored through the KiWiS IoT platform.

Objective

The main objective is to monitor light intensity in real time and display the sensor readings on an IoT dashboard.

Components Required

  • LDR sensor
  • Microcontroller with Wi-Fi capability
  • Resistor
  • Breadboard
  • Jumper wires
  • Power supply
  • Wi-Fi connection

Software and Platform

  • Arduino IDE
  • KiwisIoT platform

Working Principle

  1. The LDR sensor detects the light falling on its surface.
  2. The sensor's electrical response changes according to the surrounding light.
  3. The microcontroller reads the sensor signal.
  4. The microcontroller sends the reading to the KiwisIoT platform through Wi-Fi.
  5. The dashboard displays the received sensor data.
  6. The displayed reading changes when the surrounding light conditions change.

Circuit Diagram

System Flow

Light Source → LDR Sensor → Microcontroller → Wi-Fi → KiwisIoT Dashboard

Realtime Image

LIGHT MONITORING CODE

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

const char* ssid = "XXX";
const char* pass = "YYY";

const char* topic = "dash_1234";

#define LDR_PIN A0

KiwisIoT kiwisiot(ssid, pass, topic);

void sendLightData() {

  int rawValue = analogRead(LDR_PIN);

  int lightLevel = 1023 - rawValue;

  String lightStatus;

  if (lightLevel >= 700) {
    lightStatus = "BRIGHT";
  }
  else if (lightLevel >= 300) {
    lightStatus = "MEDIUM";
  }
  else {
    lightStatus = "DARK";
  }

  Serial.println();
  Serial.println("---------- LIGHT MONITORING ----------");

  Serial.print("Raw LDR Value: ");
  Serial.println(rawValue);

  Serial.print("Light Level: ");
  Serial.println(lightLevel);

  Serial.print("Light Status: ");
  Serial.println(lightStatus);

  kiwisiot.send("0", String(lightLevel));

  kiwisiot.send("1", lightStatus);

  Serial.print("Sent to KiwisIoT Channel 0: ");
  Serial.println(lightLevel);

  Serial.print("Sent to KiwisIoT Channel 1: ");
  Serial.println(lightStatus);
}

void setup() {

  Serial.begin(115200);

  Serial.println();
  Serial.println("    LDR LIGHT MONITORING    ");

  pinMode(LDR_PIN, INPUT);

  Serial.println("LDR initialized");

  Serial.println("Connecting to KiwisIoT...");

  kiwisiot.begin();

  Serial.println("KiwisIoT initialized");
  Serial.println("Starting light monitoring...");
}

void loop() {

  kiwisiot.run();

  static unsigned long lastSend = 0;

  if (millis() - lastSend >= 2000) {

    lastSend = millis();

    sendLightData();
  }

  delay(100);
}
Enter fullscreen mode Exit fullscreen mode

Applications

  • Smart lighting systems
  • Indoor light monitoring
  • Smart classrooms
  • Energy-saving automation
  • IoT-based environmental monitoring

Future Enhancements

  • Automatic light ON/OFF control
  • Mobile notifications
  • Sensor data logging
  • Historical data analysis
  • Automatic brightness control

Conclusion

This project demonstrates how an LDR sensor and a Wi-Fi-enabled microcontroller can be used for IoT-based light monitoring. By connecting the system to KiwisIoT, sensor readings can be viewed through an online dashboard.

The project provides a foundation for developing more advanced smart lighting and environmental monitoring applications.

Project Category

IoT | Embedded Systems | Sensor Monitoring

Feedback

Have you worked on a similar IoT project? Share your ideas and suggestions in the comments!

Top comments (0)