KY-018 Photoresistor Module
The KY-018 is a photoresistor module that detects ambient light levels. It outputs an analog signal corresponding to the light intensity, making it suitable for projects that require light sensing capabilities.

On this page
KY-018 pinout
The KY-018 is a 3-pin photoresistor/LDR (light-dependent resistor) module:
| Pin | Type | Description | Notes |
|---|---|---|---|
| Pin (-) | Power | Ground connection | |
| Pin (middle) | Power | Power supply | 3.3V to 5V |
| Pin (S) | Communication | Analog signal output | Voltage increases with light intensity |
Interface: Analog output (voltage divider circuit)
Sensor: LDR (light-dependent resistor) + 10kΩ fixed resistor
Output: Higher voltage = more light, lower voltage = less light
Power: 3.3V to 5V operation
Detection: Visible light spectrum sensitivity
Applications: Automatic lighting, light intensity measurement, day/night detection, solar trackers
Wiring the KY-018 to ESP32
To interface the KY-018 with an ESP32 for light intensity measurement:
| KY-018 pin | ESP32 pin | Purpose |
|---|---|---|
| Pin (-) | GND | Ground |
| Pin (middle) | 3.3V or 5V | Power supply |
| Pin (S) | GPIO36 | Analog input (ADC pin) |
ADC Pins: Use GPIO32-39 for analog input on ESP32
Voltage: 3.3V recommended for ESP32 ADC range
Response: LDR has slower response time compared to phototransistors
Calibration: Map ADC values to light levels for your specific application
KY-018 code examples
KY-018 Arduino example
Copyint sensorPin = 36; // Photoresistor on GPIO36 (ADC1_CH0, matches the wiring above)
int sensorValue = 0;
void setup() {
Serial.begin(115200);
Serial.println("KY-018 Photoresistor Test");
}
void loop() {
sensorValue = analogRead(sensorPin); // 0-4095 on the ESP32's 12-bit ADC
Serial.print("Light Intensity: ");
Serial.println(sensorValue);
delay(500);
}The photoresistor's analog output is read on GPIO36 (ADC1_CH0, matching the wiring above) with analogRead(), which on the ESP32 returns 0-4095 across the 12-bit range. Brighter light produces higher values. GPIO36 is input-only, which is exactly what an analog sensor needs.
KY-018 ESP-IDF example
Copy#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/adc.h"
#define PHOTORESISTOR_CHANNEL ADC1_CHANNEL_0 // GPIO36
void app_main(void) {
adc1_config_width(ADC_WIDTH_BIT_12);
adc1_config_channel_atten(PHOTORESISTOR_CHANNEL, ADC_ATTEN_DB_0);
printf("KY-018 Photoresistor Test\n");
while (1) {
int raw = adc1_get_raw(PHOTORESISTOR_CHANNEL);
printf("Light Intensity: %d\n", raw);
vTaskDelay(pdMS_TO_TICKS(500));
}
}This ESP-IDF code configures GPIO36 (ADC1_CHANNEL_0) to read analog values from the KY-018 photoresistor. It prints the raw ADC value, corresponding to light intensity, to the console every 500 milliseconds.
KY-018 ESPHome example
Copysensor:
- platform: adc
pin: GPIO36
name: "KY-018 Light Intensity"
update_interval: 500ms
filters:
- multiply: 0.00322265625This ESPHome configuration sets up the KY-018 photoresistor on GPIO36. It reads the analog value every 500 milliseconds and applies a multiplier to convert the raw ADC reading to a voltage value.
KY-018 PlatformIO example
Copy[env:esp32]
platform = espressif32
board = esp32dev
framework = arduino#include <Arduino.h>
#define PHOTORESISTOR_PIN 36
void setup() {
Serial.begin(115200);
Serial.println("KY-018 Photoresistor Test");
}
void loop() {
int sensorValue = analogRead(PHOTORESISTOR_PIN);
Serial.print("Light Intensity: ");
Serial.println(sensorValue);
delay(500);
}This PlatformIO code configures GPIO36 as an analog input to read the KY-018 photoresistor sensor values. The light intensity readings are printed to the serial monitor every 500 milliseconds.
KY-018 MicroPython example
Copyimport machine
import time
PHOTORESISTOR_PIN = 36 # ADC input pin
adc = machine.ADC(machine.Pin(PHOTORESISTOR_PIN))
adc.atten(machine.ADC.ATTN_11DB) # Full range 0-3.3V
while True:
light_intensity = adc.read()
print("Light Intensity:", light_intensity)
time.sleep(0.5)This MicroPython script configures GPIO36 as an ADC input for the KY-018 photoresistor sensor. The sensor value is read every 500 milliseconds and printed to the console.
KY-018 specifications
About the KY-018
The KY-018 is a cadmium-sulfide (CdS) photoresistor, commonly a GL55-series cell, paired with a fixed 10 kOhm resistor in a voltage divider - light and dark aren’t measured directly but inferred from how far the LDR’s resistance swings (roughly 1 megohm in darkness down to a few hundred ohms in bright light) against that fixed reference. The swing is nonlinear and not calibrated to lux, so the ADC reading is best used for relative brightness and threshold logic - day/night switching, shadow detection - rather than as an actual light meter.
CdS cells like this one also carry a cadmium-content issue: they’re increasingly restricted in RoHS markets, which matters if this is going into a product rather than a one-off build. On the wiring side, connect the signal pin to one of the ESP32’s ADC1 pins (GPIO32-39) - GPIO36 as shown above works fine - and pair it with a laser or LED module like the KY-008 for the classic beam-break tripwire project.
KY-018 troubleshooting
No Response from Sensor
›
Issue: The sensor does not output any signal regardless of light conditions.
Solutions:
- Verify that all connections are secure and correctly placed.
- Ensure the module is receiving the appropriate voltage (3.3V to 5V).
- Check if the microcontroller's analog input pin is correctly configured.
Incorrect or Fluctuating Readings
›
Issue: The sensor outputs inconsistent or incorrect light intensity values.
Solutions:
- Ensure stable lighting conditions during measurements.
- Check for loose connections or interference from nearby electronic components.
- Implement software filtering to smooth out rapid fluctuations in readings.
Where to buy the KY-018

Resources
Similar sensors





