KY-054 Phototransistor Module

View on Amazon
Overview
About KY-054 Phototransistor Module
The KY-054 Phototransistor Module is designed to detect light intensity and convert it into an electrical signal. It operates similarly to a light-dependent resistor (LDR) but offers faster response times and greater sensitivity. This module is ideal for applications such as ambient light monitoring, automatic brightness adjustment, and light-based control systems.
KY-054 Specifications
Complete technical specification details for KY-054 Phototransistor Module
📊 Technical Parameters
KY-054 Pinout
The **KY-054** is a 3-pin phototransistor light detection module:
Visual Pinout Diagram

Pin Types
Quick Tips
**Interface**: Analog output (light intensity measurement),💡 **Sensor**: Phototransistor (faster than LDR)
**Output**: Voltage varies with ambient light level,⚡ **Power**: 3.3V or 5V operation
**Response**: Faster response time than LDR sensors,🎯 **Applications**: Ambient light detection, automatic brightness control, light-triggered systems
Pin Descriptions
| Pin Name | Type | Description | Notes |
|---|---|---|---|
1 GND | Power | Ground connection | |
2 +V | Power | Power supply | 3.3V or 5V |
3 Signal | Communication | Analog output | Voltage proportional to light intensity |
Wiring KY-054 to ESP32
To interface the **KY-054** with an **ESP32** for light intensity measurement:
Pin Connections
| KY-054 Pin | Connection | ESP32 Pin | Description |
|---|---|---|---|
1 GND Required | GND | Ground | |
2 +V Required | 3.3V or 5V | Power supply | |
3 Signal Required | GPIO36 | Analog input (ADC pin) |
**ADC Pins**: Use GPIO32-39 for analog input on ESP32
**Voltage**: 3.3V recommended for ESP32 ADC compatibility
**Light Level**: Higher light = higher voltage output
**Faster Response**: Phototransistor responds quicker than LDR/photoresistor
KY-054 Troubleshooting
Common issues and solutions to help you get your sensor working
Common Issues
Issue: The sensor does not provide any output or the readings remain constant.
Solutions:
- Ensure that the module is properly powered with the correct voltage (3.3V or 5V).
- Verify that all connections are secure and correctly oriented.
- Check if the analog input pin on the microcontroller is functioning correctly by testing with another analog sensor.
Issue: The sensor provides erratic or incorrect light intensity values.
Solutions:
- Avoid exposing the sensor to direct light sources that may cause saturation.
- Implement software filtering techniques, such as averaging multiple readings, to smooth out fluctuations.
- Ensure that there are no loose connections or interference from nearby electronic components.
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-054 Programming Examples
Ready-to-use code examples for different platforms and frameworks
// Define pin for phototransistor
int light_sensor = A5;
// Definition of the parameters required for the calculation
const double U1 = 5.0;
const double R2 = 10000.0;
double U2;
double I;
double R1;
double lux;
int rawValue;
void setup() {
// Define the pin mode
pinMode(light_sensor, INPUT);
// Set up serial communication for serial monitor
Serial.begin(9600);
Serial.println("KY-054 Brightness test");
}
void loop() {
// Reading the voltage of the light sensor
rawValue = analogRead(light_sensor);
U2 = rawValue * (5.0/1023) ;
// Check U2 for the division
if (U2 != 0) {
// Calculate the resistance of the sensor
R1 = (U1 * R2) / U2;
// Calculate current
I = (U1 / R1) * 1000000.0;
// Calculate lux
lux = log(I)/0.06;
}
else lux = 0;
// Output the result on the serial monitor
Serial.print("Lux:\t");
Serial.println(lux);
// wait for one second
delay(1000);
}This Arduino code sets up the KY-054 phototransistor module to measure ambient light intensity. It reads the analog voltage from the sensor, calculates the corresponding lux value using a logarithmic formula, and outputs the result to the serial monitor every second.
This ESP-IDF code configures GPIO36 as an analog input to read the output of the KY-054 phototransistor module. It calculates the voltage value and estimates the light intensity in lux using a logarithmic formula. The readings are displayed on the console every second.
sensor:
- platform: adc
pin: GPIO36
name: "KY-054 Light Sensor"
update_interval: 1s
filters:
- multiply: 3.3
- lambda: |-
float resistance = (3.3 * 10000.0) / (x == 0 ? 1 : x);
float current = (3.3 / resistance) * 1000000.0;
return log(current) / 0.06;This ESPHome configuration sets up the KY-054 phototransistor module on GPIO36 as an analog input. It reads the voltage level, applies a mathematical conversion to estimate light intensity in lux, and updates the value every second.
platformio.ini
[env:esp32]
platform = espressif32
board = esp32dev
framework = arduinomain.cpp
#include <Arduino.h>
#define LIGHT_SENSOR_PIN 36
void setup() {
Serial.begin(115200);
Serial.println("KY-054 Light Sensor Test");
}
void loop() {
int raw_value = analogRead(LIGHT_SENSOR_PIN);
float voltage = raw_value * (3.3 / 4095.0);
Serial.printf("Light Sensor Voltage: %.2fV\n", voltage);
delay(1000);
}This PlatformIO code configures GPIO36 as an analog input for the KY-054 sensor. It reads the analog voltage, converts it to a readable format, and prints it to the serial monitor every second.
import machine
import time
import math
LIGHT_SENSOR_PIN = machine.ADC(machine.Pin(36))
LIGHT_SENSOR_PIN.atten(machine.ADC.ATTN_11DB)
while True:
raw_value = LIGHT_SENSOR_PIN.read()
voltage = (raw_value / 4095) * 3.3
resistance = (3.3 * 10000.0) / (voltage if voltage > 0 else 1)
current = (3.3 / resistance) * 1000000.0
lux = math.log(current) / 0.06
print("Light Intensity:", lux, "lux")
time.sleep(1)This MicroPython script sets up the KY-054 phototransistor module on GPIO36 as an analog input. It reads the sensor voltage, calculates the resistance, estimates the light intensity in lux, and prints the value every second.
Wrapping Up KY-054
The ESP32 KY-054 Phototransistor 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-054 into your ESP32 project and bring your ideas to life!
Explore Alternative Sensors
Looking for alternatives to the KY-054? Check out these similar sensors that might fit your project needs.
The KY-004 is a key switch module equipped with a tactile push-button. It provides a digital output signal when pressed, making it ideal for...
The KY-016 is an RGB LED module that can display a wide range of colors by adjusting the brightness of its red, green, and blue LEDs. It's...







