PIR sensor alternates between high and low on MKR IoT carrier

Hi everyone,
I bought the Oplà IoT kit and am currently following the tutorials. I'm encountering an issue with the "home alarm" project and more specifically the PIR sensor.

Board: MKR Wifi 1010.
Carrier: MKR IoT carrier.

The movement alarm (through the PIR sensor) is triggered even though there is no movement. The "pirState" value is constantly alternating between 0 and 1. As a reference, pirState is defined like this in the Arduino code:

int pir;
int pirState = 0;

then in the setup:

pir = carrier.getBoardRevision() == 1 ? A5 : A0;
pinMode(pir, INPUT);

and finally in the loop:

pirState = digitalRead(pir);

I went through many steps of troubleshooting and here are the results:

  1. Check the wiring :arrow_right: it's good.
  2. Played the sensitivity and range knobs :arrow_right: tried every configuration and the issue remains.
  3. Checked the code :arrow_right: uploaded the official Arduino code from the tutorial and a custom-made one :arrow_right: same result.
  4. Did this test :arrow_right: the PIR sensor works perfectly. This test has been performed with the sensor plugged directly to the MKR Wifi 1010 board without the carrier and then with the sensor plugged to a Uno board. Same result, it works fine.
  5. Uploaded the four last versions of the IoT carrier library :arrow_right: I tried versions 2.1.0, 2.0.4, 2.0.2, 2.0.1, 1.0.4 and the issue remains.
  6. Checked the power supply :arrow_right: I powered the board with my computer and with two different powerbanks but the problem remains.
  7. Wired the PIR sensor to another port on the carrier :arrow_right: tried the A0/A5 and the A6 but the issue remains.
  8. Followed the next tutorial in the Oplà IoT kit with the moisture sensor :arrow_right: the sensor seems to work fine but I have no idea what would be the equivalent of the issue on this sensor since it's a capacitive sensor.
  9. Wrote a simpler version of the "home alarm" sketch on Arduino IDE without using the IoT and wifi features :arrow_right: the issue remains. Here is the code (there's a mix of different languages but you get the idea):
#include <Arduino_MKRIoTCarrier.h>
MKRIoTCarrier carrier;

int pir;
int pirEtat = 0;
int lumiere = 0;

uint32_t rouge = carrier.leds.Color(255,0,0);
uint32_t noCouleur = carrier.leds.Color(0,0,0);

void setup() {

CARRIER_CASE = false;
carrier.begin();
pir = carrier.getBoardRevision() == 1 ? A5 : A0;
carrier.display.setRotation(0);
delay(1500);
pinMode(pir, INPUT);
}

void loop() {
pirEtat = digitalRead(pir);
  
while(!carrier.Light.colorAvailable()){
  delay(5);
}
int none;
  carrier.Light.readColor(none,none,none,lumiere);

if(pirEtat == HIGH) {
  carrier.leds.fill(rouge, 0, 5);
  carrier.leds.show();
  carrier.Buzzer.sound(500);
  delay(500);
 
  carrier.leds.fill(noCouleur, 0, 5);
  carrier.leds.show();
  carrier.Buzzer.noSound();
  delay(500);
}
}

void alarme(){
  carrier.leds.fill(rouge, 0, 5);
  carrier.leds.show();
  carrier.Buzzer.sound(500);
  delay(500);
 
  carrier.leds.fill(noCouleur, 0, 5);
  carrier.leds.show();
  carrier.Buzzer.noSound();
  delay(500);
}

So far, I have established that:
The issue does not come from the sensor.
The issue does not come from the wires or the wiring.
The issue does not come from the code.
The issue does not come from the setting of the sensitivity and range knobs.
The issue does not come from the libraries.
The issue does not come from the power supply.
The issue does not come from the ports themselves on the carrier.

I've spent a lot of time troubleshooting this and I have to confess I'm a bit tired of all this. I've contacted the Arduino support team and they sent me here...

Any help would be welcome, thanks in advance!

Arduino Support team will assit you further on this via the support ticket you opened.

That's actually the Arduino support team who sent me here after two weeks of emails exchanges...

After four more weeks of waiting (initially for a replacement), I finally got an answer. Here it is for the people who may encounter the same issue in the future:

A pin (like the carrier's A0.....A5) in INPUT mode is floating , which means it can switch back and forth between LOW and HIGH seemingly at random, influenced by EMI in the surrounding environment.

To make it work, you have to use a workaround by connecting

the PIR Module to the MKR 1010 board's A0 (a digital pin can also be used) using 3 Female-Male connector.

Replacing the carrier or PIR sensor won't resolve the issue you reported, but this workaround should help you use the PIR.

(quotes from the support team).

You also have to redefine the PIN number for the PIR sensor in your sketch by commenting out:

//const int pirPin = carrier.getBoardRevision() == 1 ? A5 : A0;  and set the pin as shown below.
const int pirPin = A0;

I hope it will help!

By doing so, you won't be able to close the plastic casing unless you buy special "tiny flexible wires" (I haven't found any that fit so I won't be able to help on this matter. I used Dupont cables that I had to bend and run through the holes in the back).

Thankfully since there's a workaround, you won't need any replacement.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.