I have made two projects with ESP8266 and Arduino IOT Cloud.
First project is to control a relay based on soil moisture data.
Second project is to control a relay based on temperature.
I have written the code for these projects and i have connected devices but my problem is that i cant read data from sensors and i cant control relay from the Arduino IOT Cloud.
/*
Sketch generated by the Arduino IoT Cloud Thing "Untitled"
https://create.arduino.cc/cloud/things/c5b29890-ea17-4f31-9492-271104ec2c4b
Arduino IoT Cloud Variables description
The following variables are automatically generated and updated when changes are made to the Thing
CloudTemperatureSensor temperatura1;
CloudTemperatureSensor temperatura2;
bool rele;
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 DHT1PIN 2
#define DHT2PIN 3
//DHT dht1 (DHT1PIN, DHTTYPE);
//DHT dht2 (DHT2PIN, DHTTYPE);
#define DHTTYPE DHT11
#define relayPin 2
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);
// Defined in thingProperties.h
initProperties();
// Connect to Arduino IoT Cloud
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
Serial.begin(9600);
Serial.println("DHTxx test!");
//dht1.begin();
// dht2.begin();
pinMode(2, OUTPUT);
/*
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
float h1 = dht1.readHumidity();
float t1 = dht1.readTemperature();
float h2 = dht2.readHumidity();
float t2 = dht2.readTemperature();
}
if (t1 > t2 + 4 )
{
digitalWrite(relayPin, HIGH);
Serial.println("Relay ON ");
}
else
{
if (digitalRead(relayPin) == HIGH && t1 < t2 + 2)
{
digitalWrite(relayPin, LOW);
Serial.println("Relay OFF ");
}
/*
Since Rele is READ_WRITE variable, onReleChange() is
executed every time a new value is received from IoT Cloud.
*/
void onReleChange() {
// Add your code here to act upon Rele change
}
@Idahowalker Can you help me with project first, please ?