ESP32 KY-001 Temperature Sensor Module
Overview
The KY-001 is a temperature sensor module that operates within a wide temperature range. It supports 1-Wire communication and is based on the popular DS18B20 digital sensor. This module is ideal for temperature monitoring projects requiring precise and reliable readings.
About KY-001 Temperature Sensor Module
The KY-001 is a temperature sensor module based on the DS18B20 digital temperature sensor. It communicates via the 1-Wire protocol, ensuring easy integration with ESP32, Arduino, and other microcontrollers. With high accuracy and a wide temperature range, it is ideal for temperature monitoring in smart home applications, weather stations, and industrial environments.
⚡ Key Features
- DS18B20-Based Sensor – Ensures reliable and accurate temperature measurements.
- High Accuracy – ±0.5°C from -10°C to +85°C.
- Wide Operating Range – Supports -55°C to +125°C.
- 1-Wire Communication – Simple connection with a single data wire.
- Requires 4.7kΩ Pull-Up Resistor – For stable operation between data and VCC.
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.
Pin 1 (GND):
Connects to the ground of the circuit.Pin 2 (VCC):
Supplies power to the module, typically 3.3V or 5V.Pin 3 (DATA):
Communicates via the 1-Wire protocol and requires a pull-up resistor.
Troubleshooting Guide
Common Issues
❌ KY-001 Not Detecting Temperature
Issue: The sensor is not detected, returning -127°C or no data.
Solutions:
- Ensure proper wiring connections and check the pull-up resistor (4.7kΩ).
- Use a multimeter to verify voltage on the VCC and DATA pins.
- Confirm the correct GPIO pin is used in the code.
🌡️ Incorrect Temperature Readings
Issue: The sensor outputs incorrect or fluctuating temperature values.
Solutions:
- Check for noise interference on the data line; use shielded cables if necessary.
- Ensure the sensor is properly powered (3.3V or 5V).
- Retry the sensor readings after resetting the microcontroller.
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
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 4
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
void setup() {
Serial.begin(115200);
sensors.begin();
}
void loop() {
sensors.requestTemperatures();
Serial.print("Temperature: ");
Serial.println(sensors.getTempCByIndex(0));
delay(2000);
}
This code initializes and reads the KY-001 sensor using the OneWire and DallasTemperature libraries.
ESP-IDF Example
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"
#include "onewire.h"
#include "ds18b20.h"
#define KY001_GPIO GPIO_NUM_4
void app_main(void) {
printf("KY-001 Sensor Test\n");
onewire_bus_handle_t bus = onewire_bus_init(KY001_GPIO);
uint8_t rom_code[8];
if (!onewire_search_first(bus, rom_code, false)) {
printf("Sensor not found\n");
return;
}
while (1) {
float temp;
ds18b20_start_conversion(bus, rom_code);
vTaskDelay(pdMS_TO_TICKS(750));
ds18b20_get_temperature(bus, rom_code, &temp);
printf("Temperature: %.2f°C\n", temp);
vTaskDelay(pdMS_TO_TICKS(2000));
}
}
This ESP-IDF code initializes the KY-001 sensor and reads the temperature every 2 seconds.
ESPHome Example
sensor:
- platform: dallas_temp
address: 0x1234567890abcdef
name: KY-001 Temperature Sensor
update_interval: 60s
ESPHome configuration for the KY-001 temperature sensor.
PlatformIO Example
platformio.ini
[env:esp32]
platform = espressif32
board = esp32dev
framework = arduino
lib_deps =
paulstoffregen/OneWire
milesburton/DallasTemperature
PlatformIO Example Code
#include <Arduino.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 4
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
void setup() {
Serial.begin(115200);
sensors.begin();
}
void loop() {
sensors.requestTemperatures();
Serial.print("Temperature: ");
Serial.println(sensors.getTempCByIndex(0));
delay(2000);
}
PlatformIO example for reading the KY-001 sensor.
MicroPython Example
import machine
import onewire
import ds18x20
import time
pin = machine.Pin(4)
ow = onewire.OneWire(pin)
ds = ds18x20.DS18X20(ow)
roms = ds.scan()
while True:
ds.convert_temp()
time.sleep(1)
for rom in roms:
print("Temperature:", ds.read_temp(rom))
time.sleep(2)
MicroPython script to read temperature from KY-001 using the DS18B20 driver.
Conclusion
The ESP32 KY-001 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.