Laboratory Exercise #05 – Light Sensor: An
Application of LDR
Mark Lorenzo B. Camarines
Bachelor of Science in Mechanical Engineering
Visayas State University
Baybay City, Philippines
[email protected]
Abstract—This laboratory demonstrates the construction of • To develop an Arduino program that receives
a light sensor circuit with an Arduino UNO and a Light sensor values and controls an LED based on a
Dependent Resistor (LDR). The circuit employs a voltage predefined threshold.
divider configuration to quantify light intensity and then
transmits that signal to an LED. For illustrative purposes • To acquire hands-on experience in sensor
regarding fundamental principles in sensor interfacing, voltage interface, circuit fabrication, and embedded
division, and embedded programming, the LED activates when programming.
ambient light levels fall within a specified threshold.
• To examine the sensor’s performance under
Keywords—Arduino, LDR, Light Sensor, LED, Voltage changing light conditions.
Divider, Microcontroller, Sensor Interfacing
B. Scope and Limitation
I. INTRODUCTION This laboratory exercise focuses on the basic integration
In today’s technology-driven world, the integration of of a light sensor (LDR) with an Arduino UNO to construct a
sensors with microcontrollers plays a key role in building threshold-based LED control circuit. The scope covers
intelligent systems for automation, environmental monitoring, designing a voltage divider circuit, programming the
and smart devices. The Arduino platform, with its ease of use microcontroller for analog-to-digital conversion, and
and versatility, has become a popular tool for both beginners developing a rudimentary decision-making algorithm.
and specialists in developing such systems. One of the most However, the experiment is constrained to a single sensor type
accessible and frequently used sensors is the Light according and a set threshold value, which may not account for all
Resistor (LDR), which regulates its resistance according on variations in ambient light conditions. Advanced calibration
the intensity of incoming light. When combined with a voltage procedures, signal conditioning, and applications in more
divider circuit, the LDR delivers an analog voltage that is dynamic circumstances are beyond the scope of this exercise
proportional to the ambient light levels. [4], [5].
This laboratory exercise focuses on designing a simple yet III. METHODOLOGY
effective light sensor circuit using an LDR and an Arduino 1. Component Assembly: Gather all needed
UNO. The primary objective is to detect ambient light components: Arduino UNO, LDR, LED, 330 Ω
conditions and control an LED accordingly; the LED turns on resistor, 10 kΩ resistor, breadboard, USB cable, and
when the environment is dark (i.e., when the LDR’s resistance connecting wires.
increases) and remains off in bright conditions. By completing
this project, students receive hands-on experience with sensor
2. Circuit Construction:
interfacing, analog-to-digital conversion, and the use of
conditional logic in embedded systems programming. • Build a voltage divider by connecting the 10 kΩ
Moreover, the practical aspects of wiring, circuit constructing, resistor to the Arduino’s 5V supply and the
and troubleshooting improve theoretical notions learned in LDR in series.
class. This activity is congruent with educational strategies • Connect the junction of the resistor and LDR to
that emphasize practical learning and give a good platform for analog pin A0.
more advanced sensor applications [1], [2]. Additionally, by • Attach the free end of the LDR to the common
offering direct visual feedback via the LED indicator, the ground (GND).
project illustrates the real-world impact of sensor-based
control systems, bridging the gap between abstract theory and 3. Wire the LED: connect its anode via a 330 Ω resistor
actual engineering [3]. to digital pin 12, and its cathode to the common
ground.
II. OBJECTIVES
A. Objectives 4. Programming:
• To comprehend the working of a Light • Open the Arduino IDE and create a new sketch.
Dependent Resistor (LDR) as a light sensor. • Input the supplied code, which reads the analog
value from the LDR, compares it against a
• To create a sensor circuit with a voltage divider threshold (500), and turns the LED on or off
configuration.
accordingly.
5. Verification and Upload:
MEng 125n – Basic Electronics
2nd Semester SY 2023-2024
Instructor: Engr. Philip Caesar L. Ebit
• Verify the code for bugs in the IDE.
• Upload the code to the Arduino board using the void loop() {
USB connection. lightValue = analogRead(lightPin);
// Read the value from the LDR
6. Testing and Data Collection: Serial.println(lightValue);
• Open the Serial Monitor to view the LDR // Print the sensor value to the Serial
readings. Monitor
• Vary ambient light conditions (e.g., cover the
// Compare the sensor reading to the
sensor or expose it to light) and observe the
threshold
LED’s reaction.
if (lightValue > 500) {
// Condition: if room is dark (value above
7. Analysis:
threshold)
• Compare sensor values to the threshold to digitalWrite(ledPin, HIGH);
confirm the correct functioning of the circuit. // Turn the LED on
A. Materials } else {
// Otherwise, if room is bright (value
• 1 – Arduino UNO R3
below threshold)
• 1 – USB Cable (USB-A to USB-B) digitalWrite(ledPin, LOW);
// Turn the LED off
• 1 – LDR (photocell) }
• 1 – LED (Red)
delay(10);
• 1 – 330 ohms resistor // Short delay for rapid sensor updates
• 1 – 10k ohms resistor }
• 1 – Breadboard Explanation:
• Connecting Wires
Variable Declarations: The variables lightPin, ledPin,
• Computer with Arduino software and lightValue are declared to indicate the sensor input, the
B. Circuit Diagram LED output, and to store the sensor’s analog value,
respectively.
Setup Function: Initializes serial connection for
monitoring sensor data and sets the LED pin as an output.
Loop Function:
• Reads the analog input from the LDR using
analogRead().
• Prints the sensor value to the Serial Monitor for
real-time monitoring.
• Uses an if-else statement to check the sensor
reading against the threshold value of 500. If
the value is above 500 (indicating low ambient
Figure 1 light), the LED is switched on; otherwise, it is
shut off.
C. Code • A minor delay of 10 milliseconds is included to
// Assign variables for sensor and LED permit rapid and stable sensor updates.
int lightPin = 0;
// Analog pin for the LDR
int ledPin = 12; IV. RESULTS AND DISCUSSIONS
// Digital pin for the LED The experimental setup successfully confirmed the
int lightValue = 0; functionality of an LDR-based light sensor circuit. The sensor
// Variable to store the sensor value readings, which normally ranged from around 16 under bright
circumstances to almost 970 in dark situations, were
void setup() { effectively exploited to determine the active state of the LED.
Serial.begin(9600); When the analog value crossed the threshold of 500, the LED
// Initialize serial communication at was illuminated, confirming the circuit's sensitivity to low-
9600 baud rate light settings. These observations are compatible with
pinMode(ledPin, OUTPUT); acknowledged sensor interface techniques and illustrate the
// Set the LED pin as an output reliability of simple threshold-based regulation in embedded
} systems [1], [3]. Minor variations in sensor readings may
MEng 125n – Basic Electronics
2nd Semester SY 2023-2024
Instructor: Engr. Philip Caesar L. Ebit
happen due to ambient circumstances and the inherent features
of the LDR and resistor, underscoring the need of calibration • Implement new calibration processes to
in practical applications. optimize the sensor’s response under diverse
ambient light situations.
V. CONCLUSIONS AND RECOMMENDATIONS
• Explore the use of additional sensors to
In conclusion, this laboratory exercise effectively construct a multi-parameter monitoring system,
exhibited the integration of an LDR-based light sensor circuit boosting the capabilities beyond simple light
with an Arduino UNO, displaying the seamless connectivity detection.
between hardware and software in embedded systems. The • Consider integrating wireless connection
system effectively detects ambient light levels by converting modules to offer remote monitoring and
the changing resistance of the LDR into an analog voltage control, therefore increasing the application of
using a voltage divider circuit. The Arduino, designed to read the sensor network in smart home or industrial
these voltage levels, effectively illuminates an LED, offering scenarios.
rapid visual feedback that proves the sensor’s operation. The
testing results, where sensor readings varied from roughly 16 Overall, this laboratory activity has delivered a thorough
in light circumstances to over 970 in darkness, supported the learning experience by integrating theoretical ideas with
expected threshold logic, with the LED being illuminated practical application. It has trained students to tackle
when the analog number reached 500. increasingly sophisticated projects in the domain of
embedded systems and sensor technologies, ensuring they are
The post lab questions further enlarged the activity by well-equipped for future challenges in both academic and
stimulating critical thinking on circuit changes and code professional settings [1], [2], [3], [4].
adjustments. For instance, when employing a different
Arduino analog input pin, the code must be modified to ACKNOWLEDGMENT
reflect the new pin assignment, which shows the Arduino’s To my dear mother, Angelita B. Camarines, who always
adaptability in supporting multiple hardware configurations. fully supported me, I would like to express my deepest
Additionally, upgrading the circuit to integrate many LEDs gratitude to her despite the problems faced during my
(red, yellow, and green) to represent varying brightness academics without question and to my lovely pair, Jemiah B.
ranges requires both hardware expansion and software Sabares, for always motivating me, keeping me from falling
modifications. This update, where the red LED may represent off and succumbing to pressure. I also want to reach my thanks
0–340, yellow for 340–680, and green for 680–1023, to my dear friends and regular-mates for continuing the
illustrates how a simple sensor circuit can be enhanced to support with each other. To our Basic Electronics instructor,
deliver more extensive environmental information. Engr. Philip Caesar Ebit for always guiding us and teaching
us not only in theory but also with hands-on experience-based
These results underline the necessity of calibration, learning.
sensor selection, and circuit design in obtaining accurate and
REFERENCES
consistent performance. The experiment not only met its
[1] N. Cameron, Arduino Applied, 2019, doi:10.1007/978-1-4842-3960-5.
teaching purposes but also cleared the route for subsequent
[2] J. Culkin and E. Hagan, Make: Learn Electronics with Arduino, An
investigation into complex sensor integration, multi-sensor Illustrated Beginner’s Guide to Physical Computing, Maker Media,
systems, and adaptive threshold algorithms. Inc., 2017.
[3] S. Monk, Electronics Cookbook, O’Reilly Media, Inc., 2017.
Based on these findings, it is proposed that future work [4] W. Osborne, Learn to Program in Arduino C: 18 Lessons, from setup()
in this area should include the following enhancements: to robots, Amdillo Books, 2017.
MEng 125n – Basic Electronics
2nd Semester SY 2023-2024
Instructor: Engr. Philip Caesar L. Ebit