• Ankita Sharma

Smart Lighting System - Arduino - Controlling an LED & Buzzer using LDR Sensor

Updated: Dec 15, 2020

Efficient energy utilization plays an important role in sustainable economic development. For high-efficiency and reliability, LED is already a winner in lighting technology. Adding smartness to LEDs further boost its superiority. Smart Lighting System is a basic automation technology to reduce energy consumption and to prevent wastage of resources.


In this article, we will see how to make a Smart Lighting System using the LDR sensor.


Hardware Components :


The following hardware components are required for designing the circuit -

Components Required

Breadboard :

Breadboard

They are basically a construction base used for prototyping electronic circuits. Breadboards allow us to make quick connections between hardware components, without soldering.


Buy Breadboard from here.


Arduino UNO :

Arduino UNO

#Arduino UNO is an open-source microcontroller board containing a set of digital, analog pins, power pins, and interfaces for serial communication and USB (Universal Serial Bus) ports. Arduino boards are used to read inputs like light on a sensor and turn it into an output.


Buy Arduino UNO from here.


LDR Sensors :

LDR Sensors

#LDR ( Light Dependent Resistors ), also known as #photoresistors has a variable resistance that changes with the change in light intensity falling on it. It is inexpensive and mainly used to detect light levels in the automated lighting system.


Buy LDR Sensors from here.


Jumper Wires :


Jumper Wires

Jumper wires are the connecting wires that have connector pins at each end, allowing them to be used to connect the two points without soldering. They typically come in three versions - male-to-male, male-to-female, and female-to-female.


Buy Jumper Wires from here.


LEDs :

LEDs

#LEDs ( Light Emitting Diodes ) are semiconductor devices that emit light whenever current flows through them. It consists of two leads - Cathode and Anode. Cathode lead is smaller as compared to the anode.


Buy LEDs from here.


Resistors :


220-ohm Resistor
10 k-ohm Resistor

#Resistors are passive two-terminal devices used to limit the amount of current flow in the circuit. For this project design, we will be using 1k ohm and 220-ohm resistors. They protect the sensor from the high electricity flow.


Buy Resistance box from here.


Buzzer :

Buzzer

A #buzzer is a small and compact two-pin structure consisting of a positive ( longer terminal lead ) and a negative pin ( short terminal lead ). It is an audio signaling device mainly used to alarm the user with something important.


Buy Buzzer from here.


Softwares :


Arduino IDE :


Arduino Integrated Development Environment ( IDE ) is open-source software that facilitates the development and uploading of codes to the microcontroller. Program written in Arduino IDE is called Sketch. These Sketch files are saved with the file extension ino.


Here is the link to download the software


Circuit Connections :


The circuit connections are as shown in the figure below -


circuit connections
  1. The positive side of Buzzer is connected to pin 12 of the Arduino Board while the negative side is connected to the ground.

  2. The positive side of the LED pin is connected to a 220-ohm resistor while the other terminal of the resistor is connected to pin12 of the Arduino.

  3. GND ( Ground ) pin of the Arduino is connected to the ground of #Breadboard.

  4. One side of the LDR is connected to +5V of the Arduino Board, and another side is connected to a 10k ohm resistor as well as the A0 pin of the Arduino board.

  5. The other terminal of the 10k ohm resistor is connected to the ground of Arduino.


Code Explanation :


The code explanation for making a Smart Lighting system is as follows -

const int led=13; //this represents led pin
const int buzzer=12; //this represents buzzer pin
const int ldr = A0; //this represents ldr pin

Firstly, we declared variables for LED, Buzzer, LDR, and assigned pins as pin 13, 12, and A0 respectively.

void setup ()
 {
  Serial.begin(9600);
  pinMode(led, OUTPUT);
  pinMode(buzzer, OUTPUT);
  pinMode(ldr, INPUT);
 }

Secondly, we declared pins as output/input. Here, led ( pin 13 ) and buzzer (pin 12) are declared as output pins and LDR(A0 pin ) is declared as an input pin.

void loop()
 {
    int val=analogRead(ldr);  //read the value from the LDR and storing it in val variable
    if (val>=500) {  //when value goes above 500
    tone(buzzer, 100); //buzzer gets ON
    digitalWrite(led, HIGH); //LED gets ON
    delay(1000); //delay of 1000 msec ( 1 sec )

    noTone(buzzer); //buzzer gets OFF
    digitalWrite(led, LOW); //LED gets OFF
    delay(1000); //delay of 1000 msec ( 1 sec )
  } 

Reading analog values from LDR and storing them in a variable ( Val ). Now, we will be applying a condition that whenever the LDR value goes above 500, the Buzzer and LED gets ON and starts blinking with a time delay of 1000 msec.

  else
 {
    noTone(buzzer); //buzzer gets OFF permanently until value is below 500
    digitalWrite(led, LOW); //LED gets OFF permanently until value is below 500
  }

If the LDR value is below 500 then Buzzer and LED will get OFF.


Complete Code :


const int led=13; //this represents led pin
const int buzzer=12; //this represents buzzer pin
const int ldr = A0; //this represents ldr pin

void setup () {
  Serial.begin(9600);
  pinMode(led, OUTPUT);
  pinMode(buzzer, OUTPUT);
  pinMode(ldr, INPUT);
}

void loop() {
  int val=analogRead(ldr);  //read the value from the LDR and storing it in val variable
  if (val>=500) {  //when value goes above 500
    tone(buzzer, 100); //buzzer gets ON
    digitalWrite(led, HIGH); //LED gets ON
    delay(1000); //delay of 1000 msec ( 1 sec )

    noTone(buzzer); //buzzer gets OFF
    digitalWrite(led, LOW); //LED gets OFF
    delay(1000); //delay of 1000 msec ( 1 sec )
  } 
  
  else {
    noTone(buzzer); //buzzer gets OFF permanently until value is below 500
    digitalWrite(led, LOW); //LED gets OFF permanently until value is below 500
  }
}

Download the document given below, copy the code, and then paste it into the Arduino IDE code window.

code
.txt
Download TXT • 871B

Note: Do not forget to change the file extension to .ino(Arduino IDE) file format before you upload the code to Arduino Board.


Once the hardware connections are completed and the code is written, connect the Arduino board to the system via USB cable. Now, upload the code to the board and then Run.


Working:


The working principle of the #Smart lighting system is based on the principle of photoconductivity, which states that the conductivity of the LDR varies according to the absorption of light. Whenever the LDR value reaches a threshold value ( 500 in this case ), the LED turns ON and the buzzer beeps.


Do watch the video given below to get a better idea of the Smart #Lighting System through practical implementation.


Video By - Abhishek Goud


This article demonstrates a #prototype of a Smart Lighting System in which we control the lights of a room depending on the intensity of light. The smart lighting system is no doubt an #innovation with many future #applications apart from street lights, headlights, and industrial lights.

See Also :


  • Facebook
  • YouTube
  • Instagram
  • LinkedIn
LearnElectronics
Contact Us
© Copyright - LearnElectronics 2020.