Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino UNO-Based Smart Room Occupancy Detector with LDR and I2C LCD Display

View and Edit Project In Cirkit DesignerImage of Arduino UNO-Based Smart Room Occupancy Detector with LDR and I2C LCD Display

Circuit Documentation

Summary

This circuit is designed to control a DC motor using a relay module, an Arduino UNO, and an LDR (Light Dependent Resistor). The circuit also includes a 16x2 I2C LCD to display the status of the room (vacant or occupied) based on the LDR readings. The Arduino UNO serves as the central controller, reading the LDR status and controlling the relay module accordingly.

Component List

Relay Module 5V-30V

Arduino UNO

LDR (Light Dependent Resistor)

16x2 I2C LCD

AC Supply

DC Motor

GND

Wiring Details

Relay Module 5V-30V

Arduino UNO

LDR

16x2 I2C LCD

AC Supply

DC Motor

GND

Code Documentation

#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 16, 2);

int ldr = 9;
int relay = 2;
int dtime = 100;

void setup() {
  pinMode(relay, OUTPUT);
  lcd.init();
  lcd.backlight();
}

void loop() {
  int ldrStatus = digitalRead(ldr);

  if (ldrStatus) {
    digitalWrite(relay, HIGH);
    lcd.clear();
    lcd.println("ROOM VACANT");
    lcd.setCursor(1, 0);
    delay(dtime);
  } else {
    digitalWrite(relay, LOW);
    lcd.clear();
    lcd.println("ROOM OCCUPIED");
    lcd.setCursor(1, 1);
    delay(dtime);
  }
}

Code Explanation