KY-054 Phototransistor Module

The KY-054 is a phototransistor module that detects ambient light levels and provides an analog voltage output proportional to the light intensity. It is commonly used in projects that require light sensing capabilities, such as automatic lighting systems and brightness detection.

Analog KY-0xx module Phototransistor
KY-054 Phototransistor Module image
KY-054 · Analog
Analog
Interface
3pins
Connections
3.3V - 5 V
Supply
-25 to 70 °C
Operating temp
$3
Typical price
On this page

KY-054 pinout

3 pins · Analog

The KY-054 is a 3-pin phototransistor light detection module:

View:
KY-054 Phototransistor Module pinout
PinTypeDescriptionNotes
GNDPowerGround connection
+VPowerPower supply3.3V or 5V
SignalCommunicationAnalog outputVoltage proportional to light intensity
  • 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

Wiring the KY-054 to ESP32

3 connections · all required

To interface the KY-054 with an ESP32 for light intensity measurement:

Wiring diagram coming soon
The pin-to-pin table covers every connection.
KY-054 pinESP32 pinPurpose
GNDGNDGround
+V3.3V or 5VPower supply
SignalGPIO36Analog 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 code examples

5 platforms
Platform:

KY-054 Arduino example

Copy
// Define pin for phototransistor
int light_sensor = 36; // GPIO36 / ADC1_CH0, matches the wiring above
// Definition of the parameters required for the calculation
const double U1 = 3.3;     // Supply voltage (ESP32: 3.3V)
const double R2 = 10000.0; // Series resistor
double U2;
double I;
double R1;
double lux;
int rawValue;

void setup() {
  Serial.begin(115200);
  Serial.println("KY-054 Brightness test");
}

void loop() {
  // Reading the voltage of the light sensor (ESP32: 12-bit ADC, 3.3V)
  rawValue = analogRead(light_sensor);
  U2 = rawValue * (3.3 / 4095.0);

  // 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.

KY-054 ESP-IDF example

Copy
#include <stdio.h>
#include <math.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/adc.h"

#define LIGHT_ADC_CHANNEL ADC1_CHANNEL_0 // GPIO36, matches the wiring above

void app_main(void)
{
    adc1_config_width(ADC_WIDTH_BIT_12);
    adc1_config_channel_atten(LIGHT_ADC_CHANNEL, ADC_ATTEN_DB_11);

    const double U1 = 3.3;     // supply voltage
    const double R2 = 10000.0; // series resistor

    while (1) {
        int raw = adc1_get_raw(LIGHT_ADC_CHANNEL);
        double U2 = raw * (3.3 / 4095.0);

        double lux = 0;
        if (U2 > 0) {
            double R1 = (U1 * R2) / U2;        // phototransistor resistance
            double I = (U1 / R1) * 1000000.0;  // current in microamps
            lux = log(I) / 0.06;               // approximate lux conversion
        }

        printf("Lux: %.1f\n", lux);
        vTaskDelay(pdMS_TO_TICKS(1000));
    }
}

The phototransistor's output is read on GPIO36 (ADC1 channel 0) with 11 dB attenuation for the full 3.3 V range. From the measured voltage the code derives the phototransistor's resistance in the 10k divider, converts it to a current, and applies the module's approximate logarithmic lux formula - fine for relative brightness; calibrate against a lux meter for absolute accuracy.

KY-054 ESPHome example

Copy
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.

KY-054 PlatformIO example

Copy
[env:esp32]
platform = espressif32
board = esp32dev
framework = arduino
src/main.cppCopy
#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.

KY-054 MicroPython example

Copy
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.

KY-054 specifications

From the datasheet
Operating Voltage
3.3V - 5V
Fixed Resistance
10 kΩ
Dimensions
28 x 15 x 7 mm
Operating Temperature
-25°C to 70°C
Output
Analog voltage proportional to light intensity

About the KY-054

The KY-054 uses an HLPT550B5H5 NPN silicon phototransistor rather than the cadmium-sulfide photoresistor on the KY-018, wired the same way - as one leg of a voltage divider against a fixed 10 kOhm resistor, so the ESP32 still reads a light-dependent voltage rather than anything calibrated to lux. The practical difference is speed and behavior: a phototransistor’s collector current tracks incident light in microseconds and follows a more predictable curve than a CdS cell’s resistance, which can take tens of milliseconds to settle and swings non-linearly over several orders of magnitude between dark and bright. Being silicon rather than cadmium-based also sidesteps the RoHS restrictions that increasingly apply to CdS photoresistors like the KY-018.

None of that makes the raw reading an accurate lux meter - treat it, like the KY-018, as a relative brightness signal for thresholds and day/night logic rather than an absolute measurement, and calibrate against a real lux meter if a project needs actual light-level numbers. On the wiring side the signal pin belongs on one of the ESP32’s ADC1 pins (GPIO32-39) as shown above, since ADC2 shares hardware with the WiFi radio and stops working reliably once WiFi is active.

KY-054 troubleshooting

2 common issues

No Response from the Sensor

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.

Inaccurate or Fluctuating Readings

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.

Resources