I've installed the pigpio library and so I decided to check it with a simple script that I hope it's right. I wanted to write a script whenever the PIR sensor detected motion. I've checked with multimeter if it was actually sending a trigger and it does, so I suppose there's a problem with software. In fact, regardless the script that may be wrong, even when I try to set the GPIO to an high state the multimeter still shows 0 V and even the example I found in the pigpio website (the Hall sensor one) doesn't work.

import pigpio
import time

pi = pigpio.pi()

pi.set_mode(25, pigpio.INPUT)
while pi.read (25) == 1:
  time.sleep (2)

Edit: sorry but I can't write properly the script here

  • I've just edited the code formatting. It should appear any moment now. Nov 22, 2015 at 10:28
  • 1
    Do you get any error message? If not the likliest problem is not talking to the GPIO you think you are. pigpio always uses Broadcom GPIO numbers. GPIO 25 in on pin 22 of the expansion header.
    – joan
    Nov 22, 2015 at 11:47
  • 1
    For joan: you were right, I was using the wrong pin numbering, now the Hall sensor script works! Nov 22, 2015 at 15:14
  • Also, for pi4, add the user to the gpio group: "sudo adduser username gpio" adding your user to the spi group is also useful.
    – Robin
    Jan 14, 2020 at 14:56

1 Answer 1


I think your code is wrong because you do a while pi.read(25) == 1. If the code runs and your pin is at zero, it will run to its end and finish. You should try with a while true and inside the while block, place an if pi.read(25) == 1 statement with the "detection" string and the sleep statement.

  • 1
    I changed the script as you told me and now it works just fine! Thank you very much for your help and your prompt reply! Nov 22, 2015 at 15:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.