How to add second relay?


#1

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);
}


#2
#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);
}

#3

Muito obrigado pela ajuda!!


#4

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


#5

remove that line and upload.


#6

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

How can I do now?!


#7

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


#8

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