Created
September 21, 2023 07:57
-
-
Save kakopappa/1df07c1d2eeb8e61d24a20aa95c68f5f to your computer and use it in GitHub Desktop.
DS18B20
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#if defined(ESP8266) | |
#define DS18B20_PIN D5 | |
#elif defined(ESP32) | |
#define DS18B20_PIN 16 | |
#endif | |
#include <OneWire.h> | |
#include <DallasTemperature.h> // Supports DS18B20 or DS1822, DS1820, MAX31820, MAX31850 | |
OneWire oneWire(DS18B20_PIN); | |
DallasTemperature sensors(&oneWire); | |
void setup() { | |
Serial.begin(115200); | |
Serial.print("DallasTemperature Library version: "); | |
Serial.println(DALLASTEMPLIBVERSION); | |
sensors.begin(); | |
} | |
void loop() { | |
sensors.requestTemperatures(); | |
float temperatureC = sensors.getTempCByIndex(0); | |
float temperatureF = sensors.getTempFByIndex(0); | |
Serial.print(temperatureC); | |
Serial.println("C"); | |
Serial.print(temperatureF); | |
Serial.println("F"); | |
delay(2000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment