Skip to content

Instantly share code, notes, and snippets.

@elktros
Created March 27, 2021 13:14
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Code for ESP32 DS18B20 with I2C LCD.
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define DS18B20PIN 16
/* Create an instance of OneWire */
OneWire oneWire(DS18B20PIN);
DallasTemperature sensor(&oneWire);
LiquidCrystal_I2C lcd(0x3F, 16, 2);
byte degree_symbol[8] =
{
0b00111,
0b00101,
0b00111,
0b00000,
0b00000,
0b00000,
0b00000,
0b00000
};
void setup()
{
/* Start the DS18B20 Sensor */
sensor.begin();
lcd.init();
lcd.backlight();
lcd.createChar(0, degree_symbol);
lcd.setCursor(0,0);
lcd.print(" DS18B20 with ");
lcd.setCursor(0,1);
lcd.print(" ESP32 DevKit ");
delay(2000);
lcd.clear();
}
void loop()
{
sensor.requestTemperatures();
float tempinC = sensor.getTempCByIndex(0);
lcd.setCursor(0,0);
lcd.print("Temp = ");
lcd.print(tempinC);
lcd.write(0);
lcd.print("C");
delay(1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment