Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    Reading PIR

    Scheduled Pinned Locked Moved LoPy
    9 Posts 5 Posters 2.5k Views 5 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • L Offline
      louis
      last edited by sakis

      Trying to read a PIR-sensor with the LoPy without success so far, I turn to this eminent group for help.
      I have tried the following code, with the pir (https://www.adafruit.com/product/189) connected to Vin, Grnd and G5, bridging v3.3 and G28 for pullup:

      What am I doing wrong?

      from machine import Pin
      from time import sleep_ms
      pir = ("G5", mode=Pin.INPUT, pull=Pin.PULL_UP)
      while True:
          sleep_ms(100)
          curr_val = pir.value()
          print(curr_val)
      
      1 Reply Last reply Reply Quote 0
      • L Offline
        livius
        last edited by

        i understand this:

         connected to Vin, Grnd and G5
        

        but for what you do this?

        bridging v3.3 and G28 for pullup
        

        will be better to show picture of your setup

        think about people first, then computers

        L 1 Reply Last reply Reply Quote 0
        • L Offline
          louis @livius
          last edited by

          @livius I have used the adafruit example for the Raspberry PI as a reference and misread it. Nevertheless, also without the pullup I do not get a state change, the value remains 0 (zero).

          1 Reply Last reply Reply Quote 0
          • D Offline
            digsatman
            last edited by

            What PIR are you using as the one mentioned in the Adafruit example specifically states it works on 5V to 12V even though the output logic is 3.3V compatible. It states that you need to bypass the onboard regulator if you want to run it from a 3V power rail.

            L 1 Reply Last reply Reply Quote 0
            • X Offline
              Xykon administrators
              last edited by Xykon

              I found my PIR module and gave it a go.

              Connected VCC/GND on the PIR module to VIN (5V) and GND on the LoPy.

              First I connected OUT to an LED to see that the module is working. LED would light up when something got close to it.

              Second I checked with a multimeter that OUT would not exceed 3.3V

              Then I connected it to P8 and used the simple input pin example from the quick reference (no pull-up needed). Values change as expected.

              from machine import Pin
              p_in = Pin('P8', mode=Pin.IN)
              p_in()
              

              Christian Ehlers

              1 Reply Last reply Reply Quote 2
              • L Offline
                louis @digsatman
                last edited by

                @digsatman said in Reading PIR:

                bypass the onboard regulator

                I see what you mean, thanks for pointing it out. Will try this and let you know if it worked.

                1 Reply Last reply Reply Quote 0
                • L Offline
                  louis
                  last edited by

                  Following digsatman's suggestion I found this posting

                  http://www.instructables.com/id/Convert-a-5v-PIR-Motion-Sensor-to-33v-for-ESP8266/

                  which seems to work.

                  Thanks everyone for taking your time to reply.

                  1 Reply Last reply Reply Quote 1
                  • R Offline
                    Ralph
                    last edited by

                    I have the same sensor and got it running. I'll make a blog post of it soon. Here is some simplified part of my code that should be of use to you (it's untested though)

                    from machine import Pin
                    import time
                    
                    pir_triggered=0
                    
                    def pirTriggered(pin):
                        print("Pir triggered")
                        global pir_triggered
                        pir_triggered = 1
                    
                    pir = Pin('GP4',mode=Pin.IN,pull=Pin.PULL_UP)
                    pir.irq(trigger=Pin.IRQ_RISING, handler=pirTriggered)
                    
                    while True:
                        time.sleep_ms(500)
                        if pir_triggered == 1:
                            pir_triggered = 0
                            print("Sending some http requests to my domoticz server from here...")
                    

                    Notice I have it connected to GP4. I'm using a callback to set a global flag, then detect it in the main loop. I'm sending an http request to my domoticz server from there to turn on a lamp

                    L 1 Reply Last reply Reply Quote 1
                    • L Offline
                      louis @Ralph
                      last edited by

                      @Ralph Thanks, for the posting, I will definitely try it out.

                      1 Reply Last reply Reply Quote 0

                      Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                      Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                      With your input, this post could be even better 💗

                      Register Login
                      • 1 / 1
                      • First post
                        Last post

                      Pycom on Twitter

                      Pycom