By Abdul Rehman
DS18b20 is a temperature Sensor module which works on single wire protocol. The reason to choose DS18b20 as a temperature sensor is because, we can interface many DS18b20 sensors on single wire. So we do not need extra pins for interfacing as well as we also do not need analog pins. Because ESP8266 Nodemcu module has only single analog pin, so it is not wise to use it for such sensors which could easily be replaced with the digital output like DS18b20.
According to the ds18b20 datasheet the main features of this sensor are as follows
DS18b20 is a 3 pin sensor. Two pins are for power supply and middle pin for reading the output temperature via one wire protocol. Here is the wiring diagram for DS18b20 with ESP8266 Nodemcu board.
as you can see we had used only nodemcu and ds18b20 interfacing with esp8266 module. We do not need extra hardware for viewing the code.
There are two main libraries which we use for reading the DS18b20 with esp8266. Same libraries and code is also valid for other Arduino variants. The libraries you need for this code are <DallasTemperature.h> and <OneWire.h>.
The complete code is as follows
|Here is the complete tutorial for this code|
|#define ONE_WIRE_BUS D1 //D2 pin of nodemcu|
|DallasTemperature ds18b20(&oneWire); // Pass the oneWire reference to Dallas Temperature.|
|ds18b20.requestTemperatures(); // Send the command to get temperatures|
|Serial.println(ds18b20.getTempCByIndex(0)); // Why "byIndex"? You can have more than one IC on the same bus. 0 refers to the first IC on the wire|
11 May 2021
27 April 2021
10 February 2021
03 February 2021
27 January 2021
FYP Solutions Powered By Impressive Business WordPress Theme