Arduino光敏電阻測試,適合家長及小朋友一齊創作。

Parent-Child STEM DIY: Arduino Light Sensor Indicator with KY-018 (2026)

In our previous Arduino STEM project, we used a PIR motion sensor to build a simple motion alarm. This time, we will take the next step and explore another common type of sensor: light sensing.

In this project, we use the KY-018 Photoresistor Sensor Module together with an Arduino Uno R3 to build a simple light sensor indicator.

The Arduino reads the light sensor value from the KY-018 and uses a threshold in the program to control an external LED.

The main purpose of this project is not simply to "make an LED light up". It introduces children to an important Arduino concept: Analog Input. Instead of only checking whether a sensor is HIGH or LOW, we can read a changing numerical value and use that value to make decisions.


Completed Arduino light sensor indicator: the KY-018 detects changes in ambient light and the Arduino controls the external LED.

💡 What Will We Learn?

This project introduces several useful Arduino basics:

  • What a photoresistor / LDR is
  • What Analog Input means
  • How to use analogRead()
  • How to view sensor readings with the Serial Monitor
  • How to use a threshold value to control an LED
  • Why LOW and HIGH can have different physical effects depending on the circuit connection

The basic learning process is:

Ambient Light → KY-018 → Analog Reading → Arduino Decision → LED Output

🧰 What You Need

Component Purpose
Arduino Uno R3 Main controller
KY-018 Photoresistor Sensor Module Detects changes in ambient light
LED Displays the sensor result
220Ω Resistor Limits current through the LED
Breadboard Allows easy, solderless prototyping
Jumper Wires Connects the Arduino, sensor and LED
USB Cable Power and programming connection

Because we are using an external LED, a 220Ω current-limiting resistor is used. The resistor helps limit the current flowing through the LED.

No soldering is required, making this project suitable for a simple parent-child STEM activity using a breadboard.

👨👩👧 Recommended Age and Time

  • Recommended age: Around 8 years old and above with adult guidance
  • Estimated time: Around 30–45 minutes, depending on age and Arduino experience
  • Difficulty: Beginner
  • Soldering required: No

💡 New Concept: Analog Input

In our previous PIR project, the Arduino mainly checked whether the sensor output was HIGH or LOW. We could think of this as a simple "yes or no" signal.

A photoresistor works differently.

A photoresistor, also known as an LDR, changes its electrical characteristics according to the amount of light it receives. The KY-018 module combines the photoresistor with its supporting circuit and provides a Signal (S) output that can be read by an Arduino analog input.

This allows us to work with a changing numerical value instead of only HIGH or LOW.

For this project, we use the Arduino Uno's A0 analog input to read the KY-018 signal.

This means children can progress from asking:

"Is there motion or not?"

to asking:

"What value is the sensor reading right now?"

This is an important step in learning how sensors and microcontrollers work together.

🔌 Wiring

First, connect the KY-018 as follows:

KY-018 Arduino Uno
S / Signal A0
VCC 5V
− / GND GND

Then connect the external LED and 220Ω resistor according to the actual circuit arrangement.

This project uses an Active-Low LED connection. With this wiring arrangement, the LED turns ON when Arduino D13 outputs LOW and turns OFF when D13 outputs HIGH.

Arduino Connection
D13 LED control connection through the 220Ω resistor
Other side of LED Connected to the positive supply

The actual ON/OFF behaviour of an LED depends on how it is connected. Therefore, when building the circuit, pay attention not only to the LED polarity but also to whether the LED is configured as active-high or active-low.

使用arduino uno r3去創作一個小型diy project,歡迎到新昌電腦找尋你的DIY配件。

Actual wiring setup: Arduino Uno with KY-018, external LED and 220Ω resistor on a breadboard.

🔎 Why Does the LED Turn On When It Is Dark?

This is an important concept in this project.

The program contains the following condition:

if (lightLevel < 500) {
  digitalWrite(ledPin, LOW);
} else {
  digitalWrite(ledPin, HIGH);
}

With the actual LED connection used in this project:

Arduino D13 LED State
LOW LED ON
HIGH LED OFF

Therefore, when the Arduino reads a value below 500:

lightLevel < 500 → D13 LOW → LED ON

When the reading is 500 or above:

lightLevel ≥ 500 → D13 HIGH → LED OFF

In this particular setup, the LED can therefore be used as a simple light-sensitive indicator.

Important: LOW does not universally mean "LED OFF". Whether LOW turns an LED on or off depends on how the LED is connected in the circuit.

💻 Arduino Code

Here is the complete Arduino program used for this project:

const int lightSensorPin = A0;
const int ledPin = 13;

