How to add second relay?

My project is not arduino. One to trigger 4 relays work normal, when I switched to MQTT I can not add the second trigger (relay). We advise you to add it first using a sketch or code, but I have questions about how to write the code for the next triggers together. In the middle code only the first relay, how do I put 4 or more?

#define CAYENNE_PRINT Serial // Comment this out to disable prints and save space
#include <CayenneMQTTEthernet.h>

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username = “6xxxxxx”;
char password = “8xxxxxx”;
char clientID = “7axxxxxx”;

#define VIRTUAL_CHANNEL 8
#define ACTUATOR_PIN 4 // Do not use digital pins 0 or 1 since those conflict with the use of Serial.

void setup()
{
Serial.begin(9600);
pinMode(ACTUATOR_PIN , OUTPUT);
Cayenne.begin(username, password, clientID);

}

void loop()
{
Cayenne.loop();
}

// This function is called when data is sent from Cayenne.
CAYENNE_IN(VIRTUAL_CHANNEL)
{
int value = getValue.asInt();
CAYENNE_LOG(“Channel %d, pin %d, value %d”, VIRTUAL_CHANNEL, ACTUATOR_PIN , value);
// Write the value received to the digital pin.
digitalWrite(ACTUATOR_PIN , value);
}

#define CAYENNE_PRINT Serial // Comment this out to disable prints and save space
#include <CayenneMQTTEthernet.h>

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = “6xxxxxx”;
char password[] = “8xxxxxx”;
char clientID[] = “7axxxxxx”;

#define VIRTUAL_CHANNEL 8
#define ACTUATOR_PIN 4
#define VIRTUAL_CHANNEL_1 9
#define ACTUATOR_PIN_1 5    // Do not use digital pins 0 or 1 since those conflict with the use of Serial.

void setup()
{
Serial.begin(9600);
pinMode(ACTUATOR_PIN , OUTPUT);
pinMode(ACTUATOR_PIN_1 , OUTPUT);
Cayenne.begin(username, password, clientID);

}

void loop()
{
Cayenne.loop();
}

// This function is called when data is sent from Cayenne.
CAYENNE_IN(VIRTUAL_CHANNEL)
{
int value = getValue.asInt();
CAYENNE_LOG(“Channel %d, pin %d, value %d”, VIRTUAL_CHANNEL, ACTUATOR_PIN , value);
// Write the value received to the digital pin.
digitalWrite(ACTUATOR_PIN , value);
}
CAYENNE_IN(VIRTUAL_CHANNEL_1)
{
int value_1 = getValue.asInt();
CAYENNE_LOG(“Channel %d, pin %d, value %d”, VIRTUAL_CHANNEL, ACTUATOR_PIN , value);
// Write the value received to the digital pin.
digitalWrite(ACTUATOR_PIN_1 , value_1);
}

Muito obrigado pela ajuda!!

Friend, when I order compile in Arduino this line is highlighted and shows an error:

CAYENNE_LOG(“Channel %d, pin %d, value %d”, VIRTUAL_CHANNEL, ACTUATOR_PIN , value);

exit status 1
stray ‘\342’ in program

remove that line and upload.

Removed the line, made sending the code without error, but the devices are not triggered!

How can I do now?!

did you add a custom button on the cayenne dashboard with appropriate channel.

Actually the channel was wrong on the panel button. Thank you very much

1 Like