Code help

Hello everyone;
I need some help with this code please. It does nothing right now.
What I'm trying to do is:

  1. If it's not dark, keep checking until that changes.
  2. If the PIR is not activated, keep checking until it is.
  3. If both are true, sound the alarm and blink the LEDs for three seconds.
    Any hints or help would be helpful. Thanks.
int ldrPin = 0;
int pirPin = 8;
int LED1 = 5;
int LED2 = 6;
int relayPin = 10;

byte pirState = LOW;
byte ldrState = LOW;

unsigned long interval = 3000;
unsigned long previousMillis = 0;
unsigned long currentMillis = 0;

void setup() {

  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(8, INPUT);
  pinMode(0, INPUT);
  pinMode(10, OUTPUT);
}

void loop () {

Start:
  unsigned long currentMillis = millis();  //Get current time

  analogRead(ldrPin);                //Is it dark?
  if (ldrState  >= 100) {
    goto Start;
  }                 //If it's not dark, check again
  else {                             //If it is dark go on
  }
  delay(10);
  digitalRead(pirPin);                //Is the PIR activated?
  if (pirState == LOW) {
    goto Start;                         //If it is not activated, go to start

  }
  else  {                                  
    delay(10);
  }
}
void alarm () {

  digitalWrite(relayPin, HIGH);            //If the pin is actuated and it is dark, sound the alarm

  digitalWrite(LED1, HIGH);
  digitalWrite(LED2, LOW);
  delay(100);

  digitalWrite(LED1, LOW);
  digitalWrite(LED2, HIGH);
  delay(100);

  if ((unsigned long)(currentMillis - previousMillis) >= interval) {  //let it sound for 3 seconds

    previousMillis = millis();
  }
}

I can't see any place where alarm() is called.

Prepare to be castigated for using goto.

dougp:
I can't see any place where alarm() is called.

Prepare to be castigated for using goto.

Hi, The alarm is on the Relay pin.
Is there another way to have the program go to the start with Goto?

Why use goto's? and you shouldn't use delays.

There is no call to Alarm?

If i were doing this I would do something like this

Loop
Read LDR into an integer "light Level"
Read pir High/Low "Pir activated"

If "light level" < x and pir activated == high then Alarm //where x eguals dark threshold.

Alarm
put alarm action code here

that should do everything you need without the gotos
The program will loop continuously and only activate the alarm when BOTH conditions are true.

If you then want to get fancy you could run a four core cable to the PIR and use resistor bridges to build and monitor anti tamper circuits.

Polliwog:
Is there another way to have the program go to the start with Goto?

Yes, leave out the goto.

Thanks for your help.

pinMode(0, INPUT);
pinMode(10, OUTPUT);

If you're using an UNO pins zero and one are used for the serial port to the PC and are not normally used for project I/O.

A few more small things: You give the I/O pins names - that's a good thing. But you can improve understandability by using those names instead of the values they were given. So,

pinMode(relayPin, OUTPUT);
//
// instead of
//
pinMode(10, OUTPUT);

and; since pin numbers don't exceed 255 you can save a smidge of RAM by declaring pins as bytes rather than integers.