Hi All,
I am wanting to make an alarm for my shed.
I want it to consist of 16,2 LCD, Arduino UNO, Siren, Buzzer, 3 LED’s, A switch to Arm/Disarm (Later to be replaced with an RFID Reader, Magnetic Reed Switch on door etc.
I previously started a thread asking for help on the schematic and code but I have been working hard today working on the circuit and I think I have came up with something that will suit my needs.
I really am struggling to get my head around the coding especially loops. I just can’t seem to come with a code at all.
Basically when unit is first powered up, I want the LCD screen to say something on the top line and say “Alarm Disabled” on the bottom line. I have managed that… Just!
When the button is pressed I want a delay of 15 seconds and a beep from the buzzer every second to give me time to exit the shed. If the door isn’t closed after 15 seconds, I want the alarm to sound.
If the door is shut, I want the alarm to be armed. Once the door is opened, I want the same 15 seconds delay to press the button again to disarm the alarm.
Green LED = Alarm Disarmed
Yellow LED = Countdown
Red LED = Alarm Armed.
I have the LCD Connected to the analog pins to free up some digital pins for the future when I plan to add RFID.
I have started writing the code but I have no idea what I am doing. I am new to all this lol.
// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(A0, A1, A2, A3, A4, A5);
const int ledGreen = 2;
const int ledYellow = 3;
const int ledRed = 4;
const int setAlarm = 8;
const int buzz = 9;
int buttonState = 0;
const int reed = 5;
const int Siren = 6;
void setup() {
// set up the LCD's number of rows and columns:
lcd.begin(16, 2);
// Print a message to the LCD.
pinMode(ledGreen, OUTPUT); //Set Green LED to Output
pinMode(ledYellow, OUTPUT); //Set Green LED to Output
pinMode(ledRed, OUTPUT); //Set Green LED to Output
pinMode(setAlarm, INPUT); //Set Alarm Button as INPUT
pinMode(buzz, OUTPUT); //Set buzzer as output
pinMode(reed, INPUT);
pinMode(Siren, OUTPUT);
lcd.print("Security System!");
digitalWrite(ledGreen, HIGH);
digitalWrite(buzz, HIGH);
delay(50);
digitalWrite(buzz, LOW);
delay(50);
digitalWrite(buzz, HIGH);
delay(50);
digitalWrite(buzz, LOW);
lcd.setCursor(0,1);
lcd.print(" Alarm Disarmed");
}
void trip_reed(){
lcd.clear();
lcd.setCursor(0,0);
lcd.print(" BREACH DOOR");
digitalWrite(Siren, HIGH);
}
void exit_time(){
lcd.clear();
lcd.print("Security System!");
lcd.setCursor(0,1);
lcd.print(" Setting Alarm!");
digitalWrite(buzz, HIGH);
delay(500);
digitalWrite(buzz, LOW);
delay(500);
digitalWrite(buzz, HIGH);
delay(500);
digitalWrite(buzz, LOW);
delay(500);
digitalWrite(buzz, HIGH);
delay(500);
digitalWrite(buzz, LOW);
delay(500);
digitalWrite(buzz, HIGH);
delay(500);
digitalWrite(buzz, LOW);
delay(500);
digitalWrite(buzz, HIGH);
delay(500);
digitalWrite(buzz, LOW);
delay(500);
lcd.clear();
lcd.print("Security System!");
lcd.setCursor(0,1);
lcd.print(" Alarm Set!");
return;
}
void loop(){
// read the state of the pushbutton value:
buttonState = digitalRead(setAlarm);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED on:
exit_time();
}
else {
}
int reed = digitalRead(5);
if ( reed == LOW ){
trip_reed();
}
else {}
}
Any advice at all would be really appreciated.
Many thanks
Rob