So I am trying to hook up an Arduino with a 4 relay board
I can (almost) copy and past the example for a single relay…
but it seems that something is missing for adding more than 1
any chance of getting a sample for 2-4 relays?
have a look at this Adding a New Device using MQTT and understand how it works. then you can do anything with cayenne,
yea… I’ve tried to read all that… too much info in a somewhat confusing and over whelming format…
while I wish I had the time to sort thru it and be able to do “anything with cayenne” right now what I need is to be able to do one thing, because this is just a small part of a much larger project…
if someone would take this: Cayenne-MQTT-Arduino/RelaySwitch.ino at master · myDevicesIoT/Cayenne-MQTT-Arduino · GitHub
and throw in for a second relay… I’d understand enough to put in 2 more and be able to turn the lights back on in my garage… they were hooked to a RPi and Cayenne but the RPI died… and I’m trying to clean up the garage
i hope the below code is not confusing and over whelming .
#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[] = "MQTT_USERNAME";
char password[] = "MQTT_PASSWORD";
char clientID[] = "CLIENT_ID";
#define VIRTUAL_CHANNEL1 1
#define ACTUATOR_PIN1 4
#define VIRTUAL_CHANNEL2 2
#define ACTUATOR_PIN2 5
#define VIRTUAL_CHANNEL3 3
#define ACTUATOR_PIN3 6
#define VIRTUAL_CHANNEL4 4
#define ACTUATOR_PIN4 7
void setup()
{
Serial.begin(9600);
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();
}
// This function is called when data is sent from Cayenne.
CAYENNE_IN(VIRTUAL_CHANNEL1)
{
// Write value to turn the relay switch on or off. This code assumes you wire your relay as normally open.
if (getValue.asInt() == 0) {
digitalWrite(ACTUATOR_PIN1, HIGH);
}
else {
digitalWrite(ACTUATOR_PIN1, LOW);
}
}
CAYENNE_IN(VIRTUAL_CHANNEL2)
{
// Write value to turn the relay switch on or off. This code assumes you wire your relay as normally open.
if (getValue.asInt() == 0) {
digitalWrite(ACTUATOR_PIN2, HIGH);
}
else {
digitalWrite(ACTUATOR_PIN2, LOW);
}
}CAYENNE_IN(VIRTUAL_CHANNEL3)
{
// Write value to turn the relay switch on or off. This code assumes you wire your relay as normally open.
if (getValue.asInt() == 0) {
digitalWrite(ACTUATOR_PIN3, HIGH);
}
else {
digitalWrite(ACTUATOR_PIN3, LOW);
}
}
CAYENNE_IN(VIRTUAL_CHANNEL4)
{
// Write value to turn the relay switch on or off. This code assumes you wire your relay as normally open.
if (getValue.asInt() == 0) {
digitalWrite(ACTUATOR_PIN4, HIGH);
}
else {
digitalWrite(ACTUATOR_PIN4, LOW);
}
}
Thank you very much… I will be re-reading (and probably re-re-re-reading ) the article later.
but as I said earlier… way too much on my plate right now…
the example I pointed to was just a hair away from being enough info… what you posted makes sense and about what I expected…
once again, thanks…