/*****
Proyek Arduino dengan Simulator Wokwi
Judul : Sensor Suhu dengan DS 18B20 dan LCD I2C
Deskripsi : Mengukur suhu rungan dengan sensor DS18B20 yang
ditampilkan pada LCD I2C
Dimodifikasi oleh : Yosep Prasetya Budi
Terakhir diedit : 27-08-2024 15:05
*****/
/* DS18B20 1-Wire digital temperature sensor with
Arduino example code. More info: https://www.makerguides.com */
#include <LiquidCrystal_I2C.h>
#define I2C_ADDR 0x27
#define LCD_COLUMNS 20
#define LCD_LINES 4
#include "OneWire.h"
#include "DallasTemperature.h"
// Define to which pin of the Arduino the 1-Wire bus is connected:
#define ONE_WIRE_BUS 7
// initialize the library with the numbers of the interface pins
LiquidCrystal_I2C lcd(I2C_ADDR, LCD_COLUMNS, LCD_LINES);
// 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();
// set up the LCD's number of rows and columns:
lcd.begin(16, 2);
lcd.clear(); // start with a blank screen
lcd.setCursor(0,0); // set cursor to column 0, row 0 (the first row)
lcd.print("ELECTRICAL GEN Z"); // change this text to whatever you like. keep it clean.
lcd.setCursor(0,1); // set cursor to column 0, row 1
lcd.print("SMKN KRANGPUCUNG");
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 | ");
// Print the temperature in Fahrenheit
Serial.print(tempF);
Serial.print(" \xC2\xB0"); // shows degree symbol
Serial.println("F");
// Print temperatur di LCD
lcd.setCursor(0,1); // set cursor to column 0, row 1
lcd.print("Temp : ");
lcd.setCursor(7,1); // set cursor to column 7, row 1
lcd.print(tempC);
lcd.setCursor(12,1); // set cursor to column 7, row 1
lcd.print(" \337C "); // shows degree symbol dan C
// Wait 1 second:
delay(1000);
}Loading
ds18b20
ds18b20