This is a little modification of our DS18B20 example, outputting via the serial monitor is great but of little practical use. In this example we will output the temperature to our LCD display.
The LCD display we use is the LCD Keypad Shield that is available for sale from various sources.
Here is our setup, you can see we are using a DS18b20 breakout board connected to the LCD and Keypad shield
Here is the temperature displayed on the LCD
Code
#include <OneWire.h>
#include <DallasTemperature.h>
#include <LiquidCrystal.h>
//DS18b20 connected to D13
#define DS18B20 13
// Connections: Sainsmart LCD/Keypad shield
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
OneWire ourWire(DS18B20);
DallasTemperature sensors(&ourWire);
void setup()
{
//Serial.begin(9600);
delay(1000);
//start reading
sensors.begin();
//setup the LCD
lcd.begin(16, 2); // start the library
lcd.setCursor(0,0);
lcd.print(“TEMPERATURE”);
}
void loop()
{
//read temperature and output via LCD
sensors.requestTemperatures();
lcd.setCursor(0,1);
lcd.print(sensors.getTempCByIndex(0));
lcd.setCursor(6,1);
lcd.print(“celsius”);
}
Links
LCD and Keypad Shield on Amazon US
LCD and keypad shield on Amazon UK