![]() ![]() Because we’re using just one sensor its index is 0. The getTempCByIndex() and the getTempFByIndex() methods accept the index of the temperature sensor. float temperatureF = sensors.getTempFByIndex(0) Or use the getTempFByIndex() to get the temperature in Fahrenheit. Then, get the temperature in Celsius by using the getTempCByIndex() method as shown below: float temperatureC = sensors.getTempCByIndex(0) ![]() Initialize the DS18B20 temperature sensor: sensors.begin() īefore actually getting the temperature, you need to call the requestTemperatures() method. In the setup(), initialize the Serial Monitor at a baud rate of 115200. GPIO where the DS18B20 is connected to The temperature sensor is connected to GPIO 4. #include Ĭreate the instances needed for the temperature sensor. Start by including the OneWire and the DallasTemperature libraries. However, if you’re using just one single sensor, this is one of the easiest and simplest ways. There are many different ways to get the temperature from DS18B20 temperature sensors. Pass our oneWire reference to Dallas Temperature sensorįloat temperatureC = sensors.getTempCByIndex(0) įloat temperatureF = sensors.getTempFByIndex(0) Setup a oneWire instance to communicate with any OneWire devices The code reads temperature from the DS18B20 temperature sensor and displays the readings on the Arduino IDE Serial Monitor. ![]() After installing the libraries, restart your Arduino IDE.Īfter installing the required libraries, you can upload the following code to the ESP8266. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |