/* DS18B20 1-Wire digital temperature sensor with 16x2 I2C LCD and Arduino example code. More info: https://www.makerguides.com */
// Include the required Arduino libraries:
#include <OneWire.h>
#include <DallasTemperature.h>
#include <LiquidCrystal_I2C.h>
// Define to which pin of the Arduino the 1-Wire bus is connected:
#define ONE_WIRE_BUS 2
const int buzzer = 9; //buzzer to arduino pin 9
// 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);
LiquidCrystal_I2C lcd(0x27, 16, 2);
// Degree symbol:
byte Degree[] = {
B00111,
B00101,
B00111,
B00000,
B00000,
B00000,
B00000,
B00000
};
void setup() {
// Start up the library:
sensors.begin();
// Start the LCD and turn on the backlight:
lcd.init();
lcd.backlight();
// Create a custom character:
lcd.createChar(0, Degree);
pinMode(buzzer, OUTPUT); // Set buzzer - pin 9 as an output
}
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
// Print the temperature on the LCD;
lcd.setCursor(0,1);
lcd.print(tempC);
lcd.write(0); // print the custom character
lcd.print("C");
// Wait 1 second:
delay(1000);
if (tempC >= 33){
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Hyperthermia");
lcd.setCursor(0,1);
lcd.print(tempC);
lcd.write(0); // print the custom character
lcd.print("C");
tone(buzzer, 1000); // Send 1KHz sound signal...
delay(1000); // ...for 1 sec
noTone(buzzer); // Stop sound...
delay(1000); // ...for 1sec
}
if (tempC <= 33){
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Normal");
lcd.setCursor(0,1);
lcd.print(tempC);
lcd.write(0); // print the custom character
lcd.print("C");
}
}