void setup() {
  pinMode(ledPin, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  int lightLevel = analogRead(lightSensorPin);

  Serial.println(lightLevel);

  if (lightLevel < 500) {
    digitalWrite(ledPin, LOW);
  } else {
    digitalWrite(ledPin, HIGH);
  }

  delay(200);
}

Understanding the Code

1. Set the sensor pin

const int lightSensorPin = A0;

This tells the Arduino that the KY-018 signal is connected to A0.

2. Set the LED pin

const int ledPin = 13;

The LED is controlled using digital pin 13.

3. Set the LED pin as an output

pinMode(ledPin, OUTPUT);

The Arduino needs to control the LED, so D13 is configured as an OUTPUT.

4. Start Serial communication

Serial.begin(9600);

This allows us to view the sensor readings in the Arduino IDE Serial Monitor.

5. Read the KY-018

int lightLevel = analogRead(lightSensorPin);

analogRead() reads the analog input from A0 and stores the result in lightLevel.

6. Print the reading

Serial.println(lightLevel);

The current sensor value is displayed in the Serial Monitor.

7. Compare the reading with 500

if (lightLevel < 500) {
  digitalWrite(ledPin, LOW);
} else {
  digitalWrite(ledPin, HIGH);
}

The program compares the current sensor reading with the threshold value of 500.

500 is not a universal light-level standard. It is simply the threshold used in this example. Actual readings can vary depending on the room, lighting conditions, sensor position and the particular module.

That is why checking the Serial Monitor is an important part of this project.

🧪 First Test: Change the Light and Observe the LED

  1. Check the KY-018 VCC, GND and Signal connections.
  2. Check the LED and 220Ω resistor connections.
  3. Connect the Arduino Uno to your computer using USB.
  4. Upload the program to the Arduino.
  5. Open the Arduino IDE Serial Monitor.
  6. Set the Serial Monitor speed to 9600 baud.
  7. Observe the reading under normal room lighting.
  8. Cover the KY-018 photoresistor with your hand.
  9. Shine a phone flashlight or torch at the KY-018.
  10. Compare the readings and the LED behaviour.

🔍 Why Use the Serial Monitor?

If we only look at whether the LED is ON or OFF, we can see the result but not the actual sensor reading.

The Serial Monitor lets us see the numerical value that the Arduino is receiving from the KY-018.

Try recording three different situations:

Test Condition Arduino Reading LED State
Normal room lighting Record your value Observe
Cover the sensor Record your value Observe
Phone flashlight / torch Record your value Observe

This creates a simple STEM learning cycle:

Observe → Measure → Set → Test → Modify

Instead of simply copying a program, children can use real measurements to understand what the sensor is doing.

🧠 How Does a Photoresistor Work?

A photoresistor, or LDR, is a light-sensitive component whose electrical resistance changes according to the light conditions.

The KY-018 integrates the photoresistor with supporting circuitry on a small PCB and provides a Signal (S) output that can be read by an Arduino analog input.

As the light conditions change, the sensor output changes. The Arduino then reads this signal as a numerical value that can be processed by the program.

The whole process can be visualised as:

Change in light

↓

KY-018 sensor output changes

↓

Arduino reads A0

↓

Program compares the value

↓

LED changes state

🎯 STEM Challenge: Find Your Own Threshold

Once the basic project is working, challenge your child to go one step further.

  1. Record the reading under normal room lighting.
  2. Cover the KY-018 and record the reading.
  3. Shine a phone flashlight or torch at the sensor.
  4. Compare the three readings.
  5. Change 500 in the program to another value.
  6. Upload the program again.
  7. Test the LED behaviour again.

Try asking questions such as:

  • "What happens if we change 500 to 300?"
  • "What happens if we change it to 700?"
  • "Do the readings change when the room light is switched on and off?"
  • "What happens if we move the sensor closer to a phone flashlight?"
  • "Does the same threshold work in another room?"

This turns the project from simply following instructions into a real measurement, comparison and experimentation activity.

🚀 Ideas for the Next Project

1. Build a Real Automatic Night Light

Use your measured sensor readings to choose a suitable threshold and make the LED respond automatically to the lighting conditions.

2. Add PWM Dimming

The next step is to learn about PWM and analogWrite(), allowing the LED brightness to be controlled instead of simply switching it ON or OFF.

3. Add a Buzzer

Add a buzzer that activates when the light level reaches a selected condition, turning the project into a simple light-sensitive alarm.

4. Add an LCD Display

Display the sensor reading directly on an LCD, for example:

Light Level: 420

This makes the sensor data easier for children to see and understand.

5. Combine It with the PIR Sensor

Combine the KY-018 with the PIR sensor from the previous project. For example, the LED could turn on only when both conditions are met: the environment is dark and motion is detected.

This introduces the idea of combining multiple sensor conditions to create a more useful automatic lighting system.

🧠 What Arduino Skills Did We Learn?

Concept What We Learned
Analog Input Use A0 to read the KY-018
analogRead() Read the sensor signal as a numerical value
Serial Monitor View the actual sensor readings
if / else Make different decisions based on the reading
Threshold Use 500 as an example decision point
Digital Output Control the LED using D13
Active-Low Understand that LOW can turn an LED ON depending on the circuit

👨👩👧 Parent Safety Tips

  • Disconnect the Arduino USB power before changing the wiring.
  • Check the VCC, GND and Signal connections before powering the circuit.
  • Use a current-limiting resistor with the external LED.
  • This project uses low-voltage USB power and does not involve mains electricity.
  • Adult supervision is recommended for children.
  • Keep small electronic components away from young children.
  • If the LED does not behave as expected, first check the LED polarity, D13 connection and resistor placement, then check the program.

❓ FAQ

Q1: Do I need a breadboard?

No. A breadboard is simply a convenient way to build and modify the circuit without soldering. It is particularly useful for beginner and parent-child STEM projects.

Q2: Why is the KY-018 connected to A0 instead of a digital pin?

Because this project reads a changing sensor value rather than simply checking HIGH or LOW. An Arduino analog input such as A0 is used to read the sensor signal.

Q3: Why does the LED turn on when it gets dark?

In this project, when lightLevel < 500, the program sets D13 to LOW. Because the external LED is connected using an active-low arrangement, LOW turns the LED ON.

Q4: Is 500 a fixed light-level standard?

No. 500 is only the example threshold used in this project. Actual readings can vary depending on the room lighting, sensor position and module. Use the Serial Monitor to determine a suitable threshold for your own setup.

Q5: What if my LED behaves differently from the article?

First check the LED wiring. Whether LOW or HIGH turns an LED on depends on the actual circuit configuration. A different LED connection can produce the opposite ON/OFF behaviour with the same program.

Q6: Can I use the built-in Arduino LED instead?

Yes, it can be used for a simple test. However, this project uses an external LED so that children can also learn about LED polarity, current-limiting resistors, breadboard wiring and practical circuits.

Q7: Why does the Serial Monitor value keep changing?

The sensor continuously responds to its surroundings. Room lights, your hand, sunlight, a phone flashlight and the position of the sensor can all affect the reading. Therefore, the value does not necessarily stay at one fixed number.

Q8: What should I do if 500 does not work well in my room?

Record the readings under different lighting conditions and then change 500 to a threshold that better matches your actual environment. Upload the program again and test it.

🎥 Actual Test Result


Actual Arduino light sensor test: change the ambient light and observe the KY-018 reading and LED behaviour.

📚 From PIR to KY-018: Taking Arduino Learning Further

If you followed our previous Arduino motion alarm project, this project is a natural next step.

Previous Project: PIR This Project: KY-018
Motion detection Light sensing
Digital Input Analog Input
HIGH / LOW Numerical readings
digitalRead() analogRead()
Detect whether motion is present Compare light sensor values

Through these two projects, children begin to understand one of the most important basic concepts of Arduino:

The sensor detects, the Arduino decides, and the output component shows the result.

🏠 Conclusion: Learning Arduino Through Sensors

In this project, we used a KY-018 photoresistor sensor module and an Arduino Uno to build a simple light sensor indicator.

Children are not only learning how to connect components and upload code. They are also learning how to understand the relationship between:

Environmental Change → Sensor → Numerical Value → Program Decision → Output

By using the Serial Monitor to observe real readings and changing the threshold value of 500, children can move beyond simply following instructions and start experimenting with real sensor data.

In the previous project, we introduced PIR and Digital Input. This project introduces the KY-018 and Analog Input. The next step could be PWM, LED dimming, ultrasonic distance sensing, LCD displays or even Wi-Fi IoT projects.

🛒 Related Products

If you are looking for Arduino, STEM and DIY electronic components in Hong Kong, you can also visit Sun Cheong Computer in Sham Shui Po to explore related products in person.

🔖 More Arduino STEM Ideas

After completing this light sensor project, you can continue with:

  • Arduino PWM LED automatic dimming
  • Arduino ultrasonic distance sensor
  • Arduino temperature sensor
  • Arduino LCD display
  • PIR + KY-018 dual-sensor automatic light
  • ESP32 Wi-Fi smart sensor projects

Starting with a simple photoresistor, children can gradually build their own Arduino STEM projects and learn how sensors, code and electronics work together.

Back to blog