Perhaps I really dont have an understanding of the }
i thought it's to execute whats after it as a whole?
before moving on to the next?
The brackets are for bunching relevant stuff together.
I'm really new at this...
This is about a lot more than "Send LED HIGH after 'x' seconds" ─ isn't it?
You have to approach this thing in steps.
This "one felled swoop" approach is not a winner.
I inserted some brackets where I thought they should go, but that's kind of hard to tell
So, it compiles, but I'm pretty sure that it's not what you figure.
int photocellPin = 0;// Photocell connected to analog pin 0
int photocellVal = A0; // define photocell variable
int pirVal = LOW;// motion sensor variable
int ledState = 0;//state of the led
int minLight = 20;//min light threshold
int maxLight = 20;//max light threshold
//the time we give the sensor to calibrate (10-60 secs according to the datasheet)
int calibrationTime = 30;
//the time when the sensor outputs a low impulse
unsigned long lowIn;
unsigned long refTime;
unsigned long trippoint;
const long threshold = 5000;
const byte pirPin = 2;
unsigned long pause = 5000UL;
boolean lockLow = true;
//int pirPin = 2; //the digital pin connected to the PIR sensor's output
int ledPin1 = 3;
int ledPin2 = 4;
int ledPin3 = 5;
int ledPin4 = 6;
int ledPin5 = 7;
//give the sensor some time to calibrate
Serial.print("calibrating sensor ");
for(int i = 0; i < calibrationTime; i++)
photocellVal = analogRead(photocellPin);
pirVal = digitalRead(pirPin);
if (photocellVal < minLight && ledState == 0)
for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=5)
DET = digitalRead(pirPin);
if (DET == 1) // inactive
refTime = millis();
trippoint = refTime;
else // Active Low
if(lockLow) // IF without a Condition to Meet -- WRONG
lockLow = false;
Serial.print("motion detected at ");
takeLowTime = true;
if(pirVal == LOW)
digitalWrite(ledPin1, LOW); //the led visualizes the sensors output pin state
if(takeLowTime) // another IF without a CONDITION!!!!!
lowIn = millis(); //save the time of the transition from high to LOW
takeLowTime = false; //make sure this is only done at the start of a LOW phase
if(!lockLow && millis() - lowIn > pause) // BAD code, and NO CONDITION !!!!
lockLow = true;
Serial.print("motion ended at "); //output
Serial.print((millis() - pause)/1000);
void pirActive ()
trippoint = millis();
if ((trippoint-refTime) > threshold)
I removed a lot of the comments, that's the only way I could keep from flying into a rage.
You have a few IF statements without a Condition, the equivalent of: IF (B)
. Well, What about "B", anyway?If (B == 100)
or If (B == false)
gives "B" a condition to meet. See?
Work out simpler stuff first that you can incorporate later.
There's much for you to develop.