Cheap PIR Sensor for E.g. Arduino
by diy_bloke in Circuits > Sensors
6517 Views, 12 Favorites, 0 Comments
Cheap PIR Sensor for E.g. Arduino
For a project I needed several PIR sensors and I know Adafruit sells a PIR board for about 10 USD. A description of that board is on instructables. That is doable, but I needed a few and of course there is also shipping + the mail delivery in my country (western Europe) is notoriously bad the last few years, so I had been putting it off (many other things to do as well).
Anyway, at a local thrift store, I had bought two battery operated LED nightlamps with a motion sensor (2.50 euro each) and while I was reading up on people hacking specific Breeze airfresheners for their motion sensor, these night lamps just did their duty, well sort of till I had changed the batteries a few times as they were pretty greedy for energy and i had forgotten about them.
But then I suddenly realised, Hey these thingies have motion sensors as well and when the batteries had started to leak in one of them I decide it was time for some further dissection.
The night lamp in question is a small casing with the typical white opaque PIR lens, a section with 3 bright LED's, a switch, for On, Off and Auto, and what I presumed was a photo diode, sticking out at one side. Opening the thing went pretty easy, just four screws.
It contained a little PCB with one big PIR sensor and one DIL-16 IC
The IC turned out to be an LP0001. I could find a very brief datasheet in English and the more extensive ones were in Chinese. yet I could figure it out.
I could get a digital signal from Pin 2 and an analogue signal from Pin 12.
The digital signal just indicates something moving yes or no, whereas the analog signal gives info on how close an object is. I am not sure though if the latter is really accurate.
Anyway, I needed a digital signal, but flexible as I am I decided to make a digital as well as an analogue I/O on it and also supply it with a decent 5 volt supply. That is very easily done.
Needed:
Parts:
Nightlamps with motion sensor
3 pieces of wire, preferably one of them black and the other two different colors except black or red
1 x 4 wide screw terminal strip
piece of four wire cable at desired length
Materials and tools:
Screwdriver
3-4 mm dril
solder
soldering Iron
Hotglue
Anyway, at a local thrift store, I had bought two battery operated LED nightlamps with a motion sensor (2.50 euro each) and while I was reading up on people hacking specific Breeze airfresheners for their motion sensor, these night lamps just did their duty, well sort of till I had changed the batteries a few times as they were pretty greedy for energy and i had forgotten about them.
But then I suddenly realised, Hey these thingies have motion sensors as well and when the batteries had started to leak in one of them I decide it was time for some further dissection.
The night lamp in question is a small casing with the typical white opaque PIR lens, a section with 3 bright LED's, a switch, for On, Off and Auto, and what I presumed was a photo diode, sticking out at one side. Opening the thing went pretty easy, just four screws.
It contained a little PCB with one big PIR sensor and one DIL-16 IC
The IC turned out to be an LP0001. I could find a very brief datasheet in English and the more extensive ones were in Chinese. yet I could figure it out.
I could get a digital signal from Pin 2 and an analogue signal from Pin 12.
The digital signal just indicates something moving yes or no, whereas the analog signal gives info on how close an object is. I am not sure though if the latter is really accurate.
Anyway, I needed a digital signal, but flexible as I am I decided to make a digital as well as an analogue I/O on it and also supply it with a decent 5 volt supply. That is very easily done.
Needed:
Parts:
Nightlamps with motion sensor
3 pieces of wire, preferably one of them black and the other two different colors except black or red
1 x 4 wide screw terminal strip
piece of four wire cable at desired length
Materials and tools:
Screwdriver
3-4 mm dril
solder
soldering Iron
Hotglue
Cheap PIR Sensor for E.g. Arduino
The backside of the PCB is quite clear and pin 2 and pin 12 of the IC are easy to locate and solder wires to. For Pin2, it is best to solder a wire a bit at a distance from the IC. For pin 12 this is not really possible. I also soldered a black ground wire to replace the original red ground wire. Of course isf you are only interested in a digital output, a wire to pin 2 is enough.
The photodiode is also easy to spot at the side of the PCB. This photodiode ensures that the sensor only operates in the dark. if you want it to always operate, replace it with a 100-200 k resistor.
Then dril a small hole in the back of the casing. Put the wires through and screw down the back part again.
I led the wires into a screw terminal that I glued down with hotglue. A cable with four cores then can be used to transport the signal further
The photodiode is also easy to spot at the side of the PCB. This photodiode ensures that the sensor only operates in the dark. if you want it to always operate, replace it with a 100-200 k resistor.
Then dril a small hole in the back of the casing. Put the wires through and screw down the back part again.
I led the wires into a screw terminal that I glued down with hotglue. A cable with four cores then can be used to transport the signal further
Cheap PIR Sensor: Programcode
There is ample information on using PIR sensors with an Arduino. A Program to use the Analogue signal could look as follows:
int pirPin=0; int value=0; void setup() { Serial.begin(9600); //just to check pinMode(pirPin, INPUT); } void loop() { value=sample(pirPin); Serial.println(value); } int sample(int z) /* This function will read the Pin 'z' 5 times and take an average. Afterwards it will be mapped by dividing by 4 Could of course immediately divide by 20 but this way it is easier to follow the program */ { int i; int sval = 0; for (i = 0; i < 5; i++){ sval = sval + analogRead(z);// sensor on analog pin 'z' } sval = sval / 5; // average sval = sval / 4; // scale to 8 bits (0 - 255) return sval; }