Help with panel and relays

Hello community.
I’m having some problems.
1- whenever the arduino is connected it ends up keeping the relays connected … and thus flooding my greenhouse.
2 - whenever I update the browser or enter and exit the application, the information in the panel is not the same as in the relays. always returns to its initial state.

Thank you for your help. always evolving

#define CAYENNE_PRINT Serial  // Comment this out to disable prints and save space
#include <CayenneMQTTEthernet.h>
#include <DHT.h>
#include "DHT.h"
#define DHT1PIN A1
#define DHT1TYPE DHT11
DHT dht1(DHT1PIN, DHT1TYPE);

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "  ";
char password[] = "   ";
char clientID[] = "  ";

#define VIRTUAL_CHANNEL2 2// relè
#define VIRTUAL_CHANNEL3 3// relè
#define VIRTUAL_CHANNEL4 4// relè
#define VIRTUAL_CHANNEL5 5// relè

#define ACTUATOR_PIN1 2// relè pin
#define ACTUATOR_PIN2 3// relè pin
#define ACTUATOR_PIN3 4// relè pin
#define ACTUATOR_PIN4 5// relè pin

#define SENSOR_PIN0 A0
#define VIRTUAL_CHANNEL0 0

void setup()
{
  Serial.begin(9600);
  dht1.begin();
  // set digital pin to output
  pinMode(ACTUATOR_PIN1, OUTPUT);
  pinMode(ACTUATOR_PIN2, OUTPUT);
  pinMode(ACTUATOR_PIN3, OUTPUT);
  pinMode(ACTUATOR_PIN4, OUTPUT);
  Cayenne.begin(username, password, clientID);
}

void loop()
{
  Cayenne.loop();
}
 float h1 = dht1.readHumidity();
 float t1 = dht1.readTemperature();
 
 CAYENNE_OUT(VIRTUAL_CHANNEL0)
{
	Cayenne.virtualWrite(VIRTUAL_CHANNEL0, analogRead(SENSOR_PIN0));
}
 

CAYENNE_IN(VIRTUAL_CHANNEL2)
{
	if (getValue.asInt() == 0) {
		digitalWrite(ACTUATOR_PIN1, HIGH);
	}
	else {
		digitalWrite(ACTUATOR_PIN1, LOW);
	}
}
	CAYENNE_IN(VIRTUAL_CHANNEL3)
{
		if (getValue.asInt() == 0) {
		digitalWrite(ACTUATOR_PIN2, HIGH);
	}
	else {
		digitalWrite(ACTUATOR_PIN2, LOW);
	}
}
CAYENNE_IN(VIRTUAL_CHANNEL4)
{
		if (getValue.asInt() == 0) {
		digitalWrite(ACTUATOR_PIN3, HIGH);
	}
	else {
		digitalWrite(ACTUATOR_PIN3, LOW);

	}
}

CAYENNE_IN(VIRTUAL_CHANNEL5)
{
		if (getValue.asInt() == 0) {
		digitalWrite(ACTUATOR_PIN4, HIGH);
	}
	else {
		digitalWrite(ACTUATOR_PIN4, LOW);

	}
}
 CAYENNE_OUT(V6)
{
  Cayenne.virtualWrite(V6, dht1.readTemperature());
}

CAYENNE_OUT(V7)
{
  Cayenne.virtualWrite(V7, dht1.readHumidity());
}

did you mean that whenever the arduino restart due to power cutoff, the relay turns ON. so in your setup make your relay OFF,

we are aware of this bug and we are working on it, till then you can send the relay state to cayenne from the arduino.

Hello Shramiksalgankar. So whenever a power outage occurs, when the arduino reconnects it triggers all the relays, thus flooding my entire planted area and adding a lot of my water.

Can you explain me better how to solve this? because I already inverted the logic of it, and even then whenever it restarts it ends up getting connected … would it be something in my writing ??

this project is too big. it would be really cool I could finish without the errors to show everyone.

can you share the code you are using.

it’s right up there.

Add this in void setup digitalWrite(ACTUATOR_PIN3, HIGH); so it turns relay OFF every time arduino reboots.

I did not understand where to write this.

void setup()
{
  Serial.begin(9600);
  dht1.begin();
  // set digital pin to output
  pinMode(ACTUATOR_PIN1, OUTPUT);
  pinMode(ACTUATOR_PIN2, OUTPUT);
  pinMode(ACTUATOR_PIN3, OUTPUT);
  pinMode(ACTUATOR_PIN4, OUTPUT);
  Cayenne.begin(username, password, clientID);
digitalWrite(ACTUATOR_PIN3, HIGH); // turn off relay
}

hey, I had tested put LOW in the same way. but it actually had to be HIGH. Now it’s always off when the internet falls. It turned out to be flimsy.
now the panel is refreshed. I’ll sort it here and post the code.

very thoughtful

it depends on your connection, whether you have used NC or NO .

