I uploaded the code but the value in the dashboard not changed, can any one help me please:
I checked it was connected to my wifi
Here is the code
#include "thingProperties.h"
#include <OneWire.h>
#include <DallasTemperature.h>
#define VREF 5.0 // analog reference voltage(Volt) of the ADC
#define SCOUNT 30 // sum of sample point
int analogBuffer[SCOUNT]; // store the analog value in the array, read from ADC
int analogBufferTemp[SCOUNT];
int analogBufferIndex = 0, copyIndex = 0;
float averageVoltage = 0;
// Pin definitions
#define PhSensorPin A0
#define TdsSensorPin A1
#define TurbiditySensorPin A2
#define SIG_PIN A3 // DS18B20 sensor pin
#define Offset 0.00 //deviation compensate
#define LED 13
#define samplingInterval 20
#define printInterval 800
#define ArrayLength 40 //times of collection
int pHArray[ArrayLength]; //Store the average value of the sensor feedback
int pHArrayIndex = 0;
int turbidityArray[ArrayLength]; // Store Turbidity sensor value
OneWire oneWire(SIG_PIN);
DallasTemperature ds(&oneWire);
void setup() {
// Initialize serial and wait for port to open:
Serial.begin(9600);
ds.begin();
// This delay gives the chance to wait for a Serial Monitor without blocking if none is found
delay(1500);
// Defined in thingProperties.h
initProperties();
// Connect to Arduino IoT Cloud
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
/*
The following function allows you to obtain more information
related to the state of network and IoT Cloud connection and errors
the higher number the more granular information you’ll get.
The default is 0 (only errors).
Maximum is 4
*/
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
}
void loop() {
ArduinoCloud.update();
// Your code here
}
/*
Since PHValue is READ_WRITE variable, onPHValueChange() is
executed every time a new value is received from IoT Cloud.
*/
int getMedianNum(int bArray[], int iFilterLen)
{
int bTab[iFilterLen];
for (byte i = 0; i < iFilterLen; i++)
bTab[i] = bArray[i];
int i, j, bTemp;
for (j = 0; j < iFilterLen - 1; j++)
{
for (i = 0; i < iFilterLen - j - 1; i++)
{
if (bTab[i] > bTab[i + 1])
{
bTemp = bTab[i];
bTab[i] = bTab[i + 1];
bTab[i + 1] = bTemp;
}
}
}
if ((iFilterLen & 1) > 0)
bTemp = bTab[(iFilterLen - 1) / 2];
else
bTemp = (bTab[iFilterLen / 2] + bTab[iFilterLen / 2 - 1]) / 2;
return bTemp;
}
double avergearray(int* arr, int number) {
int i;
int max, min;
double avg;
long amount = 0;
if (number <= 0) {
Serial.println("Error number for the array to avraging!/n");
return 0;
}
if (number < 5) { //less than 5, calculated directly statistics
for (i = 0; i < number; i++) {
amount += arr[i];
}
avg = amount / number;
return avg;
} else {
if (arr[0] < arr[1]) {
min = arr[0]; max = arr[1];
}
else {
min = arr[1]; max = arr[0];
}
for (i = 2; i < number; i++) {
if (arr[i] < min) {
amount += min; //arr<min
min = arr[i];
} else {
if (arr[i] > max) {
amount += max; //arr>max
max = arr[i];
} else {
amount += arr[i]; //min<=arr<=max
}
}//if
}//for
avg = (double)amount / (number - 2);
}//if
return avg;
}
float readAverageVoltage(int pin) {
int sum = 0;
for (int i = 0; i < 10; i++) {
sum += analogRead(pin);
delay(10);
}
return (float)sum / 10.0 * (5.0 / 1024.0);
}
void onPHValueChange() {
// Add your code here to act upon PHValue change
// Read pH Sensor
int pHArray[ArrayLength]; //Store the average value of the sensor feedback
int pHArrayIndex = 0;
static float pHValue, voltage;
pHArray[pHArrayIndex++] = analogRead(PhSensorPin);
if (pHArrayIndex == ArrayLength)pHArrayIndex = 0;
voltage = avergearray(pHArray, ArrayLength) * 5.0 / 1024;
pHValue = 3.5 * voltage + Offset;
}
/*
Since TdsValue is READ_WRITE variable, onTdsValueChange() is
executed every time a new value is received from IoT Cloud.
*/
void onTdsValueChange() {
float temperature = ds.getTempCByIndex(0);
for (copyIndex = 0; copyIndex < SCOUNT; copyIndex++)
analogBufferTemp[copyIndex] = analogBuffer[copyIndex];
averageVoltage = getMedianNum(analogBufferTemp, SCOUNT) * (float)VREF / 1024.0; // read the analog value more stable by the median filtering algorithm, and convert to voltage value
float compensationCoefficient = 1.0 + 0.02 * (temperature - 25.0); //temperature compensation formula: fFinalResult(25^C) = fFinalResult(current)/(1.0+0.02*(fTP-25.0));
float compensationVolatge = averageVoltage / compensationCoefficient; //temperature compensation
tdsValue = (133.42 * compensationVolatge * compensationVolatge * compensationVolatge - 255.86 * compensationVolatge * compensationVolatge + 857.39 * compensationVolatge) * 0.5; //convert voltage value to tds value
}
/*
Since AverageTurbidityVoltage is READ_WRITE variable, onAverageTurbidityVoltageChange() is
executed every time a new value is received from IoT Cloud.
*/
void onAverageTurbidityVoltageChange() {
// Add your code here to act upon AverageTurbidityVoltage change
// Read Turbidity Sensor
float averageTurbidityVoltage = readAverageVoltage(TurbiditySensorPin);
}
/*
Since Temperature is READ_WRITE variable, onTemperatureChange() is
executed every time a new value is received from IoT Cloud.
*/
void onTemperatureChange() {
ds.requestTemperatures();
float temperature = ds.getTempCByIndex(0);
}