Problems with IoT Kit Projects

I'm going thru the projects in the Explore IoT kit and I'm finding missing code in several projects. Currently in Project 5 there is missing line 65 in given code with an unpaired bracket. I tried to replace line 65 with

if (pirState == LOW){

but have yet to get the thing to work. The code compiles without errors.

Help!

Welcome to the forum

Could you please be a bit more specific about your issue? Most of us are here for fun and do not know all the projects, examples and tutorials that people use. Could you provide a link to where you got your projects from please?

If you modified a project, please post the entire sketch (use code tags). Reduce large sketches to an example that shows the issue.

As a professor, what would you tell a student that just called Help! ? :slight_smile:

Hi!
Although I am a newbie, I think (hope) I can help with this issue.
I’ve pasted an e-mail below that I sent to the Arduino Help group that I think addresses the issue you are having troubles with. See the section highlighted in RED.
Note: I don’t know if the picture was attached, but It was linked to the wiring issue and not the pirState issue.
I’ve posted the code that works (I have some diagnostic stuff in there as well). I also initialize the pirState to LOW, but since it is updated later, I think that is irrelevant.
Thanks,
Jere
---------Email I sent to Arduino Contact-Us -------------
Good afternoon.

I wanted to let you know that I resolved the issue, and update you with what I found because it looks to me like you will need to update your online documentation.
The picture for lesson 5 (and also in lesson 6) is very misleading. It shows a different cable configuration than the one supplied with the kit and also a slightly different PIR module.
There are 2 separate issues:

  • I removed the Fresnel lens from the front of the PIR to reveal the pin designations and ground is the right-most pin, looking from the back, and VCC is the left-most pin.
    The PIR I received has 2 potentiometers, and I could not find a model number to include here.
  • The cable supplied with the kit is correct. I verified this by checking the voltage on the black and red wires.
    When it is configured as in the picture below, there is not +5v to power the PIR board.

Using the picture below, the wiring schema that works is as follows:

  • PIR Connector end - from left to right - red, yellow, black.
  • IOT Carrier end – from left to right – black, red, blank, yellow.

One other thing that I found (and maybe it’s one of those gotcha’s that an instructor puts in a lesson to make you do some troubleshooting) is that the pirState variable is initialized to HIGH (bool pirState = HIGH;), and movement is assumed to be :

if (pirState == LOW) {
alarm = true;
}
My experience with the PIR module I have is that it goes HIGH when movement is detected.

The consequence using the published code is that you can’t reset the state of the alarm variable from the IoT cloud. When you try, it immediately goes back to TRUE.

/* 
  Sketch generated by the Arduino IoT Cloud Thing "Activity5HomeAlarm"
  https://create.arduino.cc/cloud/things/811fea24-8425-4901-8742-1362c8e4f059 

  Arduino IoT Cloud Properties description

  The following variables are automatically generated and updated when changes are made to the Thing properties

  String message;
  bool alarm;

  Properties which are marked as READ/WRITE in the Cloud Thing will also have functions
  which are called when their values are changed from the Dashboard.
  These functions are generated with the Thing and added at the end of this sketch.
*/

#include "thingProperties.h"
#include <Arduino_MKRIoTCarrier.h>
MKRIoTCarrier carrier;

//Auto configure the sense distance for the touch pads
bool CARRIER_CASE = false;

//int pir = A6;
int pir = A5;
bool pirState = LOW;

//Colors
uint32_t colorRed = carrier.leds.Color(0, 255, 0);   //RED
uint32_t colorGreen = carrier.leds.Color(255, 0, 0);  //GREEN

void setup() {
  // Initialize serial and wait for port to open:
  Serial.begin(9600);
  // This delay gives the chance to wait for a Serial Monitor without blocking if none is found
  delay(1500); 

  pinMode(pir, INPUT);
  
  // Defined in thingProperties.h
  initProperties();

  // Connect to Arduino IoT Cloud
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);
  
  /*
     The following function allows you to obtain more information
     related to the state of network and IoT Cloud connection and errors
     the higher number the more granular information you’ll get.
     The default is 0 (only errors).
     Maximum is 4
 */
  setDebugMessageLevel(2);
  ArduinoCloud.printDebugInfo();
  
  //Wait to get cloud connection to init the carrier
  while (ArduinoCloud.connected() != 1) {
    ArduinoCloud.update();
    delay(500);
  }
  carrier.begin();
}

void loop() {
  ArduinoCloud.update();

  //reading the status of the PIR sensor
  pirState = digitalRead(pir);  
  Serial.print ("pir = ");
  Serial.println (pir);
  Serial.print ("pirState = ");
  Serial.println (pirState);
  Serial.print ("LOW = ");
  Serial.println (LOW);
 
  // I changed this to HIGH from LOW.  This seems to be incorrect in the documentation. 
  if (pirState == HIGH) {
    alarm = true;
  }
  Serial.print ("Alarm = ");
  Serial.println (alarm);

  //Dashboard check
  //when the alarm has not been triggered and it is off
  if (alarm == false) {
    message = "Everything is good!";
    carrier.leds.fill((colorGreen), 0, 5);
    carrier.leds.show();
  } else {
    //When the alarm has been triggered and it is on
    //The alarm will be on until the user goes to cloud's dashboard to turn it off
    message = "Warning! We have detected a person";
    carrier.leds.fill((colorRed), 0, 5);
    carrier.leds.show();
    //When motion is detected
  }
}
void onAlarmChange() {
  // Do something
}