Herdin Thorik Ndirakit community
Published

Auto Switch LED light with LDR Sensor and LCD Display - B24

A simple automatic light switching system using LDR sensors and LCD Display

BeginnerFull instructions provided1 hour239
Auto Switch LED light with LDR Sensor and LCD Display - B24

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
LDR, 5 Mohm
LDR, 5 Mohm
×1
I2C 16x2 Arduino LCD Display Module
DFRobot I2C 16x2 Arduino LCD Display Module
×1
Jumper wires (generic)
Jumper wires (generic)
Male to male and Male to female
×1
LED (generic)
LED (generic)
×1
Breadboard (generic)
Breadboard (generic)
×1
Resistor 330 ohm
Resistor 330 ohm
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Multitool, Screwdriver
Multitool, Screwdriver

Story

Read more

Schematics

Auto Light Switch Schematic

This is a little tricky, but i hope you can do it
The yellow LED is where the LDR sensor is located, so don't take it wrong guys

Code

Auto Light Switch Code

Arduino
Dont forget to download the I2C library to your IDE
#include <Wire.h> 
#include <LiquidCrystal_I2C.h>

const int ledPin = 12;   //the number of the LED pin
const int ldrPin = A0;  //the number of the LDR pin
LiquidCrystal_I2C lcd(0x27, 16, 2);


void setup() {
  Serial.begin(9600);
  lcd.init();
  lcd.backlight();
  lcd.setCursor(0,0);
  lcd.print("SELAMAT DATANG  ");
  pinMode(ledPin, OUTPUT); 
  pinMode(ldrPin, INPUT);   
}

void loop() {
  int ldrStatus = analogRead(ldrPin);   //read the status of the LDR value
Serial.println(ldrStatus);
   if (ldrStatus <=80) {

    digitalWrite(ledPin, HIGH);         //turn LED on
    lcd.print("LAMPU HIDUP");
    lcd.setCursor(0,3);

   }
  else {

    digitalWrite(ledPin, LOW);          //turn LED off
    lcd.print("LAMPU MATI ");
    lcd.setCursor(0,3);
  }
  delay(500);
}

Credits

Herdin Thorik N
1 project • 0 followers
dirakit community
23 projects • 109 followers
Indonesia IoT Community by Informatics UIN Sunan Kalijaga Yogyakarta

Comments