How to assemble?

In my project i have a lot of captor.
How to assemble him ?

Example : (Thermometer + Lamp

#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 = “//”;
char password = “//”;
char clientID = “//”;

#define SENSOR_PIN 0
#define VIRTUAL_CHANNEL 3
#define VIRTUAL_CHANNEL 2
#define ACTUATOR_PIN 2 // 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 at intervals to send sensor data to Cayenne. //Lamp
CAYENNE_OUT(VIRTUAL_CHANNEL)
{
Cayenne.virtualWrite(VIRTUAL_CHANNEL, analogRead(SENSOR_PIN));
}

// This function is called when data is sent from Cayenne. //Thermometer
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);
}

I try like this but it does’nt work.

change this :

to

#define VIRTUAL_CHANNEL_0 3

#define VIRTUAL_CHANNEL_1 2

in your entire code

1 Like

Thanks you man ! ^^

1 Like

:frowning:

Whats is the problem…?

just remove that line CAYENNE_LOG

I’m triying


Mhh… :confused:

made changes to your code.

 #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[] = "";
char password[] = "";
char clientID[] = "";

#define SENSOR_PIN 0
#define VIRTUAL_CHANNEL_1 3
#define VIRTUAL_CHANNEL_2 2
#define ACTUATOR_PIN 2 // 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 at intervals to send sensor data to Cayenne. //Lamp
CAYENNE_OUT(VIRTUAL_CHANNEL_1)
{
Cayenne.virtualWrite(VIRTUAL_CHANNEL_1, analogRead(SENSOR_PIN));
}

// This function is called when data is sent from Cayenne. //Thermometer
CAYENNE_IN(VIRTUAL_CHANNEL_2)
{
int value = getValue.asInt();
digitalWrite(ACTUATOR_PIN, value);
}

Thx I’m triying

EDIT : Its work ! Thx ^^

I took the same example to add a actuator but i have a conflict whit my lamp.
When i turn on my new actuator (A fan), my lamp turn on and my fan don’t on.
When i turn on my lamp, my lamp on correctly.

can you post the code.

#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[] = "//";
char password[] = "//";
char clientID[] = "//";

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

#define VIRTUAL_CHANNEL_1 3
#define SENSOR_PIN 3

#define VIRTUAL_CHANNEL_2 2
#define ACTUATOR_PIN 2 // 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 at intervals to send sensor data to Cayenne. //Thermo
CAYENNE_OUT(VIRTUAL_CHANNEL_1)
{
Cayenne.virtualWrite(VIRTUAL_CHANNEL_1, analogRead(SENSOR_PIN));
}

// This function is called when data is sent from Cayenne. //Lampe
CAYENNE_IN(VIRTUAL_CHANNEL_2)
{
int value = getValue.asInt();
digitalWrite(ACTUATOR_PIN, value);
}
// This function is called when data is sent from Cayenne. //Ventilateur
CAYENNE_IN(VIRTUAL_CHANNEL_4)
{
  int value = getValue.asInt();
  digitalWrite(ACTUATOR_PIN, value);
}

give this a try

#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[] = "//";
char password[] = "//";
char clientID[] = "//";

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

#define VIRTUAL_CHANNEL_1 3
#define SENSOR_PIN 3

#define VIRTUAL_CHANNEL_2 2
#define ACTUATOR_PIN_2 2 // Do not use digital pins 0 or 1 since those conflict with the use of Serial.


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

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

// This function is called at intervals to send sensor data to Cayenne. //Thermo
CAYENNE_OUT(VIRTUAL_CHANNEL_1)
{
Cayenne.virtualWrite(VIRTUAL_CHANNEL_1, analogRead(SENSOR_PIN));
}

// This function is called when data is sent from Cayenne. //Lampe
CAYENNE_IN(VIRTUAL_CHANNEL_2)
{
int value= getValue.asInt();
digitalWrite(ACTUATOR_PIN_1, value);
}
// This function is called when data is sent from Cayenne. //Ventilateur
CAYENNE_IN(VIRTUAL_CHANNEL_4)
{
  int value_1 = getValue.asInt();
  digitalWrite(ACTUATOR_PIN_2, value_1);
}

Thx :yum:
Good bye ^^

but i hope you are not just copying and pasting the code. try to understand and learn from the mistake you have made till now. anyways best of luck with your project.

1 Like

Don’t worry, I studied and understood

1 Like