MMM-PIR-Sensor tuning

  • @shgmongohh Ok I’ll take a look at my stuff soon. I’m in the middle of writing another module that takes a photo when this PIR module senses user presence, if you had a camera attached it might be useful to you to see what the pir is detecting, if anything.

  • @jc21
    Thank you. I don´t have a camera.
    I don´t know if the sonsor works not correct or if I have another issue.

    When I install your module, have I to delete or uninstall the other pir-module?
    I only have renamed the folder.
    If i have to delete it, how is it done?


  • I have found a python programm, where I can track the sensor in a consolen window. Has anybody an idea how i can safe the data into a document? And how I can autostart my python programm?

    # Import required Python libraries
    import RPi.GPIO as GPIO
    import time
    import datetime
    # Use BCM GPIO references
    # instead of physical pin numbers
    # Define GPIO to use on Pi
    GPIO_PIR = 23
    print "Bewegungsmelder Test (CTRL-C zum Beenden)"
    print "========================================="
    # Set pin as input
    GPIO.setup(GPIO_PIR,GPIO.IN)      # Echo
    Current_State  = 0
    Previous_State = 0
      print "%s: Sensor initialisieren ..." %  
      # Loop until PIR output is 0
      while GPIO.input(GPIO_PIR)==1:
        Current_State  = 0    
      print "%s: Fertig! Warte auf Bewegung..."  %    
      # Loop until users quits with CTRL-C
      while True :
        # Read PIR state
        Current_State = GPIO.input(GPIO_PIR)
        if Current_State==1 and Previous_State==0:
          # PIR is triggered
          print " %s: Bewegung erkannt!" % 
          # Record previous state
        elif Current_State==0 and Previous_State==1:
          # PIR has returned to ready state
          print " %s: Fertig! Warte auf Bewegung..."  % 
        # Wait for 10 milliseconds
    except KeyboardInterrupt:
      print " Exit"
      # Reset GPIO settings

  • It done. I can tune my PIR-Sensor.
    Here is a usefull Link.

  • Hi, I’very been through a lot of the posts on the White Screen issue, and on this thread. I’m close… I can feel it, but I’ve an uncaught exception that I don’t understand.

    [TAILING] Tailing last 10 lines for [mm] process (change the value with --lines option)
    /home/pi/.pm2/logs/mm-error-0.log last 10 lines:
    0|mm | at /home/pi/MagicMirror/modules/MMM-PIR-Sensor/node_helper.js:65:18
    0|mm | at /home/pi/MagicMirror/modules/MMM-PIR-Sensor/node_modules/onoff/onoff.js:27:5
    0|mm | at Array.forEach (native)
    0|mm | at Gpio.pollerEventHandler (/home/pi/MagicMirror/modules/MMM-PIR-Sensor/node_modules/onoff/onoff.js:26:13)
    0|mm | TypeError: Cannot read property ‘writeSync’ of undefined
    0|mm | at Class.activateMonitor (/home/pi/MagicMirror/modules/MMM-PIR-Sensor/node_helper.js:21:17)
    0|mm | at /home/pi/MagicMirror/modules/MMM-PIR-Sensor/node_helper.js:59:18
    0|mm | at /home/pi/MagicMirror/modules/MMM-PIR-Sensor/node_modules/onoff/onoff.js:27:5
    0|mm | at Array.forEach (native)
    0|mm | at Gpio.pollerEventHandler (/home/pi/MagicMirror/modules/MMM-PIR-Sensor/node_modules/onoff/onoff.js:26:13)

    link to screengrab.

    Anyone offer any tips as to what might be causing this?

    I’m on a Pi3 Model B v2.
    Have only installed the standard mirror module, and the MMM-PIR module. The mirror is working fine and the PIR module is loading, but the screen isn’t switching off.

  • @open_book Few things,

    1. What version of Raspbian are you using? The onoffnpm module has issues with some releases.
      Hint: cat /etc/os-release
    2. What does your config look like for the pir module, exactly?

  • @jc21
    PRETTY_NAME=“Raspbian GNU/Linux 8 (jessie)”
    NAME=“Raspbian GNU/Linux”
    VERSION=“8 (jessie)”

    		module: 'MMM-PIR-Sensor',
    		config: {
    			sensorPIN: 3,
    			powerSaving: true,

  • @open_book Very strange, it seems the module is trying to activate/deactive the monitor using the Relay, but you haven’t specified a relay to use.

    I have noticed however, that sensorPIN of 3 shouldn’t work. This variable is incorrectly named, it is not actually the pin number of the header, but the GPIO number instead. Refer to this Pi 3 image showing which “pins” correspond to “gpio” numbers. You should be using one of 4, 5, 6, 12, 13, 18, 22, 23, 24, 25, 26 or 27.

    For example, a sensorPIN of 4 would require the PIR io cable plugged in to pin header 7.

  • @jc21 hi again, thanks for your input so far.

    I’ve had the sensorPIN at 22 previously. And tested it using the python script shared on a few other threads:

    from gpiozero import MotionSensor
    import os

    pir= MotionSensor(22)
    while True:
    if pir.wait_for_motion(timeout=10*60):
    print(“It lives”)
    os.system("/opt/vc/bin/tvservice -0")
    The result spammed “It lives”. Which I understand to mean that the sensor is working… If I change the if to “os.system(”/opt/vc/bin/tvservice -p")" the screen shutsdown.

    The reason I changed it was based on the results of “gpio readall”. I currently have power in pin 1 (3.3v), ground in pin 6 and data in pin 15

    gpio readall tells me that physical 15 = BCM 22 = GPIO 3 so I decided to try sensorPin: 3.

    I’ve changed it back to 22 now, but the result is still the same.

    Other possible vectors are:

    I’m forcing HDMI output because I’m using a HDMI -> DVI converter and so it seemed like a safe choice.

    With dev tools open I can see that USER_PRESENCE is not being logged anywhere in the console.

    I followed this post and ran:

    “Run npm rebuild --runtime=electron --target=1.3.4 --disturl= --abi=49”
    in the MMM-PIR-Sensor folder,

  • Sounds like you’re on top of that then.

    Just fyi, the latest code for the original pir sensor module will rebuild the compiled dependencies for you as part of the npm install command in the module. There should be no reason to run npm rebuild manually unless you get those pesky “expected version xx but got xx” errors.