Arduino Interfacing with LDR sensor diagram,working,code

This app note covers Arduino Interfacing with LDR sensor diagram and its working. It describes LDR sensor used and mentions arduino code.

LDR is widely used for various applications such as power savings, smart escalators, smart lighting, automatic urinal flushing system, camera shutter control, lighting switch and so on. This application note provides interfacing and working of LDR with arduino Uno board.

About LDR sensor

LDR is the short form of Light Dependent Resistor. It houses component which changes resistance when light intensity falls upon it. Hence LDR is used for light sensing circuits. LDRs are used where we need to monitor intensity of light.

LDR Curve and LDR Symbol

The figure depicts LDR illumination versus resistance curve and LDR symbol. As shown, resistance of the sensor changes with intensity of the light and consecutively output voltage also changes. The arduino board can be used along with LDR sensor in order to read the analog voltage. By programming threshold value in the code and reading the realtime values of the voltage from LDR sensor, one can decide whether it is dark or bright.

About Arduino board

Arduino board

• Arduino Uno houses ATmega328 microcontroller from ATMEL. This microcontroller contains flash memory (32 KB), RAM (2 KB), 8 bit wide CPU and 1 KB EEPROM.
• It also supports 6 analog pins which reads voltage and not current. Inside, it converts analog measurement to digital for various purposes. It supports digital pins (0 to 13) which can function either as input or output.
• It has various interfaces viz. I2C, digital pins, analog pins, serial communication, USB etc.
• It also has reset pin, power port, crystal oscillator and Tx/Rx LEDs.
• This open source prototype board can be easily programmed using easy to use arduino IDE and USB interfaced between laptop PC and arduino board.
• IDE uses simplified C++ program.
• Board requires 5V DC which can be powered using AC/DC adapter or battery.

Arduino Interfacing with LDR sensor diagram and its working

Following figure depicts arduino uno board interfacing with LDR at its 5V, GND and A0 pins.

Arduino Interfacing with LDR sensor

One can use other boards such as ESP32 or ESP8266 or any microcontroller boards for interfacing LDR sensor with analog read input.

Arduino LDR sensor interface code

Following is the arduino code compiled and uploaded to the arduino board using Arduino IDE.

#define LDRpin A0 // pin of the arduino board i.e. A0 where LDR sensor and resistor are connected

int LDRValue = 0; // Variable where LDR sensor reading is stored

void setup() {
Serial.begin(115200); // baud rate setting for serial port communication

void loop() {
LDRValue = analogRead(LDRpin); // reading from LDR sensor
Serial.println(LDRValue); // Print value on serial port
delay(100); // wait for some period and keep printing

Conclusion: In this application note we have seen LDR sensor interfacing with Arduino Uno board. Arduino board is also used for interfacing different types of sensors for applications. The typical sensors interfaced with arduino are sound sensor, gyro sensor, heartbeat sensor, gas sensor, GPS sensor, color sensor, pH sensor etc.

IoT system on chip tutorial Related Links

This tutorial section on IoT (Internet of Things) covers following sub topics:
Main tutorial  IoT section  IoT article  Cellular IoT  Components  Sensors  INDIAN companies  Antenna Types  Wireless technologies  IoT transceiver  SoC 

RF and Wireless Terminologies