Hey, what's up, Guys! Akarsh here from CETech.
Today we are going to add a new Sensor to our arsenal known as DS18B20 Temperature Sensor. It is a temperature sensor similar to DHT11 but has a different set of applications. We will be comparing it with different types of temperature sensors available and will have a look at the technical specifications of these sensors.
Towards the end of this tutorial, we will be interfacing DS18B20 with Arduino and ESP8266 to display temperature. In the case of Arduino, the temperature will be displayed on Serial Monitor and for ESP8266 we will be displaying the temperature on a web server.
Let us start with the fun now.Get PCBs for Your Project Manufactured
You must check OurPCB to get PCB's for your project manufactured online.
They use reliable components sourced from accredited suppliers such as Arrow, Avnet, Future Electronics, etc. and offer reasonable prices ultimately maximizing the user's profit margins. Specialized in multilayer and Rigid-flex Technology their priority is to maintain high-quality standards.
OurPCB focuses on small to medium volume orders and provides a very competitive price for the volume from 1-100 sq. meters. You just need to upload your files in either of the available formats(Gerber,.pcb,.pcbdoc, or.cam) and the PCB prototypes will be delivered to your doorstep.
You can also check out their partner WellPCB for good deals.Comparison Between Different Types of Temperature Sensors
The comparison shown above has three sensors DS18B20, DHT11, and NTC Thermistor but here we will limit our comparison to digital sensors only. It does not mean that the NTC thermistor is not as important as digital sensors In fact, the development of digital sensors is only possible because of NTC Thermistor. The digital sensors consist of NTC Thermistor connected with some microprocessors which ultimately gives the digital output.
Main points of the comparison are:-
1. DS18B20 is waterproof and robust while DHT11 is not that's why in real-life scenarios and applications where contact-based sensing is required, DS18B20 is generally used while DHT11 is used in the open-air environment applications.
2. DS18B20 spits out a data of 9-12 bits of data while DHT11 gives out a data of 8 bits.
3. DS18B20 gives temperature only while DHT11 can be used to obtain temperature as well as humidity.
4. DS18B20 covers a wider temperature range in comparison to the DHT11 and also has better accuracy in comparison to the DHT(+ 0.5 degrees in comparison to + 2 degrees for DHT11).
5. When it comes to pricing these sensors have a little difference in between them as the two different variants of DS18B20 which are packaged wire type and TO92 package have a cost around $1 and $0.4 while the DHT11 has a cost of around $0.6.
So we can say that DS18B20 is somewhat better than the DHT11 but a better selection can be made only on the basis of the application for which sensor is required.
You can get more knowledge about the DS18B20 by reading its datasheet from here.Connecting DS18B20 With Arduino
Here we will be connecting the DS18B20 temperature sensor with Arduino in order to obtain temperature and display it on the Serial monitor.
For this step we require- Arduino UNO, DS18B20 Temperature sensor(Packaged type or TO92 package whatever is available) and 4.7kohm resistor
DS18B20 sensor has 3 wires which are black, red, and yellow. Black one is for GND, Red one is for Vcc while the yellow one is the signal pin
1. Connect the GND pin or the black wire of the sensor to the GND.
2. Connect the Vcc pin or the Red wire of the sensor to the 5V supply.
3. Connect the signal pin or the yellow wire to the 5V through a 4.7kohm resistor and also connect this signal pin to the Digital Pin no-12 of Arduino.
You can refer to the schematic shown above for a better understanding.Coding the Arduino to Display Temperature
In this step, we will be coding our Arduino board to obtain and display temperature over Serial Monitor.
1. Connect the Arduino UNO board to the PC.
2. Move on to the Github repository for this project from here.
3. In the GitHub repository, you will see a file named "Basic code" open that file copy the code and paste it in your Arduino IDE.
4. Select the correct board and COM Port under the Tools tab and hit the upload button.
5. After the code gets uploaded, Open Serial Monitor and select the correct baud rate (9600 In our case) and you will be able to see the temperature sensed by the DS18B20 there.
You can watch the temperature rise and fall by doing suitable things to raise the temperature or settle it down such as rubbing the metallic part or burning a lighter near the metallic part of the packaged type sensor.Connecting DS18B20 With ESP8266
In this step, we will be connecting DS18B20 with the ESP8266 module to obtain the temperature.
For this step we need= ESP8266 module, 4.7kohm resistor and DS18B20 temperature sensor(Packaged type or TO92 package whatever is available).
Connections for this step are similar to the connections made with Arduino.
1. Connect the GND pin or the black wire of the sensor to the GND.
2. Connect the Vcc pin or the Red wire of the sensor to the 3.3V supply.
3. Connect the signal pin or the yellow wire to the 3.3V through a 4.7kohm resistor and also connect this signal pin to the GPIO12 which is D5 pin of the module.
You can refer to the schematic shown above for a better understanding.Setup the Arduino IDE
For coding the ESP8266 using Arduino IDE we need to install the ESP8266 board in the additional boards of the Arduino IDE as they are not preinstalled. For this purpose we need to follow the steps mentioned below:-
1. Go to File > Preferences
2. Add http://arduino.esp8266.com/stable/package_esp8266com_index.json to the Additional Boards Manager URLs.
3. Go to Tools > Board > Boards Manager
4. Search for esp8266 and then install the board.
5. Restart the IDE.Coding the ESP8266 to Display Temperature
In this step, we are going to code ESP8266 to read the temperature and after that, instead of displaying that temperature on the serial monitor, we are going to display it on a web server.
1. Move to Github repository for this project from here.
2. In the Repository, you will see a code with the name "ESP8266 Temperature Web Server" you just need to copy that code and paste it in the Arduino IDE.
3. After pasting the code change the SSID and Password in the code to that of your Wifi network.
4. Under the Tools tab select the correct board and COM port and after that hit the upload button.
5. When the code gets uploaded open the serial monitor of the IDE and then press the refresh button on the ESP8266 module you will get some unknown language written there and below that, an IP address will be present. You need to copy that IP address as it is the address of the webserver which will display the temperature.And It's done
When the code gets uploaded and the IP address is obtained. Open the webserver by using that IP address
On the webserver, there will be temperature readings displayed in degrees Celcius as well as degrees Fahrenheit.
Apart from the webserver, the temperature readings can also be observed on the serial monitor.
You will observe that as the temperature near the sensor changes the readings on the webserver also changes.
That's it for the demonstration.