Skip to content

Instantly share code, notes, and snippets.

@AlexanderSavochkin
Last active May 28, 2024 18:06
Show Gist options
  • Save AlexanderSavochkin/6045dad44130bbff80db to your computer and use it in GitHub Desktop.
Save AlexanderSavochkin/6045dad44130bbff80db to your computer and use it in GitHub Desktop.
Simple arduino 2-sensors (DS18B20) termometer + I2C LCD sketch
//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);
}
@Denrr
Copy link

Denrr commented Dec 9, 2016

As the sensors are connected to the Arduino, I shows the temperature of only one

@DAVESELECTRONICS
Copy link

hello ,im new to this whole ardunio system, but after I copied and pasted your code.i tried to compile it,
it came back with the error : c:\users\hp notebook\documents\ardunio\libraries\liquidcrystal_i2c.cpp:3:23: fatal error: wprogram.h: no such file or directory
#include "wprogram.h" compilation terminated.
exit status 1
error compiling for board ardunio/genuine uno.
if anyone has any idea on what I can do please respond thanks in advance to everyone.

@NST-Don
Copy link

NST-Don commented Aug 21, 2017

Excellent Alexander, thanks so much, just what I was looking for, and from a fellow Washingtonian!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment