Cheap PIR Sensor

Hi Folks,

to get a real cheap PIR sensor that also works with 4 - 5 volts, i disassembled an Airwick room deodorant dispenser with motion detection.
There are two versions sold this time in Germany for 6 Euros. The small one drives a magnetic valve and the big dispenser has a motor that pushes via gears the trigger of the fragrance can. (Anyway many nice parts for later use and lots of room deodorant cans for your wife)
The motor/mag. valve outputs are unusable, because the electronic limits the trigging pulse at min 7 minutes to prevent the room over flooded with good smell :wink:
Fortunaley the build in green LED flashes ~5 sec. in standby and twice on motion detection.
So i soldered a wire on the LED pin an connected it to the arduino. Then i wrote a (very dilettantish) sketch to use it:

int sensor = 0; //analog input from led pin airwick
int output = 0; //sensor output
int val1 = 0; //flash counter

void setup() {
Serial.begin(9600);

}

void loop() {
output = analogRead(sensor);
//Serial.print("output ");
//Serial.println(output);

if (output < 700){ //signal goes down when led flashes
val1 ++; //start to count, one flash = 2counts
delay(30);
if (output < 700) //wait for second flash
val1 ++;
}
else {
val1 = 0;
}
Serial.print("val1 ");
Serial.println(val1);

if (val1 > 3){ //led flashes twice in case of motion detection
Serial.println("dang"); //do something
}

delay(100);
}

it works half-well, but the problem is now, that the sketch self-counts after a few loops a detection (val1 incrases to 4)unless the PIR has detected any motion. I think the reason could be, that the sketch counts sometimes a standby flash twice.

Hope i gave you a good idea to get a cheap PIR sensor and someone can give me a hint to debug or rewrite my poor sketch that i can use the sensor for my next project.

Have fun

Matthias

Hello again,
OK, after reconsidering all, i thought it makes no sense at all with the stupid sketch i posted above.
Now i solved the problem on my analog-way. (I started out my electronics career 30 yrs before by repairing old tube radios :wink: )

Here you got it, enjoy!

/*Sketch to use the PCB of an Airwick(TM) room deodorant dispenser as motion
detector.

---The Hardware------

Solder a wire on the LED pin on the PCB (+)
Connect this wire to an 10k resistor
Connect the other end of the resistor to the + of an 47microFarad capacitor..
..and to the analog input 0 of your arduino
Connect the - (minus) of the capacitor to GND.
At least connect the power supply of the Airwick to the 5 volt output of the arduino..
..and don't forget to short-circut the "enable" pins on the airwick PCB

---How it wurks----

the Led on the PCB flashes once in standby and twice in case of motion detection.
when the Led flashes once, the capacitor get's unloaded to an level of ~ 970 and
relaods to 1030 when the Led is off.
When the Led flashes twice, the capacitor unloads more. The level is then ~ 820.
Now it's easy to use this in a sketch to switch something via the PIR..*/

int sensor = 0; //analog input from airwick as described above
int output = 0; //sensor output
int val1 = 0; //led on PIR counter

//int oldState = 0; //PIR state save

void setup() {
Serial.begin(9600);

}

void loop() {
output = analogRead(sensor);
Serial.print("output "); //for watching the signal and finetunig
Serial.println(output); //double slash if you like it

if (output < 850){ //signal goes down when led flashes
//turns lower than 850 at twice pulse

Serial.println("dang"); //do something you like
}

delay(200);
}

Kind regards

Matthias

sounds great. i picked one up last night and i'm going to poke at it today.

ok, this thing looks great. Easy to disassemble, nice selection of parts. Couple of pics of the circuit board below: The red & black leads go to the motor that trives the spray pump, the bare wires lead to the battery clips. just have to figure out where to break into the circuit. Note the free AA batteries by the way!



unfortunately, the glade ones seem to work differently than the airwick european model. Once triggered its light goes on solid and stays on for 30 minutes.

Does the PCB look the same? Where are the enable pins on the airwick?