I am having fun using the microbit with an AM312 PIR sensor - I bought a specific one that operated at a lower voltage (the ones I have used previously with Raspeberry Pis were 5V.
I am having issues with it though - I can make it work using the INPUT block ‘when Pin0 is pressed’… When I use an IF else statement with this block, it’s natural low state appears to be button pressed but if I move in front of the sensor, it changes to button unpressed. Using this command, I can make it work as a motion detector.
HOWEVER, I understand that the normal way of using one is to use the pin block 'Digital read Pin 0. When I use a logic block with this ’ Digital read pin 0 = 1 inside an if command, the PIR doesn’t trigger, it remains in a 0 state regardless of what I do.. I’m using a V2 microbit with banana plug connectors… I have tried other PIRs (I bought a 10 pack). I’m assuming it’s not this though as it can detect movement using the 'pin 0 is pressed block.
Any help gratefully received -I am new to this - do I need to set the pin as a read pin (as I would with raspberry pi?? I’m guessing it’s something like this that’s the problem??!?!
Hi, thanks for the reply. This is the barebones of the code that doesn’t work where P0 is the PIR and P1 is an LED. If I change =0 the LED lights up (which i assume means the PIR is constantly in a down state??
Solved it- just incase anyone else has a go with this- i bought a different PIR sensor type (SR602) and the code works as it should- I’m guessing the AM312 sensor works in a different way that means the other code is needed…
Could it be staying under the voltage threshold? Try analog reading it when it’s detecting/not detecting. I haven’t used Micro:bits in a while, so I don’t remember exactly how it works, but you should be able to have it read out the voltage when you press A, and if it’s reading pretty low it could just be under the threshold and not triggering it.
Got approved too late but I’m glad the issue was solved!
Thanks for this- I will definitely have a look at this, the original sensors are cheaper and I hate wasting stuff so would love to find out what’s going on…
Great piece of advice thank you - I used the ADC function and got it to constantly display the input - interestingly with the usb plugged in, it was reading 1011 as movement (I guess below the 1023 that would digitally read as 1?) When I plugged the battery in though, it was reading a consistent 1023 as movement… With this information I thought I would switch again to the digital read =1 trigger, assuming that with the battery it would work. I kept the analog read on and then found that movement with usb or battery only gave a reading of 415. Regardless, I love the fact it you can get it to constantly display the output, it makes it great for trouble shooting -thank you again for the advice!