Introduction
The DS18B20 sensor is a popular and versatile digital temperature sensor widely used in various industries and applications. It’s an excellent choice for temperature monitoring and control systems. This article aims to provide a proper overview of the DS18B20 sensor, including its features, working principles, advantages, and applications.
Principle of operation
The DS18B20 sensor relies on the principles of temperature-dependent voltage changes in a semiconductor material to measure temperature accurately.
It utilizes a digital temperature sensor called a Dallas Semiconductor Thermochron®, which incorporates a bandgap temperature sensor and a 12-bit analog-to-digital converter.
Inside the sensor, the bandgap temperature sensor produces a voltage proportional to the temperature, which is then converted into a digital signal by the analog-to-digital converter. The digital data is subsequently transmitted serially using the 1-Wire protocol.
Specifications of the DS18B20 Sensor
- Digital Interface: 1-Wire protocol, enabling multiple sensors to be connected to a single data line.
- High Accuracy: -55°C to +125°C high level of accuracy.
- Unique Addressing: 64-bit ROM code, individual addressing when multiple sensors are employed.
- Programmable Resolution: The sensor allows users to adjust the resolution of temperature measurements between 9 and 12 bits.
- Low Power Consumption: low power requirements, making it suitable for battery-powered applications.
Advantages of the DS18B20 Sensor
- High Accuracy: Ensuring reliable data for critical applications.
- Easy Integration: The DS18B20 is easy to integrate into various systems.
- Wide Temperature Range: Making it suitable for both extreme and ambient temperature monitoring.
- Multiple Sensor Support: The 1-Wire protocol enables the connection of multiple DS18B20 sensors to a single data line.
- Low Cost: Making it a cost-effective choice for temperature-sensing applications.
Disadvantages of the DS18B20 Sensor
- Limited Measurement Range: -55°C to +125°C. This range is suitable for many applications, but it is not sufficient for certain specialized environments where temperatures exceed.
Applications of the DS18B20 Sensor
- HVAC Systems
- Industrial Monitoring
- Environmental Monitoring
- Medical and Laboratory Equipment
- Consumer Electronics
Example With Arduino
Now we just interface the DS18B20 Sensor with Arduino and first, we take the reading in the serial monitor and then we display the reading in a 16×2 LCD Display.
Circuit Diagram
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
#include <OneWire.h> #include <DallasTemperature.h> #define ONE_WIRE_BUS 2 OneWire oneWire(ONE_WIRE_BUS); DallasTemperature sensors(&oneWire); void setup(void) { sensors.begin(); Serial.begin(9600); } void loop(void) { sensors.requestTemperatures(); Serial.print("Temperature: "); Serial.print(sensors.getTempCByIndex(0)); Serial.print((char)176); Serial.print("C | "); Serial.print((sensors.getTempCByIndex(0) * 9.0) / 5.0 + 32.0); Serial.print((char)176); Serial.println("F"); delay(500); } |
Code With 16×2 LCD Display
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
#include <OneWire.h> #include <Wire.h> #include <LiquidCrystal.h> LiquidCrystal lcd(12,11,10,9,8,7); OneWire ds(2); void setup() { lcd.begin(16, 2); lcd.clear(); lcd.print("Temperature....."); delay(3000); lcd.clear(); lcd.print("Starting....."); delay(3000); } void loop() { byte i; byte present = 0; byte type_s; byte data[12]; byte addr[8]; float celsius, fahrenheit; if ( !ds.search(addr)) { ds.reset_search(); delay(250); return; } for ( i = 0; i < 8; i++) { } if (OneWire::crc8(addr, 7) != addr[7]) { return; } switch (addr[0]) { case 0x10: type_s = 1; break; case 0x28: type_s = 0; break; case 0x22: type_s = 0; break; default: return; } ds.reset(); ds.select(addr); ds.write(0x44, 1); delay(1000); present = ds.reset(); ds.select(addr); ds.write(0xBE); for ( i = 0; i < 9; i++) { data[i] = ds.read(); } int16_t raw = (data[1] << 8) | data[0]; if (type_s) { raw = raw << 3; if (data[7] == 0x10) { raw = (raw & 0xFFF0) + 12 - data[6]; } } else { byte cfg = (data[4] & 0x60); if (cfg == 0x00) raw = raw & ~7; else if (cfg == 0x20) raw = raw & ~3; else if (cfg == 0x40) raw = raw & ~1; } celsius = (float)raw / 16.0; fahrenheit = celsius * 1.8 + 32.0; lcd.clear(); delay(500); lcd.setCursor(0, 0); lcd.print(" Tempature :- "); lcd.setCursor(0, 1); lcd.print(celsius); lcd.print(" C"); lcd.setCursor(9, 1); lcd.print(fahrenheit); lcd.print(" F"); delay(10000); } |
Code With Led, Buzzer And 16×2 LCD Display
Here The DS18B20 Sensor is connected to the Analog Pin (A0) And Led is connected to the 5,4 and the buzzer is connected to pin number 3.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
#include <LiquidCrystal.h> LiquidCrystal lcd(12, 11, 10, 9, 8, 7); #define DS18B20_PIN A0 #define green 5 #define red 4 #define buzzer 3 int raw_temp; float temp_c, temp_f; void setup() { pinMode(red, OUTPUT); pinMode(green, OUTPUT); pinMode(buzzer, OUTPUT); lcd.begin(16, 2); lcd.clear(); lcd.setCursor(0, 0); lcd.print(" Welcome To "); lcd.setCursor(0, 1); lcd.print(" DS18B20 Sensor "); delay(2000); lcd.clear(); } void loop() { lcd.setCursor(0, 0); lcd.print(" Temperature "); if (ds18b20_read(&raw_temp)) { temp_c = (float)raw_temp / 16; temp_f = (temp_c * 9.0) / 5.0 + 32.0; lcd.setCursor(0, 1); lcd.print(temp_c, 1); lcd.write(0xdf); // to display ° lcd.print("C "); lcd.setCursor(9, 1); lcd.print(temp_f, 1); lcd.write(0xdf); lcd.print("F "); } else { lcd.setCursor(0, 1); lcd.print(" Error! "); } if (temp_f > 100) { digitalWrite(buzzer, HIGH); digitalWrite(green, LOW); digitalWrite(red, HIGH); delay(300); } else { digitalWrite(green, HIGH); digitalWrite(red, LOW); } digitalWrite(buzzer, LOW); delay(500); } bool ds18b20_start() { bool ret = 0; digitalWrite(DS18B20_PIN, LOW); pinMode(DS18B20_PIN, OUTPUT); delayMicroseconds(500); pinMode(DS18B20_PIN, INPUT); delayMicroseconds(100); if (!digitalRead(DS18B20_PIN)) { ret = 1; delayMicroseconds(400); } return (ret); } void ds18b20_write_bit(bool value) { digitalWrite(DS18B20_PIN, LOW); pinMode(DS18B20_PIN, OUTPUT); delayMicroseconds(2); digitalWrite(DS18B20_PIN, value); delayMicroseconds(80); pinMode(DS18B20_PIN, INPUT); delayMicroseconds(2); } void ds18b20_write_byte(byte value) { byte i; for (i = 0; i < 8; i++) ds18b20_write_bit(bitRead(value, i)); } bool ds18b20_read_bit(void) { bool value; digitalWrite(DS18B20_PIN, LOW); pinMode(DS18B20_PIN, OUTPUT); delayMicroseconds(2); pinMode(DS18B20_PIN, INPUT); delayMicroseconds(5); value = digitalRead(DS18B20_PIN); delayMicroseconds(100); return value; } byte ds18b20_read_byte(void) { byte i, value; for (i = 0; i < 8; i++) bitWrite(value, i, ds18b20_read_bit()); return value; } bool ds18b20_read(int *raw_temp_value) { if (!ds18b20_start()) return (0); ds18b20_write_byte(0xCC); ds18b20_write_byte(0x44); while (ds18b20_read_byte() == 0) ; if (!ds18b20_start()) return (0); ds18b20_write_byte(0xCC); ds18b20_write_byte(0xBE); *raw_temp_value = ds18b20_read_byte(); *raw_temp_value |= (unsigned int)(ds18b20_read_byte() << 8); return (1); } |
Video
Conclusion
The DS18B20 sensor offers an ideal balance of accuracy, simplicity, and versatility for temperature sensing applications. Its digital interface, high accuracy, and wide temperature range make it a popular choice across various industries. Whether in HVAC systems, industrial monitoring, or consumer electronics, the DS18B20 sensor continues to play a vital role in temperature measurement and control, contributing to improved efficiency and reliability in countless applications.
Sensor