/* DS18B20 1-Wire digital temperature sensor with Arduino example code. More info: https://www.makerguides.com */
// Include the required Arduino libraries:
#include "OneWire.h"
#include "DallasTemperature.h"
#include <LiquidCrystal.h>
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
// Define to which pin of the Arduino the 1-Wire bus is connected:
#define ONE_WIRE_BUS 8
// Create a new instance of the oneWire class to communicate with any OneWire device:
OneWire oneWire(ONE_WIRE_BUS);
// Pass the oneWire reference to DallasTemperature library:
DallasTemperature sensors(&oneWire);
void setup() {
// Begin serial communication at a baud rate of 9600:
Serial.begin(9600);
// Start up the library:
sensors.begin();
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("body temperature");
lcd.setCursor(0, 1);
lcd.print("measurement");
delay(3000);
lcd.setCursor(0, 0);
lcd.print(" ");
lcd.setCursor(0, 1);
lcd.print(" ");
delay(3000);
}
void loop() {
// Send the command for all devices on the bus to perform a temperature conversion:
sensors.requestTemperatures();
// Fetch the temperature in degrees Celsius for device index:
float tempC = sensors.getTempCByIndex(0); // the index 0 refers to the first device
// Fetch the temperature in degrees Fahrenheit for device index:
float tempF = sensors.getTempFByIndex(0);
// Print the temperature in Celsius in the Serial Monitor:
Serial.print("Temperature: ");
Serial.print(tempC);
Serial.print(" \xC2\xB0"); // shows degree symbol
Serial.print("C | ");
lcd.setCursor(0, 0);
lcd.print("temp:");
lcd.print(tempC);
lcd.print(" ");
lcd.print("C");
// Print the temperature in Fahrenheit
Serial.print(tempF);
Serial.print(" \xC2\xB0"); // shows degree symbol
Serial.println("F");
lcd.setCursor(0, 10);
lcd.print("temp:");
lcd.print(tempF);
lcd.print(" ");
lcd.print("F");
// Wait 1 second:
delay(10);
}