ESP32 DS18B20 Digital Temperature Sensor
DS18B20 Digital Temperature Sensor interfacing with ESP32 Board
Introduction
In this tutorial, we will learn how to interface the DS18B20 Sensor With the ESP32 Devkit Development Board. if you want to build a Temperature Monitoring System Using ESP32 then just follow the article. the DS18B20 Sensor Is an excellent choice for a temperature sensor.
Bill Of Material
S.N | Component's | Quantity | Link To Buy |
1 | ESP32 Board | 1 | |
2 | DS18B20 Sensor | 1 | |
3 | Zero PCB | 1 | |
4 | Wire | 5 | |
5 | Soldering wire | 1 | |
6 | Soldering Gun | 1 |
Component’s
ESP32 Board
We already used the DS18B20 Temperature Sensor in a couple of Projects Involving Arduino, ESP8266 And Raspberry Pi.DS18B20 is a digital Temperature Sensor is measures temperatures in the range of -55°c To +125°c.
Many sensors work over I2C or SPI but the DS18B20 Temperature Sensor Uses 1-wire Communication to interact with the ESP32 Board.
The DS18B20 is a digital Temperature Sensor, the temperature data is stored in the on-chip EEPROM.some important Features.
- User-configurable Resolution between 9-bits And 12-bits.
- 64-bit Serial Code is Unique to all DS18B20 Sensors.
Circuit Diagram
Now Proceed with understanding how to interface the DS18B20 Sensor with the ESP32 Board. The first thing to remember is that DS18B20 is a Digital Sensor.
That’s means for the ESP32 Board we interfacing the DS18B20 Sensor to Digital Pin D14 Pin Number. The ESP32 is to Send and Receive Data to / From DS18B20 and we need only one wire for proper Communication.
I am Powering up the DS18B20 Sensor with normal Power. So, the VCC of DS18B20 is conected to the Vin of the ESP32 Board.
NOTE: The Range of power supply for DS18B20 is 3v to 5.5v.
the GND pin is conected to the GND pin of the ESP32 Board. Finally, The DQ pin should be pulled HIGH.So,I connected a 4.7KΩ Resistor Between the DQ Pin And 3.3V.
NOTE: The Pullup voltage can be very 3v to 5.5v.
Code
Now I Write a simple code that will initialize the 1-wire communication in GPIO 14, this one wire Communicates to the DS18B20 Sensor And reads Temperature Data.
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 14 OneWire oneWire(ONE_WIRE_BUS); DallasTemperature sensors(&oneWire); void setup(void) { Serial.begin(9600); Serial.println("Dallas Temperature Sensor"); sensors.begin(); } void loop(void) { Serial.print("Requesting temperatures..."); sensors.requestTemperatures(); Serial.println("DONE"); float tempC = sensors.getTempCByIndex(0); if (tempC != DEVICE_DISCONNECTED_C) { Serial.print("Temperature :-"); Serial.println(tempC); } else { Serial.println("Could not read temperature data"); } } |
With 16×2 LCD Using I2C
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 |
#include <OneWire.h> #include <DallasTemperature.h> #include <Wire.h> #include <LiquidCrystal_I2C.h> #define DS18B20PIN 14 OneWire oneWire(DS18B20PIN); DallasTemperature sensor(&oneWire); LiquidCrystal_I2C lcd(0x27, 16, 2); byte degree_symbol[8] = { 0b00111, 0b00101, 0b00111, 0b00000, 0b00000, 0b00000, 0b00000, 0b00000 }; void setup() { sensor.begin(); lcd.init(); lcd.backlight(); lcd.createChar(0, degree_symbol); lcd.setCursor(0,0); lcd.print(" DS18B20 with "); lcd.setCursor(0,1); lcd.print(" ESP32 DevKit "); delay(2000); lcd.clear(); } void loop() { sensor.requestTemperatures(); float tempinC = sensor.getTempCByIndex(0); lcd.setCursor(0,0); lcd.print("Temp = "); lcd.print(tempinC); lcd.write(0); lcd.print("C"); delay(1000); } |
Working Project
Now you see the temperature values on the serial monitor on Arduino Ide Software
if I Provide some heat then the temperature value will change.
Video
Conclusion
In this tutorial, we interfaced the DS18B20 Temperature Sensor with the ESP32 Board and implemented it with the LCD. You learned some Information about the DS18B20 Sensor And How to interface with the ESP32 Board.
Related Posts: