I added the "wait for 5 seconds" code...thank you Runaway Pancake.
Haven't been able to test it yet because I cannot verify the code with errors.
I don't know how to fix it...I'm still at it, won't give up...and yes, I'm very new at this. ![]()
Automobile_Deterrent:131: error: a function-definition is not allowed here before '{' token
Automobile_Deterrent:138: error: expected }' at end of input Automobile_Deterrent:138: error: expected }' at end of input
/*
This example shows the output of an analogRead() of a Photocell.
By M.Gonzalez
www.codingcolor.com
The example code is in the public domain
*/
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;
byte DET;
const byte pirPin = 2;
//the amount of milliseconds the sensor has to be low
//before we assume all motion has stopped
unsigned long pause = 5000UL;Â
boolean lockLow = true;
boolean takeLowTime;Â
//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;
void setup() {
Serial.begin(9600);
 pinMode(photocellPin, INPUT);
 pinMode(pirPin, INPUT);
 pinMode(ledPin1, OUTPUT);
 pinMode(ledPin2, OUTPUT);
 pinMode(ledPin3, OUTPUT);
 pinMode(ledPin4, OUTPUT);
 pinMode(ledPin5, OUTPUT);
Â
 //give the sensor some time to calibrate
 Serial.print("calibrating sensor ");
  for(int i = 0; i < calibrationTime; i++){
   Serial.print(".");
   delay(1000);
   }
  Serial.println(" done");
  Serial.println("SENSOR ACTIVE");
  delay(50);
}
void loop() {
 photocellVal = analogRead(photocellPin);
 pirVal = digitalRead(pirPin);
 Â
 if (photocellVal < minLight && ledState == 0){
  // fade in from min to max in increments of 5 points:
 for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=5) {
  // sets the value (range from 0 to 255):
  analogWrite(ledPin1, fadeValue);   Â
  // wait for 30 milliseconds to see the dimming effect Â
  delay(30);
 Â
{
 DET = digitalRead(pirPin);
 if (DET == 1) // inactive
 {
  refTime = millis();
  trippoint = refTime;
 }
 else // Active Low
 {
  pir_active();
Â
}
Â
  digitalWrite(ledPin4, HIGH);
  digitalWrite(ledPin5, HIGH);}
 Â
   if(lockLow){Â
    //makes sure we wait for a transition to LOW before any further output is made:
    lockLow = false;     Â
    Serial.println("---");
    Serial.print("motion detected at ");
    Serial.print(millis()/1000);
    Serial.println(" sec");
    delay(50);
    }   Â
    takeLowTime = true;
  Â
  //Serial.println("fade up");
 {          Â
 Â
 if(pirVal == LOW)
Â
    Â
   digitalWrite(ledPin1, LOW); //the led visualizes the sensors output pin state
   digitalWrite(ledPin2, LOW);
   digitalWrite(ledPin3, LOW);
   digitalWrite(ledPin4, LOW);
   digitalWrite(ledPin5, LOW);
    Â
 if(takeLowTime){
    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 the sensor is low for more than the given pause,
   //we assume that no more motion is going to happen
Â
 if(!lockLow && millis() - lowIn > pause){Â
     //makes sure this block of code is only executed again after
     //a new motion sequence has been detected
     lockLow = true;           Â
     Serial.print("motion ended at ");   //output
     Serial.print((millis() - pause)/1000);
     Serial.println(" sec");
     delay(50);
   }
 Â
 Â
  void pir_active ()
{
   trippoint = millis();
 if ((trippoint-refTime) > threshold)
 {
   digitalWrite(ledPin2,HIGH);
   digitalWrite(ledPin3, HIGH);}
    }
   }