Overview

Temperature Sensors are an integral part many systems like Automobiles, Computers, Air Conditioners, Printers, etc. They are also an important part of Home Security and Home Automation Systems. Focusing on the Home Automation part, Temperature Sensors, like DS18B20, can be used in IoT Weather Stations, which is again a combination of different sensors. Upon implementing a Weather Station, you need to monitor the data in order to take necessary actions.

Here comes the combination of ESP8266 and ThingSpeak. Using ESP8266, you can connect your Weather Station to the Internet and using ThingSpeak API, you can monitor the data from the Weather Station remotely i.e. from any Web Browser. Before implementing a complete IoT Weather Station, we will see how to Interface a DS18B20 Temperature Sensor with ESP8266 and ThingSpeak.

A Brief Note on DS18B20 Temperature Sensor

I have already shown you how to interface DS18B20 Temperature Sensor with both Arduino and Raspberry Pi. If you are interested in those projects, you can have a look: RASPBERRY PI DS18B20 TUTORIAL and ARDUINO DS18B20 INTERFACE TUTORIAL.

Coming to the sensor, DS18B20 is a Digital Thermometer which can measure temperatures in the range of -55 0C to +125 0C. The communication between the DS18B20 Sensor and the Microcontroller is through 1-Wire Communication (1-Wire Bus). The most commonly used package of the DS18B20 Temperature Sensor is TO-92 Package and its Pin Diagram is shown below.

This sensor is frequently used in thermometers, thermostats, consumer electronics and industrial control systems.

Interfacing DS18B20 Temperature Sensor with ESP8266 and ThingSpeak

In this project, I’ll interface the DS18B20 Temperature Sensor with ESP8266 WiFi Module and after obtaining the data from the sensor, I’ll post Temperature information on the ThingSpeak API. The ESP8266 Module is responsible for all the calculations and even posting the results to ThingSpeak.

Circuit Diagram

The image below shows the circuit diagram of Interfacing DS18B20 Temperature Sensor with ESP8266.

Components Required

DS18B20 Temperature Sensor ESP8266 Module Arduino 4.7 KΩ Resistor (for pull-up) 1 KΩ and 2.2 KΩ Resistors (for level converter) Connecting Wires Mini Breadboard SPDT Switch Push Button

Circuit Design

All the connections with respect to Arduino, which is being used as an USB-to-Serial Converter and ESP8266 Module are already explained several times in the previous projects. Coming to the DS18B20 Sensor, its data pin must be pulled high using a 4.7 KΩ Resistor. This data pin is connected to the GPIO2 of the ESP8266. NOTE: I have connected a 1.5 KΩ Resistor as pull-up.

Code

Following is the code for interfacing DS18B20 Temperature Sensor with ESP8266. If you observe the code, it is very similar to the one written for Interfacing DHT11 Humidity Sensor with ESP8266. Do not forget to change the SSID, Password and API Key as per your requirement. Also, make sure that you have downloaded the libraries OneWire and DallasTemperature.

Working

In this project, by Interfacing DS18B20 Temperature Sensor with ESP8266, I am extracting the temperature information from the sensor. Let me explain how this works. After making all the connection as shown in the circuit diagram, configure the ESP8266 Module in Programming Mode (by connecting GPIO0 to GND and Resetting the Module). Now, you can upload the code to the ESP8266 Module using Arduino IDE. NOTE: Select correct board and PORT in the Arduino IDE. Generic ESP8266 Module should be the Board. Once the code is uploaded, configure the ESP8266 is normal mode by sliding GPIO0 from GND and resetting the module. Open the Serial Monitor in the Arduino IDE and select the baud rate as 115200. Also, do not forget to choose “Both NL & CR” option.

In the serial monitor, you can see the ESP8266 Module getting connected to the Internet through the WiFi Network. After confirming the WiFi Connection, the ESP Module will start reading the Temperature information from the DS18B20 Sensor. This temperature information is displayed on the serial monitor. As we are also interested in monitoring the Temperature remotely, the temperature values will be uploaded to the ThingSpeak API on your channel. In order to view the results, open your ThingSpeak Channel in any web browser and in the private view tab, you can see the Temperature values being updated.

Conclusion and Applications

In the previous and this project, I have shown you interfacing two sensors i.e. DHT11 Humidity Sensor and DS18B20 Temperature Sensor with ESP8266. Also, the values (or results) from these sensors are posted in the ThingSpeak API for remote monitoring. These two sensors along with a few other sensors, can be implemented in a IoT based Weather Station Project.

  Arduino: 1.8.5 (Windows 7), Board: “Generic ESP8266 Module, 80 MHz, ck, 26 MHz, 40MHz, QIO, 512K (no SPIFFS), 2, v2 Lower Memory, Disabled, None, Only Sketch, 115200” Archiving built core (caching) in: C:\Users\LABBIO~1\AppData\Local\Temp\arduino_cache_163781\core\….. Sketch uses 262560 bytes (52%) of program storage space. Maximum is 499696 bytes. Global variables use 33516 bytes (40%) of dynamic memory, leaving 48404 bytes for local variables. Maximum is 81920 bytes. warning: espcomm_sync failed error: espcomm_open failed error: espcomm_upload_mem failed error: espcomm_upload_mem failed This report would have more information with “Show verbose output during compilation” option enabled in File -> Preferences. Please, if you know something about that i will be pleased.Thank you Comment * Name * Email * Website

Δ

DS18B20 Temperature Sensor with ESP8266 and ThingSpeak - 51DS18B20 Temperature Sensor with ESP8266 and ThingSpeak - 74DS18B20 Temperature Sensor with ESP8266 and ThingSpeak - 79DS18B20 Temperature Sensor with ESP8266 and ThingSpeak - 18DS18B20 Temperature Sensor with ESP8266 and ThingSpeak - 53DS18B20 Temperature Sensor with ESP8266 and ThingSpeak - 70DS18B20 Temperature Sensor with ESP8266 and ThingSpeak - 53DS18B20 Temperature Sensor with ESP8266 and ThingSpeak - 16DS18B20 Temperature Sensor with ESP8266 and ThingSpeak - 21DS18B20 Temperature Sensor with ESP8266 and ThingSpeak - 29DS18B20 Temperature Sensor with ESP8266 and ThingSpeak - 31DS18B20 Temperature Sensor with ESP8266 and ThingSpeak - 53