Inteface PIR to 18M2 on 18m project board.

Hi

I am currently working on a project for automatic security lights prototype. The aim of the project is to turn a light on through a relay when light drops to a threshold. The light should be activated through PIR.

I have interfaced the LDR successfully as I have used the function to readadc and witnessed the value changing with light. Relay working also.

I have had no luck so far with the PIR that I have bought. I thought it would be a case of connecting the digital pin to an input on the microcontroller and writing code that basically says 'if light below threshold and presence then turn light I'm.
Below is an example of the code I have used:
Code:
b2 = c.1
Main:
readadc 1, b2
debug b2
if b2 <140 then gosub night_time
goto main

night_time:
do
low b.4
if pinC.0 = 1 then goto presence_detected
readadc 1, b2
debug b2
if b2 > 140 then gosub daytime
loop

presence_detected:
high b.4
pause 4000
goto night_time

daytime:
low b.4
goto main
The above code is just one example of my attempts to interface the sensor. The sensor is made by hiletgo.


Any help on interfacing PIR would be greatly appreciated.
 

hippy

Technical Support
Staff member
The first question is whether this PIR is an electronic module or a typical burglar alarm unit ?

What you have looks reasonable and right to me so it might be worthwhile writing some short code to see if the PICAXE is detecting PIR activation -
Code:
#Terminal 4800
Do
  If pinC.0 = 0 Then
    SerTxd( "PIR LOW",  CR, LF ) : Do : Loop While pinC.0 = 0
  Else
    SerTxd( "PIR HIGH", CR, LF ) : Do : Loop While pinC.0 = 1
  End If
Loop
Change that 4800 to 9600 if using a PICAXE X2.
 
The first question is whether this PIR is an electronic module or a typical burglar alarm unit ?

What you have looks reasonable and right to me so it might be worthwhile writing some short code to see if the PICAXE is detecting PIR activation -
Code:
#Terminal 4800
Do
  If pinC.0 = 0 Then
    SerTxd( "PIR LOW",  CR, LF ) : Do : Loop While pinC.0 = 0
  Else
    SerTxd( "PIR HIGH", CR, LF ) : Do : Loop While pinC.0 = 1
  End If
Loop
Change that 4800 to 9600 if using a PICAXE X2.
The first question is whether this PIR is an electronic module or a typical burglar alarm unit ?

What you have looks reasonable and right to me so it might be worthwhile writing some short code to see if the PICAXE is detecting PIR activation -
Code:
#Terminal 4800
Do
  If pinC.0 = 0 Then
    SerTxd( "PIR LOW",  CR, LF ) : Do : Loop While pinC.0 = 0
  Else
    SerTxd( "PIR HIGH", CR, LF ) : Do : Loop While pinC.0 = 1
  End If
Loop
Change that 4800 to 9600 if using a PICAXE X2.
Hippy,
The serial terminal showed that the microcontroller is reading the PIR.
 

hippy

Technical Support
Staff member
The serial terminal showed that the microcontroller is reading the PIR.
That's good. I suppose the question is whether the PICAXE determines day or night correctly.

If so, then it would seem there is possibly some logical error in the program. There are some GOSUB's to non-subroutines in the code, which isn't right but probably does not cause a problem when running on an actual chip.

It might help to refactor the code a little -
Code:
Main:
  Do
    Low B.4
    ReadAdc C.1, b2
    If b2 > 140 Then
      Gosub Day_Time
    Else
      Gosub Night_Time
    End If
    Pause 100
  Loop

Day_Time:
  ; Do nothing
  Return

Night_Time:
  If pinC.0 = 1 Then
    High B.4
    Pause 4000
  End If
  Return
 

erco

Senior Member
Dan: Are you aware that you are using the sensor module I linked to? It's not a simple IR-only sensor. It has its own built-in light sensor and timer delay, so there is a lot going on. You will definitely get erratic results if you try to use it as a simple sensor and aren't aware of its inner workings. If you need a sensor without a light sensor, try something like https://www.amazon.co.uk/SODIAL-HC-SR505-Infrared-Precise-Detector/dp/B078H52HBV/ref=pd_sbs_23_4/257-5494501-9297432

Also, IR sensors can only transition so fast. They need settling time between trigger states.
 
Last edited:

PhilHornby

Senior Member
Datasheet for BISS0001 used by module: https://cdn-learn.adafruit.com/assets/assets/000/010/133/original/BISS0001.pdf

Things to watch out for:

When the BISS0001 is first powered up, it takes a while (a minute?) to stabilise, during which time it is triggered on.
There are two o/p modes, one where it sends a long HIGH to denote triggering and one where it sends a train of pulses as it detects a moving IR source.
 

mikeyBoo

Senior Member
hi Dan,
I played with the SR501 motion detectors a while back & posted a project about using them. They are very cheap & work great in a lot of applications. They have sensitivity & output on-time adjustments. Also, under the little round cover there is a place to mount a LVR if you only want them to activate at night.
About the only time I ever coupled one to a Picaxe is when I wanted to send an RF message (the Picaxe can be activated by powering an open-collector transistor with +5v).
Anyhow, the link below describes my adventures with the 501, might save you some effort. My writing style is very relaxing (my buddy says reading my stuff helps him get to sleep at night).

Have fun! And if you learn something new, please share (that’s what this site is all about).

https://picaxeforum.co.uk/threads/cheap-easy-motion-detectors-night-light-controllers-picaxe-or-stand-alone.28233/
 
Dan: Are you aware that you are using the sensor module I linked to? It's not a simple IR-only sensor. It has its own built-in light sensor and timer delay, so there is a lot going on. You will definitely get erratic results if you try to use it as a simple sensor and aren't aware of its inner workings. If you need a sensor without a light sensor, try something like https://www.amazon.co.uk/SODIAL-HC-SR505-Infrared-Precise-Detector/dp/B078H52HBV/ref=pd_sbs_23_4/257-5494501-9297432

Also, IR sensors can only transition so fast. They need settling time between trigger states.
Dan: Are you aware that you are using the sensor module I linked to? It's not a simple IR-only sensor. It has its own built-in light sensor and timer delay, so there is a lot going on. You will definitely get erratic results if you try to use it as a simple sensor and aren't aware of its inner workings. If you need a sensor without a light sensor, try something like https://www.amazon.co.uk/SODIAL-HC-SR505-Infrared-Precise-Detector/dp/B078H52HBV/ref=pd_sbs_23_4/257-5494501-9297432

Also, IR sensors can only transition so fast. They need settling time between trigger states.

Erco,

I am aware that it has other capabilities and was possibly a poor selection for this project. You points are noted for the next one though, I will take more care in future.

Thanks
 
hi Dan,
I played with the SR501 motion detectors a while back & posted a project about using them. They are very cheap & work great in a lot of applications. They have sensitivity & output on-time adjustments. Also, under the little round cover there is a place to mount a LVR if you only want them to activate at night.
About the only time I ever coupled one to a Picaxe is when I wanted to send an RF message (the Picaxe can be activated by powering an open-collector transistor with +5v).
Anyhow, the link below describes my adventures with the 501, might save you some effort. My writing style is very relaxing (my buddy says reading my stuff helps him get to sleep at night).

Have fun! And if you learn something new, please share (that’s what this site is all about).

https://picaxeforum.co.uk/threads/cheap-easy-motion-detectors-night-light-controllers-picaxe-or-stand-alone.28233/

Useful info, thanks.
 
Datasheet for BISS0001 used by module: https://cdn-learn.adafruit.com/assets/assets/000/010/133/original/BISS0001.pdf

Things to watch out for:

When the BISS0001 is first powered up, it takes a while (a minute?) to stabilise, during which time it is triggered on.
There are two o/p modes, one where it sends a long HIGH to denote triggering and one where it sends a train of pulses as it detects a moving IR source.
That's good. I suppose the question is whether the PICAXE determines day or night correctly.

If so, then it would seem there is possibly some logical error in the program. There are some GOSUB's to non-subroutines in the code, which isn't right but probably does not cause a problem when running on an actual chip.

It might help to refactor the code a little -
Code:
Main:
  Do
    Low B.4
    ReadAdc C.1, b2
    If b2 > 140 Then
      Gosub Day_Time
    Else
      Gosub Night_Time
    End If
    Pause 100
  Loop

Day_Time:
  ; Do nothing
  Return

Night_Time:
  If pinC.0 = 1 Then
    High B.4
    Pause 4000
  End If
  Return

Hippy

It worked!

Thanks for your help.
 
Top