send data to from arduino to nodemcu, data is from a turbidty sensor , i am receiving the vales on the nodemcu serial monitor but nothing on blynk 2.0
#define BLYNK_DEVICE_NAME "ds18b20"
#define BLYNK_AUTH_TOKEN "emExKG6X2o7bmg8JSzR4JRVyAUFH1-9C"
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp8266.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Wire.h>
#define ONE_WIRE_BUS D2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
#define TdsSensorPin A0
#define VREF 3.3 // 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,tdsValue = 0,temperature = 25;
char auth[] = "emExKG6X2o7bmg8JSzR4JRVyAUFH1-9C";
char ssid[] = "*********"; // type your wifi name
char pass[] = "*********"; // type your wifi password
BlynkTimer timer;
//String voltage;
void sendSensor()
{
// Request temperature to all devices on the data line
sensors.requestTemperatures();
Serial.print("Celsius temperature: ");
//We can connect more than one IC on the same data wire. 0 refers to the first IC on the wire
Serial.print(sensors.getTempCByIndex(0));
Serial.print(" - Fahrenheit temperature: ");
Serial.println(sensors.getTempFByIndex(0));
int tempC=sensors.getTempCByIndex(0);
int tempF=sensors.getTempFByIndex(0);
delay(1000);
static unsigned long analogSampleTimepoint = millis();
if(millis()-analogSampleTimepoint > 40U) //every 40 milliseconds,read the analog value from the ADC
{
analogSampleTimepoint = millis();
analogBuffer[analogBufferIndex] = analogRead(TdsSensorPin); //read the analog value and store into the buffer
analogBufferIndex++;
if(analogBufferIndex == SCOUNT)
analogBufferIndex = 0;
}
static unsigned long printTimepoint = millis();
if(millis()-printTimepoint > 800U)
{
printTimepoint = millis();
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
//Serial.print("voltage:");
//Serial.print(averageVoltage,2);
//Serial.print("V ");
Serial.print("TDS Value:");
Serial.print(tdsValue,0);
Serial.println("ppm");
}
//int sdata = voltage.toInt();
//Serial.print("voltage= ");
//Serial.println(sdata);
//Blynk.virtualWrite(V3,sdata);
//voltage ="";
//delay(500);
// You can send any value at any time.
// Please don't send more that 10 values per second.
Blynk.virtualWrite(V1, tempC);
Blynk.virtualWrite(V2, tdsValue);
//Blynk.virtualWrite(V3,sdata);
}
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;
}
void setup()
{
Serial.begin(9600);
sensors.begin();
pinMode(TdsSensorPin,INPUT);
Blynk.begin(auth, ssid, pass);
timer.setInterval(1000L, sendSensor);
while (!Serial) {
;
}
}
void loop()
{
if (Serial.available()){
char data = Serial.read();
Serial.write(Serial.read());
//voltage = voltage + data;
}
sendSensor();
Blynk.run();
timer.run();
}