/*********
Rui Santos
Complete project details at https://randomnerdtutorials.com
Based on the Dallas Temperature Library example
*********/
/*
* The DS18B20 is a digital temperature sensor...
* manufactured by Maxim Integrated (formerly Dallas Semiconductor).
* It is one of the most popular temperature sensors on the market and provides...
* fairly high accuracy (±0.5 °C) over a large temperature range (-55 °C to + 125 °C).
* ~ https://www.makerguides.com/ds18b20-arduino-tutorial
*/
//Modified by Barbu Vulc!
//Source: https://randomnerdtutorials.com/guide-for-ds18b20-temperature-sensor-with-arduino/
#include <OneWire.h>
#include <DallasTemperature.h>
//One extra library:
#include <Arduino_FreeRTOS.h>
//Connect ds18b20 to Arduino pin D12:
#define ONE_WIRE_BUS 12
//Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);
//Pass our oneWire reference to Dallas Temperature sensor
DallasTemperature sensors(&oneWire);
//Initialization of sensor & serial communication:
void setup() {
Serial.begin(9600);
sensors.begin();
xTaskCreate(DS18B20, "ds18b20", 100, NULL, 0, NULL);
}
//Without a while loop, the program will show the results in serial monitor only once!
static void DS18B20(void* pvParameters) {
while(true){
//Call sensors.requestTemperatures() to issue a global temperature and Requests to all devices on the bus
sensors.requestTemperatures();
Serial.print("Celsius temperature: ");
//Why "byIndex"? You can have more than one IC on the same bus. 0 refers to the first IC on the wire
Serial.println(sensors.getTempCByIndex(0));
Serial.print("Fahrenheit temperature: ");
Serial.println(sensors.getTempFByIndex(0));
//The following line demark the last serial iteration from the next one!
Serial.println("-------------------------");
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
}
//No need for 'loop' function here!
void loop() {}