Hi, need help to setup voltage monitor. I use 4 voltage sensor conected to analog pin 2 to pin 5 and measured 4 diferent voltage., and show up on cayenne dashboard. But the problem is the witdget seem show the same pin. Can u please help me…
> Blockquote
// This example shows how to connect to Cayenne using an Ethernet W5100 shield and send/receive sample data.
// #define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial
#include <CayenneMQTTEthernet.h>
#define analogInput2 2
#define analogInput3 3
#define analogInput4 4
#define analogInput5 5
// Volmeter
int analogInput = A2 - A5;
float vout = 0.0;
float vin = 0.0;
float R1 = 30000.0; //
float R2 = 7500.0; //
int value = 0;
// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = ".................................................";
char password[] = "......................................";
char clientID[] = ".................................";
unsigned long lastMillis = 0;
void setup() {
Serial.begin(9600);
Serial.print("DC VOLTMETER");
pinMode(analogInput2, INPUT);
pinMode(analogInput3, INPUT);
pinMode(analogInput4, INPUT);
pinMode(analogInput5, INPUT);
Cayenne.begin(username, password, clientID);
}
void loop() {
Cayenne.loop();
//Publish data every 1 seconds (1000 milliseconds). Change this value to publish at a different interval.
if (millis() - lastMillis > 1000) {
lastMillis = millis();
//Write data to Cayenne here. This example just sends the current uptime in milliseconds.
Cayenne.virtualWrite(2, vin , "voltage", "v");
Cayenne.virtualWrite(3, vin , "voltage", "v");
Cayenne.virtualWrite(4, vin , "voltage", "v");
Cayenne.virtualWrite(5, vin , "voltage", "v");
//Some examples of other functions you can use to send data.
//Cayenne.celsiusWrite(1, 22.0);
//Cayenne.luxWrite(2, 700);
//Cayenne.virtualWrite(3, 50, TYPE_PROXIMITY, UNIT_CENTIMETER);
// read the value at analog input
//Voltmeter
value = analogRead(analogInput);
vout = (value * 5.0) / 1024.0; // see text
vin = vout / (R2 / (R1 + R2));
if (vin < 0.50)
{
vin = 0.0;
}
}
}
// Volmeter
int analogInput = A2 - A5;
float vout = 0.0;
float vin = 0.0;
float R1 = 30000.0; //
float R2 = 7500.0; //
int value = 0;
// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username = “xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx”;
char password = “xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx”;
char clientID = “xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx”;
//Publish data every 1 seconds (1000 milliseconds). Change this value to publish at a different interval.
if (millis() - lastMillis > 1000) {
lastMillis = millis();
//Write data to Cayenne here. This example just sends the current uptime in milliseconds.
Cayenne.virtualWrite(2, vin , “voltage”, “v”);
Cayenne.virtualWrite(3, vin , “voltage”, “v”);
Cayenne.virtualWrite(4, vin , “voltage”, “v”);
Cayenne.virtualWrite(5, vin , “voltage”, “v”);
//Some examples of other functions you can use to send data. //Cayenne.celsiusWrite(1, 22.0); //Cayenne.luxWrite(2, 700); //Cayenne.virtualWrite(3, 50, TYPE_PROXIMITY, UNIT_CENTIMETER);
// read the value at analog input
//Voltmeter
value = analogRead(analogInput);
vout = (value * 5.0) / 1024.0; // see text
vin = vout / (R2 / (R1 + R2));
if (vin < 0.05)
{
vin = 0.0;
}
}
}
CAYENNE_OUT(2) // Get current value of analog pin 2
{
Cayenne.virtualWrite(analogInput2, vin);
}
CAYENNE_OUT(3) // Get current value of analog pin 3
{
Cayenne.virtualWrite(analogInput3, vin);
}
CAYENNE_OUT(4) // Get current value of analog pin 4
{
Cayenne.virtualWrite(analogInput4, vin);
}
CAYENNE_OUT(5) // Get current value of analog pin 5
{
Cayenne.virtualWrite(analogInput5, vin);
}