//Bibliotecas incluidas
#include <CayenneMQTTEthernet.h> //Cayenne
#define CAYENNE_PRINT Serial     // Ativa porta serial arduino/pc
#include <DHT.h>  //DHT11 sensor de temperatura e umidade do ar
#include "DHT.h"  //DHT11 sensor de temperatura e umidade do ar                             
// Informacoes da placa para conectar ao cayenne
.
.
.

//dados do sensor do ar 
#define DHTPIN A1
#define DHTTYPE DHT11   
DHT dht(DHTPIN, DHTTYPE);
//Abre canais virtuais no cayenne ?????
#define VIRTUAL_CHANNEL2 2   //sensor temperatura e umidade do ar
#define VIRTUAL_CHANNEL3 3   //sensor umidade do solo
#define VIRTUAL_CHANNEL4 4   //sensor porta
#define VIRTUAL_CHANNEL5 5   //sensor agua
#define VIRTUAL_CHANNEL6 6   //sensor adubo
#define VIRTUAL_CHANNEL7 7   //atuador ventilacao
#define VIRTUAL_CHANNEL8 8   //atuador agua
#define VIRTUAL_CHANNEL9 9   //atuador adubo
//define portas no arduino 
#define umidade_solo A3      //sensor umidade do solo
#define mantem_ligado 2      //mantem ligado para os botoes
#define sensor_porta 3       //sensor porta
#define sensor_agua 4        //sensor agua
#define sensor_adubo 5       //sensor adubo
#define atuador_ventilacao 6 //atuador ventilacao
#define atuador_agua 7       //atuador agua
#define atuador_adubo 8      //atuador adubo
#define atuador_reserva 9    //atuador adubo

void setup()

{ Serial.begin(9600);
  dht.begin();                            //sensor temperatura e umidade do ar
	pinMode(umidade_solo, INPUT);           //sensor umidade do solo
	pinMode(sensor_porta, INPUT);           //sensor porta
	pinMode(sensor_agua, INPUT);            //sensor agua
	pinMode(sensor_adubo, INPUT);           //sensor adubo
	pinMode(atuador_ventilacao, OUTPUT);    //atuador ventilacao
	pinMode(atuador_agua, OUTPUT);          //atuador agua
	pinMode(atuador_adubo, OUTPUT);         //atuador adubo
  pinMode(atuador_reserva, OUTPUT);       //atuador reserva
	pinMode(mantem_ligado, OUTPUT);         // mantem botao ligado
  digitalWrite(atuador_ventilacao, HIGH); //mandem os reles desligados
  digitalWrite(atuador_agua, HIGH);       //mandem os reles desligados
  digitalWrite(atuador_adubo, HIGH);      //mandem os reles desligados
  digitalWrite(atuador_reserva, HIGH);    //mandem os reles desligados
	Cayenne.begin(username, password, clientID);
}

void loop()
{
  Cayenne.loop();
}
  float h1 = dht.readHumidity();
  float t1 = dht.readTemperature();

CAYENNE_OUT(V0)
{
  Cayenne.virtualWrite(V0, dht.readTemperature());
}
CAYENNE_OUT(V1)
{
  Cayenne.virtualWrite(V1, dht.readHumidity());
}
CAYENNE_OUT(V2)
{
	Cayenne.virtualWrite(V2, analogRead(umidade_solo));
} 
CAYENNE_OUT(V3)
{
	Cayenne.virtualWrite(V3, digitalRead(sensor_porta));
}
CAYENNE_OUT(V4)
{
	Cayenne.virtualWrite(V4, digitalRead(sensor_agua));
} 
CAYENNE_OUT(V5)
{
	Cayenne.virtualWrite(V5, digitalRead(sensor_adubo));
} 
 
CAYENNE_IN(V6)
{
	if (getValue.asInt() == 0) {
		digitalWrite(atuador_agua, HIGH);
	}
	else {
		digitalWrite(atuador_agua, LOW);
	}
}
	CAYENNE_IN(V7)
{
		if (getValue.asInt() == 0) {
		digitalWrite(atuador_adubo, HIGH);
	}
	else {
		digitalWrite(atuador_adubo, LOW);
	}
} 
CAYENNE_IN(V8)
{
	if (getValue.asInt() == 0) {
		digitalWrite(atuador_ventilacao, HIGH);
	}
	else {
		digitalWrite(atuador_ventilacao, LOW);
	}
}
	CAYENNE_IN(V9)
{
		if (getValue.asInt() == 0) {
		digitalWrite(atuador_reserva, HIGH);
	}
	else {
		digitalWrite(atuador_reserva, LOW);
	}
}

in this my project has.
4 relays, a thermometer and air hygrometer, soil moisture.
next to the panel I have 2 push buttons, where I activate manually. also has the oven door sensor. I’m going to run it for a few days to incorporate the other parts.
Thank you for your help.

how going your project?

which project are you referring? i have alot going on here.