Why is this so hard to make the lights come on!

I have:
PIR Sensor
Relay
Button

What I need it to do:

  • Sensor searching
  • It sees me and turns on the relay.
  • If the button is pressed while the relay is on, turn it off for 5 seconds.
  • start back over
//Varialbles
int calibrationTime = 15;   //the time we give the sensor to calibrate
int pirPin = 3;    //pin connected to the PIR sensor's output
int relayPin = 12;    //pin connected to the relay
int buttonPin = 2;

//Setup
void setup(){
  Serial.begin(9600);
  pinMode(pirPin, INPUT);
  pinMode(relayPin, OUTPUT);
  pinMode(buttonPin, INPUT);

  //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);
  }

//LOOP
void loop(){

int sensorValue = digitalRead(pirPin);    //declaring sensorValue to equal the tigger of PIR Sensor
int buttonValue = digitalRead(buttonPin);

     if(sensorValue == HIGH){   //sensor is triggered 
       digitalWrite(relayPin, LOW);   //turn on the relay
       Serial.println("On");    //write on
       if(buttonValue == HIGH){
        Serial.println("button Pressed");
        digitalWrite(relayPin, HIGH);
        delay(1000);
        Serial.println("1 Second");
        delay(1000);
        Serial.println("2 Seconds");
        delay(1000);
        Serial.println("3 Seconds");
        delay(1000);
        Serial.println("4 Seconds");
        delay(1000);
        
       }
     }else{
      digitalWrite(relayPin, HIGH);
      Serial.println("OFF");
     }
  }

Hi,
Welcome to the forum.

What isn't you code doing?

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom.. :slight_smile:

So what does it actually do?

I see a button that probably isn't being pulled down, though you should use internal pullup

I'm going to have to research the internal pull-up idea. I don't know anything about that.

I just shut down the computer after hours of figuring it out. Tomorrow I will try and get a picture drawn up for you guys. Hopefully you guys can help.

What it is doing:
The sensor works
It triggers the relay fine
The button just does not work.