#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Define PIR pin
#define PIRPIN 7
// Define LED pin
#define LEDPIN 13
// Define buzzer pin
#define BUZZERPIN 13 // Assuming buzzer is connected to pin 13
// Define LCD address
#define LCD_ADDRESS 0x27
// Initialize LCD library
LiquidCrystal_I2C lcd(LCD_ADDRESS, 16, 2);
// Simulated temperature variable (replace with actual reading if possible)
float temperature = 23.5; // Replace with a sensor reading if available
void setup() {
// Initialize serial communication
Serial.begin(9600);
// Initialize LCD
lcd.init();
lcd.backlight();
}
void loop() {
// Check if temperature is below 16°C or above 25°C
if (temperature < 16 || temperature > 25) {
// Turn on buzzer
tone(BUZZERPIN, 1000);
// Display message on LCD
lcd.setCursor(0, 0);
lcd.print("Suhu ");
if (temperature < 16) {
lcd.print("di Bawah");
} else {
lcd.print("Di Atas");
}
lcd.print(" Rata-Rata");
lcd.setCursor(0, 1);
lcd.print(temperature);
lcd.print("°C");
// Wait for 2 seconds
delay(2000);
// Turn off buzzer
noTone(BUZZERPIN);
// Clear LCD display
lcd.clear();
}
// Read PIR sensor value
int pirValue = digitalRead(PIRPIN);
// Check if motion is detected
if (pirValue == HIGH) {
// Turn on LED
digitalWrite(LEDPIN, HIGH);
// Display message on LCD
lcd.setCursor(0, 1);
lcd.print("Gerakan Terdeteksi");
// Wait for 2 seconds
delay(2000);
// Turn off LED
digitalWrite(LEDPIN, LOW);
// Clear LCD display (second row)
lcd.setCursor(0, 1);
for (int i = 0; i < 16; i++) {
lcd.print(" ");
}
}
// Display author name on LCD (scrolling from left to right)
lcd.setCursor(0, 0);
String authorName = "Andra Matarisman";
for (int i = 0; i < authorName.length(); i++) {
lcd.print(authorName[i]);
delay(50);
for (int j = 0; j < i; j++) {
lcd.print(" ");
}
}
// Delay for 1 second
delay(1000);
}