ESP32 KY-028 Digital Temperature Sensor Module
Overview
The KY-028 is a digital temperature sensor module equipped with an NTC thermistor. It offers both analog and digital outputs, with an adjustable threshold via an onboard potentiometer, making it ideal for temperature monitoring and control applications.
About KY-028 Digital Temperature Sensor Module
The KY-028 Digital Temperature Sensor Module features an NTC thermistor for temperature measurement. It provides both analog and digital outputs, allowing for precise temperature readings and threshold-based alerts. The module includes an onboard potentiometer to adjust the temperature threshold for the digital output, making it suitable for various temperature monitoring applications.
Where to Buy
Prices are subject to change. We earn from qualifying purchases as an Amazon Associate.
Technical Specifications
Pinout Configuration
The VCC
pin is used to supply power to the sensor, and it typically requires 3.3V or 5V (refer to the datasheet for specific voltage requirements). The GND
pin is the ground connection and must be connected to the ground of your ESP32.
GND:
Connects to ground.+V:
Connects to 3.3V or 5V power supply.A0:
Analog output providing a voltage proportional to the temperature.D0:
Digital output that goes high when the temperature exceeds the set threshold.
Troubleshooting Guide
Common Issues
❌ No Analog Output
Issue: The analog output does not change with temperature variations.
Solutions:
- Ensure proper connections to the analog output pin.
- Verify that the power supply voltage is within the specified range (3.3V to 5V).
- Check the thermistor for damage or disconnection.
❌ Digital Output Not Triggering
Issue: The digital output does not change state when the temperature exceeds the set threshold.
Solutions:
- Adjust the potentiometer to set the desired temperature threshold.
- Ensure the comparator (LM393) is functioning correctly.
- Check the indicator LEDs to confirm module operation.
Debugging Tips
🔍 Serial Monitor
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.
⚡ Voltage Checks
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
Code Examples
Arduino Example
int led = 13; // LED output pin
int digitalPin = 2; // KY-028 digital interface
int analogPin = A0; // KY-028 analog interface
int digitalVal; // digital readings
int analogVal; // analog readings
void setup() {
pinMode(led, OUTPUT);
pinMode(digitalPin, INPUT);
Serial.begin(9600);
}
void loop() {
// Read the digital interface
digitalVal = digitalRead(digitalPin);
if (digitalVal == HIGH) { // if temperature threshold reached
digitalWrite(led, HIGH); // turn ON Arduino's LED
} else {
digitalWrite(led, LOW); // turn OFF Arduino's LED
}
// Read the analog interface
analogVal = analogRead(analogPin);
Serial.println(analogVal); // print analog value to serial
delay(100);
}
This Arduino code reads both the digital and analog outputs of the KY-028 sensor. When the temperature exceeds the set threshold, the digital output goes HIGH, turning on the onboard LED connected to pin 13. The analog output provides a continuous reading corresponding to the temperature, which is printed to the serial monitor.
ESP-IDF Example
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/adc.h"
#include "driver/gpio.h"
#define TEMP_SENSOR_ANALOG_PIN ADC1_CHANNEL_0 // GPIO36
#define TEMP_SENSOR_DIGITAL_PIN GPIO_NUM_17
#define LED_PIN GPIO_NUM_16
void app_main(void) {
adc1_config_width(ADC_WIDTH_BIT_12);
adc1_config_channel_atten(TEMP_SENSOR_ANALOG_PIN, ADC_ATTEN_DB_11);
gpio_set_direction(TEMP_SENSOR_DIGITAL_PIN, GPIO_MODE_INPUT);
gpio_set_direction(LED_PIN, GPIO_MODE_OUTPUT);
printf("KY-028 Temperature Sensor Test\n");
while (1) {
int analog_value = adc1_get_raw(TEMP_SENSOR_ANALOG_PIN);
int digital_value = gpio_get_level(TEMP_SENSOR_DIGITAL_PIN);
if (digital_value == 1) {
gpio_set_level(LED_PIN, 1); // Turn on LED
printf("Temperature threshold exceeded. Analog Value: %d\n", analog_value);
} else {
gpio_set_level(LED_PIN, 0); // Turn off LED
printf("Temperature within normal range. Analog Value: %d\n", analog_value);
}
vTaskDelay(pdMS_TO_TICKS(1000));
}
}
This ESP-IDF code configures the KY-028 temperature sensor to read analog temperature values on GPIO36 and monitor the threshold-based digital output on GPIO17. If the temperature exceeds the set threshold, an LED on GPIO16 turns on, and the event is logged to the console.
ESPHome Example
sensor:
- platform: adc
pin: GPIO36
name: "KY-028 Temperature Analog"
update_interval: 1s
binary_sensor:
- platform: gpio
pin:
number: GPIO17
mode: INPUT_PULLUP
name: "KY-028 Temperature Threshold"
This ESPHome configuration reads the KY-028 sensor's analog output on GPIO36 and detects the temperature threshold trigger using GPIO17 as a binary sensor. Updates are logged every second.
PlatformIO Example
platformio.ini
[env:esp32]
platform = espressif32
board = esp32dev
framework = arduino
PlatformIO Example Code
#include <Arduino.h>
#define TEMP_SENSOR_ANALOG_PIN A0
#define TEMP_SENSOR_DIGITAL_PIN 17
#define LED_PIN 16
void setup() {
pinMode(TEMP_SENSOR_DIGITAL_PIN, INPUT);
pinMode(LED_PIN, OUTPUT);
Serial.begin(115200);
Serial.println("KY-028 Temperature Sensor Test");
}
void loop() {
int analog_value = analogRead(TEMP_SENSOR_ANALOG_PIN);
int digital_value = digitalRead(TEMP_SENSOR_DIGITAL_PIN);
if (digital_value == HIGH) {
digitalWrite(LED_PIN, HIGH);
Serial.printf("Temperature threshold exceeded. Analog: %d\n", analog_value);
} else {
digitalWrite(LED_PIN, LOW);
Serial.printf("Temperature normal. Analog: %d\n", analog_value);
}
delay(1000);
}
This PlatformIO code reads the KY-028 sensor's analog output and monitors the digital temperature threshold trigger. The values are printed every second, and an LED turns on when the temperature exceeds the set threshold.
MicroPython Example
import machine
import time
TEMP_SENSOR_ANALOG_PIN = machine.ADC(machine.Pin(36))
TEMP_SENSOR_ANALOG_PIN.atten(machine.ADC.ATTN_11DB)
TEMP_SENSOR_DIGITAL_PIN = machine.Pin(17, machine.Pin.IN, machine.Pin.PULL_UP)
LED_PIN = machine.Pin(16, machine.Pin.OUT)
while True:
analog_value = TEMP_SENSOR_ANALOG_PIN.read()
digital_value = TEMP_SENSOR_DIGITAL_PIN.value()
if digital_value:
LED_PIN.on()
print("Temperature threshold exceeded - Analog:", analog_value)
else:
LED_PIN.off()
print("Temperature normal - Analog:", analog_value)
time.sleep(1)
This MicroPython script reads the KY-028 sensor's analog signal using ADC on GPIO36 and monitors the digital output on GPIO17. An LED on GPIO16 turns on when the temperature threshold is exceeded, and the readings are printed every second.
Conclusion
The ESP32 KY-028 Digital Temperature Sensor 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.
For optimal performance, ensure proper wiring and follow the recommended configuration for your chosen development platform.
Always verify power supply requirements and pin connections before powering up your project to avoid potential damage.