B4R Tutorial B4R PIR (Passive Infrared Sensor) Example

Thanks to Erel for this great product !! (again)

Here's a PIR example (presence detection) with Arduino and B4R; the PIR sensor is the PIR HC-SR501



Code:

B4X:
#Region Project Attributes
    #AutoFlushLogs: True
    #StackBufferSize: 300
#End Region


Sub Process_Globals
   Public Serial1 As Serial
   Private pin13 As Pin
End Sub

Private Sub AppStart
   Serial1.Initialize(115200)
   Log("AppStart")
   pin13.Initialize (13, pin13.MODE_INPUT_PULLUP)
   pin13.AddListener("Change_state")
 
End Sub

Sub Change_state (State As Boolean)

  Select Case State
      Case True
        Log("state: Detected")
    Case False
        Log("state: Not Detected")
  End Select
 
End Sub
 

inakigarm

Well-Known Member
Licensed User
Longtime User
That's because I've used the 13 pin; that way I can "visually" detect when the PIR detects motion (activates the Pin 13 input of Arduino); Testing right performance of B4R (and logs) there's no need to use the pin13 as the PIR connection pin.
 

Cableguy

Expert
Licensed User
Longtime User
Shouldn't this be in the Tutorials section?
 

derez

Expert
Licensed User
Longtime User
I can't compile
If you just want to tell us your feelings - the right place is in chit-chat post.
If it is support you seek - the way to write it is to provide detailed data, like:
The board you use,
The sensor you use,
How did you connect it,
Versions of s/w,
Error messages,
etc.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…