Cant Figure Out Error - First Time Programmer

I am new to the Audrino world - just purchased my first board - a UNO - and writing a program for an alarm system in my workshop which is a separate building a few hundred feet from out house. Have been broken into twice over the last 10 years and many of my tools stolen. I am installing cameras along with magnetic switches on all doors and motion alarms in several areas.

I have wanted to try using an Audrino board for a while and figured this would be a good project to start with. I want to use an Audrino UNO to activate flashing lights and a siren in various configurations depending how long the alarm continues.

The following code is my first attempt at writing Audrino code. After running verify/compile several times and cleaning up some typos and minor coding errors I am stuck on an error in the lat line of the code. I keep getting an error "expected '}' at end of input. I tired many variations of the last line and use of brackets but no luck. FYI the intent of the last line is to hold the program indefinitely (do nothing) at this point till the alarm input goes to LOW.

Appreciate any help or suggestions, thanks Gary

int RedLite = 4;
int Siren = 7;
int Level1 = 8;
int Alarm = 2;

void setup() {
// put your setup code here, to run once:
pinMode(RedLite, OUTPUT);
pinMode(Siren, OUTPUT);
pinMode (Level1, OUTPUT);
pinMode(Alarm, INPUT);
}

void loop() {
// put your main code here, to run repeatedly:

// Level 1 Alarm - Flashing Red lights for 15 seconds

if (digitalRead(Alarm) == HIGH) { //Check if Alarm is activate or this will
//be false and not run }

{ for (int x = 0; x < 15; x++) //Repeat 15 times

digitalWrite(RedLite, HIGH); //Blink Red Lights on
delay(500); //for 500ms
digitalWrite(RedLite, LOW); //Blink Red Lights off
delay(500); //for 500ms
digitalWrite (Level1, HIGH); //Set Level1 Alarm to be used in Level2
delay(10);
}

//Level 2 Alarm - Flashing Red Lights and Siren doe 3 minutes

if (digitalRead(Alarm) == HIGH && digitalRead(Level1) == HIGH) {
//Check if alarm is active and Level1 was on
//or else this loop will be false and will not run
for (int y = 0; y < 360; y++){ //Repeat 360 times
digitalWrite(Siren, HIGH); //Turn on Siren
digitalWrite(RedLite, HIGH); //Blink Red Lights on
delay(250); //for 250ms
digitalWrite(RedLite, LOW); //Blink Red Lights off
delay(250); } //for 250ms
}

//Level 3 Alarm - Solid Red Lights for 46 Minutes

if (digitalRead(Siren) == HIGH) { //Check is Siren on to confirm Level2 was on
//or else this loop will be false and not run
digitalWrite(Siren, LOW); //Turn off Siren
digitalWrite(RedLite, HIGH); //turn Red Lights on solid
delay(10000000); //delay for 46 minutes
digitalWrite(RedLite, HIGH); //Turn Red lights off
digitalWrite(Level1, LOW); //Turn Level1 Status off
}

if (digitalRead(Alarm) == HIGH) { //Do nothing as long as Alarm stays High
}

  if (digitalRead(Alarm) == HIGH) {    //Do nothing as long as Alarm stays High
}

}   // missing

Thank a lot - that was easy to fix - I thought I had tried adding the extra bracket at the end before but when I did it now it completed compiling with no problem

thanks again

You have these lines:

pinMode(Alarm, INPUT);
...
... 
 if (digitalRead(Alarm) == HIGH) {      //Check if Alarm is activate

... which indicates that the alarm sensor is wired from the pin to 5V. Do you have a pull down resistor to ensure it doesn't accidentally go high due to atmospherics or phases of the moon and give false alarms?

A better approach is to wire the sensor from pin to ground, use the internal pullup, and change the logic:

pinMode(Alarm, INPUT_PULLUP);
...
... 
 if (digitalRead(Alarm) == LOW) {      //Check if Alarm is activate

Next stop blink without delay and state machines :wink:

Just to satisfy my curiosity, is the idea that if Alarm goes high, the red lite blinks, and when the blinks are complete AND Alarm is still high, the siren sounds, with more blinking? Then when the siren is complete, regardless of Alarm being high or low, the red lite goes on for 46 minutes?

I suspect you want more than"digitalWrite(RedLite, HIGH);" to repeat 15 times:

    {
      for (int x = 0; x < 15; x++)         //Repeat 15 times
        digitalWrite(RedLite, HIGH);          //Blink Red Lights on


      delay(500);                           //for 500ms
      digitalWrite(RedLite, LOW);           //Blink Red Lights off
      delay(500);                           //for 500ms
      digitalWrite (Level1, HIGH);          //Set Level1 Alarm to be used in Level2
      delay(10);
    }

To put more than one statement inside an if/for/while you would put a '{' and '}' around them. For example:

    {
      for (int x = 0; x < 15; x++)         // Blink 15 times
      {
        digitalWrite(RedLite, HIGH);          //Blink Red Lights on
        delay(500);                           //for 500ms
        digitalWrite(RedLite, LOW);           //Blink Red Lights off
        delay(500);                           //for 500ms
      }
      digitalWrite (Level1, HIGH);          //Set Level1 Alarm to be used in Level2
      delay(10);
    }