Professional Documents
Culture Documents
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.
SOURCE CODE
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 -
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 -
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 –