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:
- Check the wiring
it's good.
- Played the sensitivity and range knobs
tried every configuration and the issue remains.
- Checked the code
uploaded the official Arduino code from the tutorial and a custom-made one
same result.
- Did this test
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.
- Uploaded the four last versions of the IoT carrier library
I tried versions 2.1.0, 2.0.4, 2.0.2, 2.0.1, 1.0.4 and the issue remains.
- Checked the power supply
I powered the board with my computer and with two different powerbanks but the problem remains.
- Wired the PIR sensor to another port on the carrier
tried the A0/A5 and the A6 but the issue remains.
- Followed the next tutorial in the Oplà IoT kit with the moisture sensor
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.
- Wrote a simpler version of the "home alarm" sketch on Arduino IDE without using the IoT and wifi features
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!