How to reduce PIR sensing area

Im working on a spray bottle project that is supposed to sense a hand closing in on the bottle and activate a servo (that squeezes the handle & sprays the bottle).

The problem is that even with all the sensitivity down to its lowest value via the onboard pot of the PIR sensor, it still fires when someone just walks by or opens the door.

Is there a way to make it so that it behaves more like a public bathroom sensor where the detection area is only limited to a few cms directly in front of the sensor?

Marciokoko:
...even with all the sensitivity down to its lowest value via the onboard pot of the PIR sensor...

That is not a sensitivity pot, but a 'delayed response' adjustment, to reduce false triggering.

Modding the fresnel lens (plastic dome) could be an easy way to reduce viewing angle for the sensor.
Try a round piece of paper inside the dome. With or without a hole in the middle.

Bathroom sensors most likely don't use PIR sensors.
Leo..

Is this safe? Can a child walk up to it and not get a face full of sanitizer?

So I put a pvc 1/2" pipe around the sensor, replacing the dome. Doesnt make a difference, still fires, maybe a little less but still fires.

As for it being safe, its placed on a low level table where anyone in the house would be a hand or hip level if in front of it. Why do you ask?

ive enclosed the entire pir sensor with its protruding 1/2" pvc pipe structure and even with nobody present it seems to fire. Although when I test it without the servo connected, from my laptop, the sm seems to show normal behavior. For some reason when connected to the motor it behaves erratic and fires every 8 seconds?

#include <Servo.h>
Servo myservo;
int calibrationTime = 30;
//the time when the sensor outputs a low impulse
long unsigned int lowIn;
//the amount of milliseconds the sensor has to be low
//before we assume all motion has stopped
long unsigned int pause = 500;
boolean takeLowTime;
int pirPin = 6;    //the digital pin connected to the PIR sensor's output
int ledPin = 13;

void setup() {
 Serial.begin(9600);
 pinMode(pirPin, INPUT);
 pinMode(ledPin, OUTPUT);
 digitalWrite(pirPin, LOW);
 myservo.attach(9);  // attaches the servo on pin 9 to the servo object
 delay(1000);
 myservo.write(0);
 //give the sensor some time to calibrate
 Serial.print("calibrating sensor ");
 for (int i = 0; i < calibrationTime; i++) {
   digitalWrite(ledPin,HIGH);
   Serial.print(".");
   digitalWrite(ledPin,LOW);
   delay(10);
 }
 Serial.println(" done");
 Serial.println("SENSOR ACTIVE");
 delay(50);
}

void loop() {
 //delay(1000);
 Serial.println("main loop");
 if (digitalRead(pirPin) == HIGH) {
   Serial.println("---");
   Serial.print("motion detected at ");
   Serial.print(millis() / 1000);
   Serial.println(" sec");
   digitalWrite(ledPin,HIGH);
   digitalWrite(pirPin, LOW);
   //delay(2000);//wait 1 sec to see if it's still there
   //if (digitalRead(pirPin) == HIGH) {//still high. time to squirt
     //Serial.println("still there");
   squirt_it();
   //}
   digitalWrite(ledPin,LOW);
 }
}

void squirt_it() {
 Serial.println("squirt");
 for (int i = 0; i <= 1; i++) {//squirt twice
   myservo.write(180);              
   Serial.println(180);
   digitalWrite(ledPin,HIGH);
   delay(1000);                       // waits 15ms for the servo to reach the position
   myservo.write(0);
   Serial.println(0);
   digitalWrite(ledPin,LOW);
   delay(1000);                       // waits 15ms for the servo to reach the position
   myservo.write(180);             
   Serial.println(180);
   myservo.write(0);
   Serial.println(0);
   digitalWrite(ledPin,HIGH);
   delay(2000);
 }
}

I moved it to the dining table (without the motor
for testing) and placed a ceramic cup over it and it doesnt fire every 8, but it still fires every now and then…

oh wait, the mobile was near it. Now it seems to be working. Ill go plug in the motor…ok its misfiring again. I think there are 2 issues:

  1. Stability of power source. With laptop it seems better because it doesnt misfire as often, as opposed to the power bank source. Turns out its not so much the stability of the power source as it is the power bank internal wiring. I guess each time it pulses it sets off the sensor for some reason. Powered by the laptop the sensor simply doesnt misfire. I just tested on wall power and it works fine.

  2. Heat. With my current settings on the PIR and code and stable laptop battery source, my hand barely sets it off, but if I run a cup of coffee in front of it it works every time.

I know this is not the sensor used for this type of application, but Im trying to make it work.

Marciokoko:
I know this is not the sensor used for this type of application, but Im trying to make it work.

Perhaps try it this way........Flush.jpg

Flush.jpg