Skip to content

Instantly share code, notes, and snippets.

@elktros
Created February 6, 2018 11:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elktros/2265f692cdd8ee648dca6912b4c464ed to your computer and use it in GitHub Desktop.
Save elktros/2265f692cdd8ee648dca6912b4c464ed to your computer and use it in GitHub Desktop.
Code for Interfacing DS18B20 Temperature Sensor with Arduino.
#include <OneWire.h>
#include <DallasTemperature.h>
#include <LiquidCrystal.h>
#define DS18B20 8
OneWire ourWire(DS18B20);
DallasTemperature sensor(&ourWire);
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
byte degree_symbol[8] =
{
0b00111,
0b00101,
0b00111,
0b00000,
0b00000,
0b00000,
0b00000,
0b00000
};
void setup()
{
Serial.begin(9600);
delay(1000);
sensor.begin();
lcd.begin(16, 2);
lcd.createChar(1, degree_symbol);
lcd.setCursor(0,0);
lcd.print(" Digital ");
lcd.setCursor(0,1);
lcd.print(" Thermometer ");
delay(4000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Temp - ");
}
void loop()
{
sensor.requestTemperatures();
Serial.print(sensor.getTempCByIndex(0));
Serial.println("°C");
lcd.setCursor(7,0);
lcd.print(sensor.getTempCByIndex(0));
lcd.write(1);
lcd.print("C");
delay(1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment