Skip to content

Instantly share code, notes, and snippets.

@elktros
Created March 27, 2021 13:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elktros/9ce440f6ce1ce53574044f566f122351 to your computer and use it in GitHub Desktop.
Save elktros/9ce440f6ce1ce53574044f566f122351 to your computer and use it in GitHub Desktop.
Code for ESP32 DS18B20 Interface with results on Serial.
#include <OneWire.h>
#include <DallasTemperature.h>
#define DS18B20PIN 16
/* Create an instance of OneWire */
OneWire oneWire(DS18B20PIN);
DallasTemperature sensor(&oneWire);
void setup()
{
Serial.begin(115200);
/* Start the DS18B20 Sensor */
sensor.begin();
}
void loop()
{
sensor.requestTemperatures();
float tempinC = sensor.getTempCByIndex(0);
Serial.print("Temperature = ");
Serial.print(tempinC);
Serial.println("ºC");
delay(3000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment