Hi everyone, newbie here...calling for help hh cuz I struggling with the programming. The problem is sensor data from arduino uno can't reach node mcu esp8266 and not showing in blynk console/app. The sensor showing on the LCD was ok, but the blynk app just dont give any response. Thanks for helping me
Here is the code
Arduino part
#include <OneWire.h>
#include <DallasTemperature.h>
#include <LiquidCrystal.h>
#include <SoftwareSerial.h>
SoftwareSerial nodemcu(11,12); //11 is tX and 12 is rX
// 16x2 LCD
#define rs 10
#define en 9
#define d4 6
#define d5 5
#define d6 4
#define d7 3
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
#define PIN_A1 (15)
namespace pin {
const byte tds_sensor = PIN_A1;
const byte one_wire_bus = 7; // Dallas Temperature Sensor
}
int sensor1 = PIN_A1; //sdata1 tds/ec
int sensor2 = PIN_A1; //sdata2 EC
int sensor3 = 7; //sdata3 temp
int sdata1 = 0; // sensor1 data
int sdata2 = 0; // sensor2 data
int sdata3 = 0; // sensor3 data
String cdata; // complete data, consisting of sensors values
namespace device {
float aref = 4.3;
}
namespace sensor {
float rawEc = 0;
unsigned int tds = 0;
float waterTemp = 0;
float ecCalibration = 1;
}
OneWire oneWire(pin::one_wire_bus);
DallasTemperature dallasTemperature(&oneWire);
void setup() {
Serial.begin(9600); // Dubugging on hardware Serial 0
nodemcu.begin(9600);
lcd.begin(16, 2);
dallasTemperature.begin();
pinMode(sensor1, INPUT);
pinMode(sensor2, INPUT);
}
void loop() {
readTdsQuick();
delay(1000);
}
void readTdsQuick() {
dallasTemperature.requestTemperatures();
sensor::waterTemp = dallasTemperature.getTempCByIndex(0);
float rawEc = analogRead(pin::tds_sensor) * device::aref / 1024.0; // read the analog value more stable by the median filtering algorithm, and convert to voltage value
float temperatureCoefficient = 1.0 + 0.02 * (sensor::waterTemp - 25.0); // temperature compensation formula: fFinalResult(25^C) = fFinalResult(current)/(1.0+0.02*(fTP-25.0));
sensor::ec = (rawEc / temperatureCoefficient) * sensor::ecCalibration; // temperature and calibration compensation
sensor::tds = (133.42 * pow(sensor::ec, 3) - 255.86 * sensor::ec * sensor::ec + 857.39 * sensor::ec) * 0.5; //convert voltage value to tds value
Serial.print(F("TDS:")); Serial.println(sensor::tds);
Serial.print(F("EC:")); Serial.println(sensor::ec, 2);
Serial.print(F("Temperature:")); Serial.println(sensor::waterTemp,2);
lcd.clear();
lcd.print("TDS EC Temp");
lcd.setCursor(0,1);
lcd.print(sensor::tds);
lcd.setCursor(5,1);
lcd.print(sensor::ec, 2);
lcd.setCursor(11,1);
lcd.print(sensor::waterTemp,2);
dallasTemperature.requestTemperatures();
sdata3 = dallasTemperature.getTempCByIndex(0);
float rawEc = analogRead(pin::sdata1) * device::aref / 1024.0; // read the analog value more stable by the median filtering algorithm, and convert to voltage value
float temperatureCoefficient = 1.0 + 0.02 * (sdata3 - 25.0); // temperature compensation formula: fFinalResult(25^C) = fFinalResult(current)/(1.0+0.02*(fTP-25.0));
sdata2 = (rawEc / temperatureCoefficient) * sdata2; // temperature and calibration compensation
sdata3 = (133.42 * pow(sdata2, 3) - 255.86 * sdata2 * sdata2 + 857.39 * sdata2) * 0.5; //convert voltage value to tds value
Serial.print(F("TDS:")); Serial.println(sdata1);
Serial.print(F("EC:")); Serial.println(sdata2, 2);
Serial.print(F("Temperature:")); Serial.println(sdata3,2);
Serial.println(sdata1);
nodemcu.println(sdata1);
delay(1000); // 100 milli seconds
sdata1 = "";
Serial.println(sdata2);
nodemcu.println(sdata2);
delay(1000); // 100 milli seconds
sdata2 = "";
Serial.println(sdata3);
nodemcu.println(sdata3);
delay(1000); // 100 milli seconds
sdata3 = "";
}
NODE MCU ESP8266 CODE
#define BLYNK_DEVICE_NAME "WATER QUALITY MONITORING SYSTEM"
#define BLYNK_AUTH_TOKEN "***";
#define BLYNK_PRINT Serial
#define BLYNK_DEBUG
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <BlynkTimer.h>
#include <SoftwareSerial.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "***";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "***";
char pass[] = "***";
BlynkTimer timer;
String myString; //complete message from arduino, which consist of sensors data
char rdata; //received charactors
int firstVal; //sensors
int secondVal;
int thirdVal;
void myTimerEvent()
{
// Sensor Values to Blynk application
Blynk.virtualWrite(V1, millis() / 1000);
}
void setup()
{
//Debug console
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
timer.setInterval(1000L,sensorvalue1);
timer.setInterval(1000L,sensorvalue2);
}
String getValue(String data, char separator, int index)
{
}
void loop()
{
if (Serial.available() == 0 )
{
Blynk.run();
timer.run(); //Initiatives BlynkTimer
}
if (Serial.available() > 0 )
{
rdata = Serial.read();
myString = myString+ rdata;
// Serial.print(rdata);
if( rdata == '\n')
{
// Serial.println(myString);
// Serial.println("fahad");
// new code
String l = getValue(myString, ',', 0);
String m = getValue(myString, ',', 1);
String n = getValue(myString, ',', 2);
firstVal = l.toInt();
secondVal = m.toInt();
thirdVal = n.toInt();
myString = "";
// end new code
}
}
}
void sensorvalue1()
{
int sdata = firstVal;
// You can send any value at any time.
// Please don't send more that 10 values per second.
Blynk.virtualWrite(V2, sdata);
}
void sensorvalue2()
{
int sdata = secondVal;
// You can send any value at any time.
// Please don't send more that 10 values per second.
Blynk.virtualWrite(V3, sdata);
}
void sensorvalue3()
{
int sdata = thirdVal;
// You can send any value at any time.
// Please don't send more that 10 values per second.
Blynk.virtualWrite(V4, sdata);
}