KY-013 Analog Temperature Sensor Module

View on Amazon
Overview
About KY-013 Analog Temperature Sensor Module
The KY-013 Analog Temperature Sensor Module features an NTC thermistor capable of measuring temperatures ranging from -55°C to +125°C. As a negative temperature coefficient (NTC) thermistor, its resistance decreases with increasing temperature. This characteristic allows for temperature determination by measuring the voltage across the thermistor when used in a voltage divider configuration. The module operates at voltages between 3.3V and 5V, making it compatible with various microcontrollers, including Arduino and ESP32. It’s commonly used in applications such as climate control systems, environmental monitoring, and other temperature-dependent processes.
Get Your KY-013
Prices are subject to change. We earn from qualifying purchases as an Amazon Associate.
KY-013 Specifications
Complete technical specification details for KY-013 Analog Temperature Sensor Module
📊 Technical Parameters
KY-013 Pinout
The **KY-013** is a 3-pin analog temperature sensor module with NTC thermistor:
Visual Pinout Diagram

Pin Types
Quick Tips
**Interface**: Analog output (voltage divider),🌡️ **Sensor**: NTC thermistor (negative temperature coefficient)
**Range**: -55°C to +125°C,🎯 **Accuracy**: ±0.5°C (typical)
**Power**: 3.3V to 5V operation,💡 **Operation**: Resistance decreases as temperature increases
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 varies with temperature |
Wiring KY-013 to ESP32
To interface the **KY-013** with an **ESP32** for analog temperature reading:
Pin Connections
| KY-013 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
**Conversion**: Requires Steinhart-Hart equation for accurate temperature
**Filtering**: Software averaging recommended for stable readings
KY-013 Troubleshooting
Common issues and solutions to help you get your sensor working
Common Issues
Issue: The sensor outputs inaccurate or fluctuating temperature values.
Solutions:
- Ensure stable power supply to the sensor.
- Verify correct wiring connections, especially the analog signal pin.
- Implement proper analog signal filtering in the code to reduce noise.
Issue: The sensor provides no data or constant values.
Solutions:
- Check for loose or incorrect connections.
- Confirm that the analog input pin on the microcontroller is functioning correctly.
- Test the sensor with a known temperature source to validate its operation.
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-013 Programming Examples
Ready-to-use code examples for different platforms and frameworks
#include <math.h>
int sensorPin = A0; // Analog input pin connected to the sensor
void setup() {
Serial.begin(9600);
}
void loop() {
int rawValue = analogRead(sensorPin);
double voltage = rawValue * (5.0 / 1023.0);
double resistance = (5.0 - voltage) * 10000 / voltage;
double temperature = 1 / (log(resistance / 10000) / 3950 + 1 / 298.15) - 273.15;
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" °C");
delay(1000);
}This Arduino code reads the analog value from the KY-013 sensor, calculates the corresponding temperature using the Steinhart-Hart equation, and outputs the temperature in Celsius to the serial monitor. The sensor is connected to analog pin A0.
#include <stdio.h>
#include <math.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/adc.h"
#define ADC_CHANNEL ADC1_CHANNEL_0 // GPIO36
void app_main(void) {
adc1_config_width(ADC_WIDTH_BIT_12);
adc1_config_channel_atten(ADC_CHANNEL, ADC_ATTEN_DB_11);
while (1) {
int raw = adc1_get_raw(ADC_CHANNEL);
double voltage = raw * (3.3 / 4095.0);
double resistance = (3.3 - voltage) * 10000 / voltage;
double temperature = 1 / (log(resistance / 10000) / 3950 + 1 / 298.15) - 273.15;
printf("Temperature: %.2f °C\n", temperature);
vTaskDelay(pdMS_TO_TICKS(1000));
}
}This ESP-IDF code configures ADC1 on GPIO36 to read the analog signal from the KY-013 sensor. It calculates the temperature using the Steinhart-Hart equation and prints the result in Celsius every second.
sensor:
- platform: ntc
sensor: resistance_sensor
name: "KY-013 Temperature Sensor"
calibration:
b_constant: 3950
reference_temperature: 25°C
reference_resistance: 10kΩ
- platform: adc
pin: GPIO36
id: resistance_sensor
update_interval: 1sThis ESPHome configuration sets up the KY-013 temperature sensor using an NTC thermistor on GPIO36. The resistance is measured via ADC, and the temperature is calculated using the Steinhart-Hart equation with a B-constant of 3950.
platformio.ini
[env:esp32]
platform = espressif32
board = esp32dev
framework = arduinomain.cpp
#include <Arduino.h>
#include <math.h>
#define SENSOR_PIN 36 // Analog input pin
void setup() {
Serial.begin(115200);
}
void loop() {
int rawValue = analogRead(SENSOR_PIN);
double voltage = rawValue * (3.3 / 4095.0);
double resistance = (3.3 - voltage) * 10000 / voltage;
double temperature = 1 / (log(resistance / 10000) / 3950 + 1 / 298.15) - 273.15;
Serial.printf("Temperature: %.2f °C\n", temperature);
delay(1000);
}This PlatformIO code configures the KY-013 temperature sensor on GPIO36. It reads the analog value, converts it to voltage, calculates the resistance, and then determines the temperature using the Steinhart-Hart equation.
import machine
import time
import math
SENSOR_PIN = 36 # ADC input pin
adc = machine.ADC(machine.Pin(SENSOR_PIN))
adc.atten(machine.ADC.ATTN_11DB) # Full range 0-3.3V
def get_temperature():
raw = adc.read()
voltage = raw * (3.3 / 4095.0)
resistance = (3.3 - voltage) * 10000 / voltage
temperature = 1 / (math.log(resistance / 10000) / 3950 + 1 / 298.15) - 273.15
return temperature
while True:
print("Temperature:", round(get_temperature(), 2), "°C")
time.sleep(1)This MicroPython script reads the KY-013 sensor using ADC on GPIO36. It converts the voltage to resistance and then calculates the temperature using the Steinhart-Hart equation. The temperature is printed to the console every second.
Wrapping Up KY-013
The ESP32 KY-013 Analog 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.
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-013 into your ESP32 project and bring your ideas to life!








