Hi guys. Good morning.
I would like know if have a custom code to add a PH sensor in cayenne with arduino.
Thank you…
Hi guys. Good morning.
I would like know if have a custom code to add a PH sensor in cayenne with arduino.
Thank you…
Hi
Do you have any sample code with output on serial monitor?
What PH sensor do you have?
Hi.
Yes, I´m utilizing this code
/*
Editor : YouYou
Date : 2013.10.21
Ver : 0.1
Product: pH meter
SKU : SEN0161
*/
#define SensorPin 0 //pH meter Analog output to Arduino Analog Input 0
#define Offset 0.00 //deviation compensate
unsigned long int avgValue; //Store the average value of the sensor feedback
void setup()
{
pinMode(13,OUTPUT);
Serial.begin(9600);
Serial.println(“Ready”); //Test the serial monitor
}
void loop()
{
int buf[10]; //buffer for read analog
for(int i=0;i<10;i++) //Get 10 sample value from the sensor for smooth the value
{
buf[i]=analogRead(SensorPin);
delay(10);
}
for(int i=0;i<9;i++) //sort the analog from small to large
{
for(int j=i+1;j<10;j++)
{
if(buf[i]>buf[j])
{
int temp=buf[i];
buf[i]=buf[j];
buf[j]=temp;
}
}
}
avgValue=0;
for(int i=2;i<8;i++) //take the average value of 6 center sample
avgValue+=buf[i];
float phValue=(float)avgValue5.0/1024/6; //convert the analog into millivolt
phValue=3.5phValue+Offset; //convert the millivolt into pH value
Serial.print(" pH:“);
Serial.print(phValue,2);
Serial.println(” ");
digitalWrite(13, HIGH);
delay(800);
digitalWrite(13, LOW);
}
And to add in cayenne I was using this code!
/*
Cayenne Ethernet Example
This sketch connects to the Cayenne server using an Arduino Ethernet Shield W5100
and runs the main communication loop.
The Cayenne Library is required to run this sketch. If you have not already done so you can install it from the Arduino IDE Library Manager.
Steps:
- Set the token variable to match the Arduino token from the Dashboard.
- Compile and upload this sketch.
For Cayenne Dashboard widgets using digital or analog pins this sketch will automatically
send data on those pins to the Cayenne server. If the widgets use Virtual Pins, data
should be sent to those pins using virtualWrites. Examples for sending and receiving
Virtual Pin data are under the Basics folder.
*/
//#define CAYENNE_DEBUG // Uncomment to show debug messages
#define CAYENNE_PRINT Serial // Comment this out to disable prints and save space
include <CayenneEthernet.h>
#define SensorPin 1 //pH meter Analog output to Arduino Analog Input 0
#define Offset 0.00 //deviation compensate
unsigned long int avgValue; //Store the average value of the sensor feedback
// Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
char token = “token”;
void setup()
{
Serial.begin(9600);
Cayenne.begin(token);
pinMode(13,OUTPUT);
Serial.begin(9600);
Serial.println(“Ready”); //Test the serial monitor
}
void loop()
{
Cayenne.run();
int buf[10]; //buffer for read analog
for(int i=0;i<10;i++) //Get 10 sample value from the sensor for smooth the value
{
buf[i]=analogRead(SensorPin);
delay(10);
}
for(int i=0;i<9;i++) //sort the analog from small to large
{
for(int j=i+1;j<10;j++)
{
if(buf[i]>buf[j])
{
int temp=buf[i];
buf[i]=buf[j];
buf[j]=temp;
}
}
}
avgValue=0;
for(int i=2;i<8;i++) //take the average value of 6 center sample
avgValue+=buf[i];
float phValue=(float)avgValue5.0/1024/6; //convert the analog into millivolt
phValue=3.5phValue+Offset; //convert the millivolt into pH value
Serial.print(" pH:“);
Serial.print(phValue,2);
Serial.println(” ");
digitalWrite(13, HIGH);
delay(800);
digitalWrite(13, LOW);
}
But when I access my dashboard, I get absurd values.
I’m using a Millivoltmeter V1.0
Try this.
//#define CAYENNE_DEBUG // Uncomment to show debug messages
#define CAYENNE_PRINT Serial // Comment this out to disable prints and save space
#include <CayenneEthernet.h>
#define SensorPin 0 //pH meter Analog output to Arduino Analog Input 0
#define Offset 0.00 //deviation compensate
unsigned long int avgValue; //Store the average value of the sensor feedback
float phValue;
// Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
char token[] = "token";
void setup()
{
Serial.begin(9600);
Cayenne.begin(token);
}
void loop()
{
Cayenne.run();
int buf[10]; //buffer for read analog
for(int i=0;i<10;i++) //Get 10 sample value from the sensor for smooth the value
{
buf[i]=analogRead(SensorPin);
delay(10);
}
for(int i=0;i<9;i++) //sort the analog from small to large
{
for(int j=i+1;j<10;j++)
{
if(buf[i]>buf[j])
{
int temp=buf[i];
buf[i]=buf[j];
buf[j]=temp;
}
}
}
avgValue=0;
for(int i=2;i<8;i++) //take the average value of 6 center sample
avgValue+=buf[i];
phValue=(float)avgValue*5.0/1024/6; //convert the analog into millivolt
phValue=3.5*phValue+Offset; //convert the millivolt into pH value
}
CAYENNE_OUT(V0)
{
Cayenne.virtualWrite(V0, phValue);
}
Yes, Cayenne can transfer any value.
Do you have the sensor connected correctly?
I tested it on my Arduino and it works right.
Yes. I check the connections, and give me again the same values.
what example do you choose?
And what data sensor do you use?
Ok. i’m appreciate. Thank you so much.