KY-018 Photoresistor Module

View on Amazon
Overview
About KY-018 Photoresistor Module
The KY-018 Photoresistor Module is a light-sensitive sensor that varies its resistance based on the ambient light intensity. It contains a light-dependent resistor (LDR) and a fixed 10 kΞ© resistor, forming a voltage divider circuit. As the surrounding light increases, the LDRβs resistance decreases, resulting in a higher output voltage. This module operates at a voltage range of 3.3V to 5V and provides an analog output signal. Itβs commonly used in applications such as ambient light detection, automatic lighting control, and light intensity measurement.
Get Your KY-018
π‘ Prices are subject to change. We earn from qualifying purchases as an Amazon Associate.
KY-018 Specifications
Complete technical specification details for KY-018 Photoresistor Module
π Technical Parameters
KY-018 Pinout
The **KY-018** is a 3-pin photoresistor/LDR (light-dependent resistor) module:
Visual Pinout Diagram

Pin Types
Quick Tips
**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
Pin Descriptions
| Pin Name | Type | Description | Notes |
|---|---|---|---|
1 Pin (-) | Power | Ground connection | |
2 Pin (middle) | Power | Power supply | 3.3V to 5V |
3 Pin (S) | Communication | Analog signal output | Voltage increases with light intensity |
Wiring KY-018 to ESP32
To interface the **KY-018** with an **ESP32** for light intensity measurement:
Visual Wiring Diagram

Connection Status
Protocol
Pin Connections
| KY-018 Pin | Connection | ESP32 Pin | Description |
|---|---|---|---|
1 Pin (-) Required | GND | Ground | |
2 Pin (middle) Required | 3.3V or 5V | Power supply | |
3 Pin (S) Required | 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 Troubleshooting
Common issues and solutions to help you get your sensor working
Common Issues
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.
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.
Debugging Tips
Use the Serial Monitor to check for error messages and verify the sensor's output. Add debug prints in your code to track the sensor's state.
Use a multimeter to verify voltage levels and check for continuity in your connections. Ensure the power supply is stable and within the sensor's requirements.
Additional Resources
KY-018 Programming Examples
Ready-to-use code examples for different platforms and frameworks
int sensorPin = A0; // Photoresistor connected to analog pin A0
int sensorValue = 0;
void setup() {
Serial.begin(9600);
Serial.println("KY-018 Photoresistor Test");
}
void loop() {
sensorValue = analogRead(sensorPin);
Serial.print("Light Intensity: ");
Serial.println(sensorValue);
delay(500);
}This Arduino code sets up the KY-018 photoresistor on analog pin A0. It reads the analog value corresponding to the light intensity and prints it to the serial monitor every 500 milliseconds.
#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.
sensor:
- 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.
platformio.ini
[env:esp32]
platform = espressif32
board = esp32dev
framework = arduinomain.cpp
#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.
import 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.
Wrapping Up KY-018
The ESP32 KY-018 Photoresistor Module is a powerful KY-0xx module sensor that offers excellent performance and reliability. With support for multiple development platforms including Arduino, ESP-IDF, ESPHome, PlatformIO, and MicroPython, it's a versatile choice for your IoT projects.
Best Practices
For optimal performance, ensure proper wiring and follow the recommended configuration for your chosen development platform.
Safety First
Always verify power supply requirements and pin connections before powering up your project to avoid potential damage.
Ready to Start Building?
Now that you have all the information you need, it's time to integrate the KY-018 into your ESP32 project and bring your ideas to life!
Explore Alternative Sensors
Looking for alternatives to the KY-018? Check out these similar sensors that might fit your project needs.

KY-010 Photo Interrupter Module
The KY-010 is a photo interrupter module that detects objects by sensing interruptions in an infrared beam. It's ideal for applications...

KY-034 Automatic Flashing Color LED Module
The KY-034 is an automatic flashing color LED module that emits a sequence of seven colors when powered. It's suitable for decorative and...

KY-001 Temperature Sensor Module
The KY-001 is a temperature sensor module that operates within a wide temperature range. It supports 1-Wire communication and is based on...





