/*
Sketch generated by the Arduino IoT Cloud Thing "Untitled"
https://create.arduino.cc/cloud/things/38250d47-18cd-4407-af53-f8f772e44b37
Arduino IoT Cloud Variables description
The following variables are automatically generated and updated when changes are made to the Thing
float dHT_Hum;
float dHT_Temp;
bool led_1;
bool led_2;
bool led_3;
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 15 // GPIO that is connected to the sensor
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
const byte led1 = 25;
const byte led2 = 26;
const byte led3 = 27;
void setup() {
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
delay(1000);
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
delay(2000);
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
// 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
ReadSensor();
Serial.println();
Serial.print("Humaduty: ");
Serial.print(hum_dht);
Serial.print("%");
Serial.print(" | ");
Serial.print("Temperatura: ");
Serial.print(temp_dht);
Serial.print("°C");
delay(500);
}
/*
Since Led1 is READ_WRITE variable, onLed1Change() is
executed every time a new value is received from IoT Cloud.
*/
void onLampu1Change() {
// Add your code here to act upon Led1 change
if (lampu1) {
digitalWrite(led1, HIGH);
} else {
digitalWrite(led1, LOW);
}
}
/*
Since Led2 is READ_WRITE variable, onLed2Change() is
executed every time a new value is received from IoT Cloud.
*/
void onLampu2Change() {
// Add your code here to act upon Led2 change
if (lampu2) {
digitalWrite(led2, HIGH);
} else {
digitalWrite(led2, LOW);
}
}
/*
Since Led3 is READ_WRITE variable, onLed3Change() is
executed every time a new value is received from IoT Cloud.
*/
void onLampu3Change() {
// Add your code here to act upon Led3 change
if (lampu3) {
digitalWrite(led3, HIGH);
} else {
digitalWrite(led3, LOW);
}
}
/*
Since DHT is READ_WRITE variable, onDHTChange() is
executed every time a new value is received from IoT Cloud.
*/
void onTempDhtChange() {
// Add your code here to act upon Temp change
}
/*
Since Humidity is READ_WRITE variable, onHumidityChange() is
executed every time a new value is received from IoT Cloud.
*/
void onDhtHumChange() {
// Add your code here to act upon Humidity change
}
void ReadSensor() {
float t = dht.readTemperature();
float u = dht.readHumidity();
if (isnan(u) || isnan(t)) {
Serial.println(F("data error!"));
return;
}
temp_dht = t;
hum_dht = u;
delay(50);
}