In this article, we connect an KY-001 Temperature sensor to an Arduino Uno
The Temperature Sensor is actually a DS18B20 digital thermometer
The DS18B20 digital thermometer provides 9-bit to 12-bit Celsius temperature measurements and has an alarm function with nonvolatile user-programmable upper and lower trigger points. The DS18B20 communicates over a 1-Wire bus that by definition requires only one data line (and ground) for communication with a central microprocessor. In addition, the DS18B20 can derive power directly from the data line (“parasite power”), eliminating the need for an external power supply.
Each DS18B20 has a unique 64-bit serial code, which allows multiple DS18B20s to function on the same 1-Wire bus. Thus, it is simple to use one microprocessor to control many DS18B20s distributed over a large area. Applications that can benefit from this feature include HVAC environmental controls, temperature monitoring systems inside buildings, equipment, or machinery, and process monitoring and control systems.
- Unique 1-Wire® Interface Requires Only One Port Pin for Communication
- Reduce Component Count with Integrated Temperature Sensor and EEPROM
- Measures Temperatures from -55°C to +125°C (-67°F to +257°F)
- ±0.5°C Accuracy from -10°C to +85°C
- Programmable Resolution from 9 Bits to 12 Bits
- No External Components Required
- Parasitic Power Mode Requires Only 2 Pins for Operation (DQ and GND)
- Simplifies Distributed Temperature-Sensing Applications with Multidrop Capability
- Each Device Has a Unique 64-Bit Serial Code Stored in On-Board ROM
Here is the sensor
Parts Required
You can connect to the module using dupont style jumper wire.
This should work with other Arduino board – I have tried an Uno and Mega
Name | Link | |
Arduino Uno | ||
37 in one sensor kit | ||
Connecting cables |
Schematic/Connection
ARDUINO | SENSOR |
---|---|
Pin 3 | S |
+ | middle pin |
GND | GND |
Code Example
You will need the One Wire library and the Dallas Temperature control library – you can add these via the Arduino IDE. Links are also underneath
#include <OneWire.h> #include <DallasTemperature.h> // input pin is declared to which the sensor module is connected #define DS18b20 3 // Libraries are configured OneWire oneWire(DS18b20); DallasTemperature sensors(&oneWire); void setup() { // Initialize serial output Serial.begin(9600); Serial.println("KY-001 temperature measurement"); // Sensor is initialized sensors.begin(); } //main program loop void loop() { // Temperature measurement is started... sensors.requestTemperatures(); // ... and output measured temperature Serial.print("Temperature: "); Serial.print(sensors.getTempCByIndex(0)); Serial.println(" °C"); delay(1000); // 1s pause until next measurement }
Serial Monitor Output
I was holding the sensor to get a variation in readings
Links
Dallas Temperature Control Library