#include <LiquidCrystal_I2C.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <HX711.h>
#include <Wire.h>
// Inisialisasi sensor DS18B20
#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
// Inisialisasi sensor HX711
HX711 scale;
const int LOADCELL_DOUT_PIN = 3;
const int LOADCELL_SCK_PIN = 4;
// Inisialisasi sensor ACS712
const int ACS712_PIN = A0;
// Inisialisasi LCD I2C
LiquidCrystal_I2C lcd(0x27, 16, 2);
// Inisialisasi tombol dan relay
const int BUTTON1_PIN = 5;
const int BUTTON2_PIN = 6;
const int RELAY_PIN = 7;
// Variabel untuk menyimpan data
float m, T1, V, I, T2;
unsigned long t;
void setup() {
// Inisialisasi komunikasi serial
Serial.begin(9600);
// Inisialisasi sensor suhu
sensors.begin();
// Inisialisasi load cell
scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
// Inisialisasi LCD
lcd.init();
lcd.backlight();
// Inisialisasi pin input dan output
pinMode(BUTTON1_PIN, INPUT_PULLUP);
pinMode(BUTTON2_PIN, INPUT_PULLUP);
pinMode(RELAY_PIN, OUTPUT);
// Tampilkan pesan awal
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("KALORIMETER");
lcd.setCursor(0, 1);
lcd.print("BLOK OTOMATIS");
delay(2000);
lcd.clear();
lcd.print("OLEH KELOMPOK 1");
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("HOLIS, NIA,");
lcd.setCursor(0, 1);
lcd.print("& NISA");
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Tekan 1 untuk");
lcd.setCursor(0, 1);
lcd.print("mulai");
}
void loop() {
// Menunggu tombol 1 ditekan
if (digitalRead(BUTTON1_PIN) == LOW) {
// Baca massa dan suhu
m = scale.get_units();
sensors.requestTemperatures();
T1 = sensors.getTempCByIndex(0);
// Tampilkan massa dan suhu
lcd.clear();
lcd.print("Massa: ");
lcd.print(m);
lcd.print(" kg");
lcd.setCursor(0, 1);
lcd.print("Suhu: ");
lcd.print(T1);
lcd.print(" C");
// Menunggu tombol 2 ditekan
while (digitalRead(BUTTON2_PIN) == HIGH);
// Aktifkan relay dan mulai stopwatch
digitalWrite(RELAY_PIN, HIGH);
unsigned long startTime = millis();
delay(5000); // Tunggu 5 detik
// Mulai pengukuran tegangan dan arus
V = analogRead(ACS712_PIN) * (5.0 / 1023.0);
I = V / 185.0; // Contoh konversi, sesuaikan dengan spesifikasi ACS712 Anda
// Tampilkan waktu dan besaran tegangan serta arus
lcd.clear();
lcd.print("Waktu: ");
lcd.print((millis() - startTime) / 1000);
lcd.print(" s");
lcd.setCursor(0, 1);
lcd.print("V: ");
lcd.print(V);
lcd.print(" I: ");
lcd.print(I);
// Tunggu sampai suhu naik 10 derajat
do {
sensors.requestTemperatures();
} while (sensors.getTempCByIndex(0) < T1 + 10);
// Matikan relay dan berhentikan stopwatch
digitalWrite(RELAY_PIN, LOW);
t = millis() - startTime;
// Baca suhu maksimal
T2 = sensors.getTempCByIndex(0);
// Tampilkan suhu maksimal
lcd.clear();
lcd.print("T2: ");
lcd.print(T2);
lcd.print(" C");
// Menunggu tombol 2 ditekan untuk hasil
lcd.setCursor(0, 1);
lcd.print("Hasil, tekan 2");
while (digitalRead(BUTTON2_PIN) == HIGH);
// Hitung energi, kapasitas kalor, dan kalor jenis
float Q = V * I * t / 1000; // Energi dalam kalori
float C = Q / (T2 - T1); // Kapasitas kalor
float c = C / m; // Kalor jenis
// Tampilkan hasil perhitungan
lcd.clear();
lcd.print("Q: ");
lcd.print(Q);
lcd.print(" cal");
lcd.setCursor(0, 1);
lcd.print("c: ");
lcd.print(c);
lcd.print(" cal/gC");
}
}