Sistem Pemantau Arduino Uno — Arduino Uno simulation

Sistem pemantau dengan LCD, Buzzer, Keypad, dan sensor PIR/DHT11.

An interactive Arduino Uno circuit simulation you can run free in your browser on Velxio, by s160425043.

Components

Sketch code

#include <Wire.h> 
#include <LiquidCrystal_I2C.h>
#include <DHT.h>
#include <Keypad.h>

// Inisialisasi LCD I2C (Alamat 0x27, 16 kolom, 2 baris)
LiquidCrystal_I2C lcd(0x27, 16, 2);

// Sensor Suhu (Pin SIG ke Pin 3)
#define DHTPIN 3
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);

// Konfigurasi Pin Komponen
const int PIR_PIN = 2;       // Sensor PIR
const int BUZZER_PIN = 4;    // Buzzer
const int LED_GREEN = 5;     // LED Hijau
const int LED_RED = 6;       // LED Merah

// Konfigurasi Keypad 4x4
const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};
byte rowPins[ROWS] = {7, 8, 9, 10};
byte colPins[COLS] = {11, 12, A0, 1};
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);

bool systemArmed = true; 

void setup() {
  lcd.init();          // Inisialisasi LCD I2C
  lcd.backlight();     // Menyalakan lampu latar
  dht.begin();
  
  pinMode(PIR_PIN, INPUT);
  pinMode(BUZZER_PIN, OUTPUT);
  pinMode(LED_GREEN, OUTPUT);
  pinMode(LED_RED, OUTPUT);
  
  lcd.setCursor(0, 0);
  lcd.print("Sistem Keamanan");
  lcd.setCursor(0, 1);
  lcd.print("Rumah Aktif...");
  delay(2000);
  lcd.clear();
}

void loop() {
  char key = keypad.getKey();
  if (key == '*') {
    systemArmed = !systemArmed;
    lcd.clear();
    if (systemArmed) {
      lcd.print("Sistem: ARMED");
    } else {
      lcd.print("Sistem: DISARMED");
      digitalWrite(BUZZER_PIN, LOW);
      digitalWrite(LED_RED, LOW);
    }
    delay(1000);
    lcd.clear();
  }

  float temp = dht.readTemperature();
  int motion = digitalRead(PIR_PIN);

  lcd.setCursor(0, 0);
  lcd.print("Suhu: ");
  if (isnan(temp)) {
    lcd.print("Error ");
  } else {
    lcd.print(temp, 1);
    lcd.print((char)223); 
    lcd.print("C  ");
  }

  if (!isnan(temp) && temp > 35.0) { 
    lcd.setCursor(0, 1);
    lcd.print("BAHAYA: FIRE!   ");
    digitalWrite(LED_RED, HIGH);
    digitalWrite(LED_GREEN, LOW);
    tone(BUZZER_PIN, 1000); // Menggunakan tone agar bunyi nyaring
  } 
  else if (systemArmed && motion == HIGH) { 
    lcd.setCursor(0, 1);
    lcd.print("AMARAN: PENYUSUP");
    digitalWrite(LED_RED, HIGH);
    digitalWrite(LED_GREEN, LOW);
    tone(BUZZER_PIN, 500);
  } 
  else {
    lcd.setCursor(0, 1);
    if (systemArmed) {
      lcd.print("Status: AMAN    ");
    } else {
      lcd.print("Status: NON-AKTIF");
    }
    digitalWrite(LED_RED, LOW);
    digitalWrite(LED_GREEN, HIGH);
    noTone(BUZZER_PIN); // Mematikan buzzer
  }

  delay(200);
}

More projects by s160425043