Soil moisture

Wanting to set up multiple (4) analog soil sensors to arduino using gauges on dash board i am very poor with code have gotten by with old system by finding sketches online and here, to get by but mqtt not much out there yet other then basics not multiple sensors. Have tried many things and get errors with code here is a example
thanks Dave
#define CAYENNE_PRINT Serial // Comment this out to disable prints and save space
#include <CayenneMQTTEthernetW5500.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
#define SENSOR_PIN 1
#define VIRTUAL_CHANNEL 2

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

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

// This function is called at intervals to send sensor data to Cayenne.
CAYENNE_OUT(VIRTUAL_CHANNEL1)
{
Cayenne.virtualWrite(VIRTUAL_CHANNEL1, analogRead(SENSOR_PIN0));
}
//This function is called at intervals to send sensor datato Cayenne.
CAYENNE_OUT(VIRTUAL_CHANNEL2)
{
Cayenne.virtualWrite(VIRTUAL_CHANNEL2, analogRead(SENSOR_PIN1));

}

With this i get β€˜VIRTUAL_CHANNEL1’ Was not decareed in this scope

Hi
When you share the code, remember to delete your MQTT username, password and clientID. :grinning:

MQTT_USERNAME  = "username"
MQTT_PASSWORD  = "password"
MQTT_CLIENT_ID = "clientID"

You must write:

#define SENSOR_PIN0 A0
#define VIRTUAL_CHANNEL1 1
#define SENSOR_PIN1 A1
#define VIRTUAL_CHANNEL2 2

Not sure what you mean got the sketch and worked with one sensor tried to duplicate for a second and get error. I am not that familuar with code and have another problem CRS being 63 years old

Try this:

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

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

#define SENSOR_PIN0 A0
#define VIRTUAL_CHANNEL1 V1
#define SENSOR_PIN1 A1
#define VIRTUAL_CHANNEL2 V2

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

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

// This function is called at intervals to send sensor data to Cayenne.
CAYENNE_OUT(VIRTUAL_CHANNEL1)
{
  Cayenne.virtualWrite(VIRTUAL_CHANNEL1, analogRead(SENSOR_PIN0));
}
//This function is called at intervals to send sensor datato Cayenne.
CAYENNE_OUT(VIRTUAL_CHANNEL2)
{
  Cayenne.virtualWrite(VIRTUAL_CHANNEL2, analogRead(SENSOR_PIN1));
}
1 Like

So what goes into bottom virtual Write and cayenne out

hey thanks alot got it to compil ok will mess with it i am sure i will have more questions
Thanks so much
Dave

2 Likes