Arduino MKR wifi 1010 DH11 IOT Cloud update issue

Hello,
I am trying to set up a DHT11 sensor on a Arduino MKR wifi 1010 with the IOT Cloud.

I have set it up so it reads the sensor every 5000ms and then updates the Cloud variables. I have made a dashboard with a gauge and a chart to show the temperature and humidity over time.

When I look at the serial monitor everything works as expected. But the Cloud variables seem to only update properly when the values of the temperature or humidity have changed significantly. e.g. when I breath on the sensor the values update every 5000ms, otherwise it only changes randomly every couple minutes.

I have attached a snip of the dashboard. Can any1 give some advice on how to fix this, if possible?

Here is the code:

/* 
  Sketch generated by the Arduino IoT Cloud Thing "Untitled"
  https://create.arduino.cc/cloud/things/95a13d0e-3781-47f8-ab42-220fc8400bb8 

  Arduino IoT Cloud Variables description

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

  float humCloud;
  float tempCloud;

  Variables 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 "DHT.h"

#define DHTPIN 2     
#define DHTTYPE DHT11   

DHT dht(DHTPIN, DHTTYPE);

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); 

  dht.begin();

  // 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();
}

void loop() {
  ArduinoCloud.update();
  // Your code here 
  
    // Wait a few seconds between measurements.
  delay(5000);

  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  float h = dht.readHumidity();
  // Read temperature as Celsius (the default)
  float t = dht.readTemperature();

  // Check if any reads failed and exit early (to try again).
  if (isnan(h) || isnan(t)) {
    Serial.println(F("Failed to read from DHT sensor!"));
    return;
  }

  Serial.print("Humidity: ");
  Serial.print(h);
  Serial.println("%");
  Serial.print("Temperature: ");
  Serial.print(t);
  Serial.println("°C ");
  
  humCloud = h;
  tempCloud = t;
  
}

Uploading: CaptureArduinoIOTCloud.PNG…Uploading: CaptureArduinoIOTCloud.PNG…

I have fixed the issue already.

The problem was that my Cloud variables were set to change "On Change" Instead of "periodically". So when the sensor read the exact same value it didn't update the Cloud Variable.

1 Like

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