/*
Sketch generated by the Arduino IoT Cloud Thing "Untitled 2"
https://create.arduino.cc/cloud/things/20010ae2-be1e-497a-bede-13b054b98c91
Arduino IoT Cloud Variables description
The following variables are automatically generated and updated when changes are made to the Thing
float t;
float z;
int h;
int y;
bool x;
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 <Arduino.h>
#include <HTTPClient.h>
#include <iostream>
#include <vector>
#include <cmath>
#include <ESP32Servo.h>
#include "DHT.h"
#define DHT22PIN 4
const int servoPin = 18;
Servo servo;
DHT dht(DHT22PIN, DHT22);
int LEDRED = 13;
int LEDGREEN = 14;
void setup() {
servo.attach(servoPin, 500, 2400);
// 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(13 , OUTPUT);
pinMode(14, OUTPUT);
// 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();
h = dht.readHumidity();
t= dht.readTemperature();
Serial.println(h);
Serial.println(t);
Serial.println(z);
Serial.print(x);
Serial.println(y);
// Your code here
delay(1500);
}
/*
Since X is READ_WRITE variable, onXChange() is
executed every time a new value is received from IoT Cloud.
*/
void onXChange() {
digitalWrite(13,x);
// Add your code here to act upon X change
}
/*
Since Y is READ_WRITE variable, onYChange() is
executed every time a new value is received from IoT Cloud.
*/
void onYChange() {
analogWrite(14,y);
// Add your code here to act upon Y change
}
/*
Since Z is READ_WRITE variable, onZChange() is
executed every time a new value is received from IoT Cloud.
*/
void onZChange() {
servo.write(z);
// Add your code here to act upon Z change
}
/*
Since H is READ_WRITE variable, onHChange() is
executed every time a new value is received from IoT Cloud.
*/
void onHChange() {
// Add your code here to act upon H change
}
/*
Since T is READ_WRITE variable, onTChange() is
executed every time a new value is received from IoT Cloud.
*/
void onTChange() {
// Add your code here to act upon T change
}