#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
int sensorPin = 0; // pin signal LDR dihubungkan ke Port Analog 0 Arduino
int ledPin = 13; // pin untuk LED
int sensorValue = 0; // variable nilai yg dihasilkan sensor
int buzzerPin = 4;
void setup()
{
pinMode(ledPin, OUTPUT);
lcd.begin(16, 2);
lcd.setCursor(3, 0); // set cursor to column 0, row 0 (the first row)
lcd.print("WARNING!!!"); // change this text to whatever you like. keep it clean.
lcd.setCursor(3, 1); // set cursor to column 0, row 0 (the first row)
lcd.print("WARNING!!!"); // change this text to whatever you like. keep it clean.
Serial.begin(9600); // untuk membaca data pada serial port di layar monitor
}
void loop()
{
sensorValue = analogRead(sensorPin); // membaca nilai dari sensor:
Serial.println(sensorValue); // menulis nilai sensor di layar monitor
if (sensorValue <= 500 ) // tentukan batas intensitas cahaya 0 - 1024
{
lcd.display();
digitalWrite(ledPin, HIGH); // menyalakan lampu LED (on)
tone(buzzerPin, 600);
delay(500);
tone(buzzerPin, 500);
delay(500);
}
else
{
lcd.noDisplay();
digitalWrite(ledPin, LOW); // mematikan lampu LED (off)
noTone(buzzerPin);
}
}