PIR Motion sensor - stay on

Hey, I am new to Arduino and I am relatively good with coding, however, Arduino language is new to me. I am making a 'lamp' project where a PIR sensor turns on a LED when it detects motion. Easy, got that sorted. The issue is I don't know how to keep the LED on when someone is in front of it.

I want someone to walk into a room, walk past the PIR sensor and essentially the
LED or 'lamp' turns on and stays on until it doesn't detect motion anymore. So as long as someone is in range, not necessarily moving, the LED will stay on (if you go into a room and sit in bed and lay still if the PIR can see your heat signature it keeps the LED on until you leave the room).

This is my code, any advice would be appreciated!

int led = 13; // the pin that the LED is atteched to
int sensor = 2; // the pin that the sensor is atteched to
int state = LOW; // by default, no motion detected
int val = 0; // variable to store the sensor status (value)

void setup() {
pinMode(led, OUTPUT); // initalize LED as an output
pinMode(sensor, INPUT); // initialize sensor as an input
Serial.begin(9600); // initialize serial
}

void loop(){
val = digitalRead(sensor); // read sensor value
if (val == HIGH) { // check if the sensor is HIGH
digitalWrite(led, HIGH); // turn LED ON
delay(100000); // delay 1 minute

if (state == LOW) {
  Serial.println("Motion detected!"); 
  state = HIGH;       // update variable state to HIGH
}

}
else {
digitalWrite(led, LOW); // turn LED OFF
delay(10); // delay 10 milliseconds

  if (state == HIGH){
    Serial.println("Motion stopped!");
    state = LOW;       // update variable state to LOW
}

}
}

Remove the delay() calls and your code should do what you describe.

I have removed the delays and it now works quicker, but the light only stays on when I move. I want it to stay on when I am stationary but still within its range. Can it or any other item do this? I essentially want it to keep reading my heat signature even if I'm not 'moving'.

Sure, that's because the PIR can only see motion. If you don't move the PIR sensor thinks you're not there.

You cannot do that with a PIR.

Not with cheap parts. You may get this using an infrared camera and object detection but that's way out of the Arduino world.

1 Like

Hi,
I could be wrong, but to my knowledge a PIR sensor does not read the thermal signature.
It is a differential sensor, that is, it detects infrared variations.
PIR sensors used in homes/offices for example have a timer and turn off after a programmed time if you are immobile.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.