Last active
May 28, 2024 18:06
-
-
Save AlexanderSavochkin/6045dad44130bbff80db to your computer and use it in GitHub Desktop.
Simple arduino 2-sensors (DS18B20) termometer + I2C LCD sketch
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
//I2C bus support | |
#include <Wire.h> | |
//I2C | |
#include <LiquidCrystal_I2C.h> | |
//OneWire bus suport | |
#include <OneWire.h> | |
//DS18B20 temperature sensor support | |
#include <DallasTemperature.h> | |
//DS18B20 sensor pin | |
#define ONE_WIRE_BUS 8 | |
// Setup a oneWire instance to communicate with any OneWire devices | |
// (not just Maxim/Dallas temperature ICs) | |
OneWire oneWire(ONE_WIRE_BUS); | |
// Pass our oneWire reference to Dallas Temperature. | |
DallasTemperature sensors(&oneWire); | |
LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line display | |
void setup() | |
{ | |
lcd.init(); | |
lcd.backlight(); //Turns backlight on | |
sensors.begin(); | |
} | |
void loop() | |
{ | |
sensors.requestTemperatures(); | |
//Read first sensor | |
float temp = sensors.getTempCByIndex(0); | |
//Print first sensor results | |
lcd.setCursor (0, 0 ); | |
lcd.print("T1: "); | |
lcd.print(temp); | |
lcd.print(" "); | |
//Read second sensor | |
temp = sensors.getTempCByIndex(1); | |
//Print second sensor result | |
lcd.setCursor (0, 1 ); | |
lcd.print("T2: "); | |
lcd.print(temp); | |
lcd.print(" "); | |
//Wait 0.1 sec | |
delay(100); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Excellent Alexander, thanks so much, just what I was looking for, and from a fellow Washingtonian!!!