I tried to use PIR sensor for my light switch with 220v relay and work but i want that pir sensor work like Ultrasonic Rangefinder but i cant get bigger distance from ultrasonic.
I need sensor or solution for arduino, i want when folks open doors, sensor turn on light and keep light
turned on until sense people presence, when folks go to next room and close doors, light is turning off.
This adafruit sketch is a good example of PIR code. Use of state variables allows it to distinguish between "new" and "old, continuing" motion:
/*
* PIR sensor tester
https://learn.adafruit.com/pir-passive-infrared-proximity-motion-sensor/using-a-pir
*/
int ledPin = 13; // choose the pin for the LED
int inputPin = 2; // choose the input pin (for PIR sensor)
int pirState = LOW; // we start, assuming no motion detected
int val = 0; // variable for reading the pin status
void setup() {
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(inputPin, INPUT); // declare sensor as input
Serial.begin(9600);
}
void loop(){
val = digitalRead(inputPin); // read input value
if (val == HIGH) { // check if the input is HIGH
digitalWrite(ledPin, HIGH); // turn LED ON
if (pirState == LOW) {
// we have just turned on
Serial.println("Motion detected!");
// We only want to print on the output change, not state
pirState = HIGH;
}
} else {
digitalWrite(ledPin, LOW); // turn LED OFF
if (pirState == HIGH){
// we have just turned of
Serial.println("Motion ended!");
// We only want to print on the output change, not state
pirState = LOW;
}
}
}
You may also want to make the delay greater than 1 second. You need to hold the light on for say 30 seconds after last movement detected to allow for lack of movement while in the room. Or you could just make sure that whenever you are in the room, you are moving vigorously!
I want that we focus exactly on what i'm asked in my question.
Is there any way, maybe with some other sensor than PIR that solve my qustion?
I repeat, i want that when i'm in the room, even when i don't move the light is staying on because sensor is always know that i'm in that room, when i go out of that room the light is turn off.
This is great example of what i want but i want angles catching, specifications and longer distance sensing to do like pir sensor.