Alarm System

Hello everybody, and thank you for all yours replys.

I suddenly got to work.

The only then yet i installed is a doormagnet for my door, so when the door opens, the sirene goes on for like 10 secs, and then if the door is closed again, the alarm turns off.

I got 3 leds.

Red for when alarm is on.
Green for when Door is closed and everything is OK.
And a Yellow. And for the yellow i have a little question.

Yellow:
My idea is, when the alarm is on, and the door still i open, the yellow led should just be LOW. But when the door is closed and the sirene is still on (delay(10000):wink: the yellow LED should start to blink with a delay of 100 mil until the sirene is off (as it is after 10 secounds, when the door is closed), then it should be LOW- but i dont know how i can do that - i tryed for hours last day, but notin dident work :frowning:
Look at my code:

int ledPin = 13; // choose the pin for the LED
int inPin = 2;   // choose the input pin (for a pushbutton)
int val = 0;     // variable for reading the pin status
int dor = 0;
int alarmPin = 6;
int greenPin = 7;
int yellowPin = 4;
int butPin = 3;

void setup() {
  pinMode(ledPin, OUTPUT);  // declare LED as output
  pinMode(inPin, INPUT);    // declare pushbutton as input
  pinMode(alarmPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
  pinMode(yellowPin, OUTPUT);
  pinMode(butPin, INPUT);
}

void loop(){
  val = digitalRead(inPin);  // read input value
  if (val == LOW) {         // check if the input is HIGH (button released)
    digitalWrite(ledPin, LOW);  // turn LED OFF
    digitalWrite(alarmPin, LOW);
    digitalWrite(greenPin, HIGH);
    
  } else {
    digitalWrite(yellowPin, LOW);
    digitalWrite(alarmPin, HIGH);
    digitalWrite(greenPin, LOW);
    delay(150);
    digitalWrite(ledPin, HIGH);  // turn LED ON    
    
    delay(10000);
    
  }
   
    digitalWrite(yellowPin, HIGH);
    delay(200);
    digitalWrite(yellowPin, LOW);
    delay(200);
}

Can anyone tell me how to do that?.

And then i have another question :slight_smile:

  • the Arduino board is only 5v - and it wont work if i put in a 9v battery to my solderless breadboard instead of the power from the arduino board. Like the sirene needs atleast 12v (a better one i want for ths project) and some moton detectors needs more power. So how am i supposed to add like 12v power supply to the breadboard? :slight_smile:

Thank you all, and MERRY CHRISTMAS!