Created
March 27, 2021 13:14
-
-
Save elktros/bfa206f3e40935e74f88ca0465c63216 to your computer and use it in GitHub Desktop.
Code for ESP32 DS18B20 with I2C LCD.
This file contains 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
#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