PR 4
PR 4
PR 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.
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
}
}
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 -
ALGORITHM -
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 –