You are on page 1of 4

PRACTICAL NO.

04
AIM - Interfacing LDR with Arduino uno r4 wifi to sense light Presence

APPARATUS – LDR Sensor Module, LED, breadboard, 220 Ohm Resistor (1), jumper
wires, Arduino uno r4 wifi, 5V adapter, Software – Arduino IDE.

THEORY -
LDR sensor module is used to detect the intensity of light. It is associated with
both analog output pin and digital output pin labelled as AO and DO respectively on the board.
When there is light, the resistance of LDR will become low according to the intensity of light.
The greater the intensity of light, the lower the resistance of LDR. The sensor has a
potentiometer knob that can be adjusted to change the sensitivity of LDR towards light.

LDR Sensor Module Pin Diagram –

Pin No Pin Name Description

1 VCC +5 v power supply Input Pin

2 GND Ground (-) power supply Input Pin

3 D0 Digital Output Pin

4 A0 Digital Output Pin


CIRCUIT DIAGRAM-

SOURCE CODE

// Interfacing of LDR Sensor module with Arduino UNO (using digital


output) int val = 0 ;

void setup()

{
Serial.begin(9600); // sensor buart rate
pinMode(3,INPUT); // LDR Sensor output pin
connected pinMode(4,OUTPUT); // LED PIN

} void
loop()
{ val = digitalRead(3); // LDR Sensor output pin connected
Serial.println(val); // see the value in serial mpnitor in Arduino
IDE delay(10); if(val == 0 ) {
digitalWrite(4,HIGH); // LED ON
delay(1000);

}
else { digitalWrite(4,LOW); //
LED OFF
}
SOURCE CODE IN IDE -

OUTPUT -

PROCEDURE -
1. Follow the circuit diagram and make the connections as shown in circuit diagram
2. Open the Arduino IDE software on your computer. Coding in the Arduino language
will control your circuit. Open a new sketch File by clicking on New.
3. Write the code as per Source Code.
4. Compile the program and check for any errors.
5. Upload the code to Arduino through the USB connector selecting the COM port.
6. Observe the result.
WORKING -

Serial.begin() sets the baud rate for the data transfer.

1. Using the digitalRead (3) function reads the data on the digital pin no 3.
2. The value of this data is stored inn an integer variable named val.
3. Using Serial.println() we print the readings of the sensor module on the serial moniter.
4. We check the condition if sensor value is 0 , turn on the LED , else turn off the LED.

ALGORITHM -

1. Initialize the pin according to their function.


2. Read the data at the digital input pin which reads the sensor output.
3. HIGH=1 and LOW=0
4. If the button state is 1 (HIGH) turn off the LED.
5. Else (button state is 0{LOW}) turn on the LED.

RESULT –
When there is darkness the LDR sensor module senses it and sends the low state on its output
pin which is read by the Arduino and the led turns on. When there is light on the sensor it turns
the led off.

CONCLUSION –

Marks Obtained Dated signature


of Teacher
Attendace30% Performance Skills Safety Conclusion Total
20% 2 precaution 20% 25
0% 10%

You might also like