Hi everyone,
I was hoping someone can help me out. My project checks the water level in my tank using jsn-sr04t to measure the distance on a nodeMCU…sending values to blynk via SIM800L. My project seems to work from a serial monitor perspective, but values are not sending correctly to blynk. Currently, my sketch runs and prints the output correctly to serial monitor as below. Goes to sleep, and then wakes again to do the same. What am i doing wrong? At the moment, its seems that only V1 is actually sending to blynk app. All the other values are blank on my app. Any help would be appreciated.
SERIAL MONIROT OUTPUT:
Initializing modem...
[9073]
___ __ __
/ _ )/ /_ _____ / /__
/ _ / / // / _ \/ '_/
/____/_/\_, /_//_/_/\_\
/___/ v0.5.4 on NodeMCU
[9096] Modem init...
[9921] Connecting to network...
[15607] Network: 65502
[15607] Connecting to ...
[20593] Connected to GPRS
[20606] Connecting to blynk-cloud.com:80
[22575] Ready (ping: 853ms).
Tank - water distance: 73
Tank - water depth: 147
Tank - Litres: 3824
Tank - Percentage: 76
#include <NewPing.h>
#define BLYNK_PRINT Serial
#define TINY_GSM_MODEM_SIM800
#include <TinyGsmClient.h>
#include <SoftwareSerial.h>
#include <BlynkSimpleSIM800.h>
#define SIM800_TX_PIN 12
#define SIM800_RX_PIN 13
#define uS_TO_m_FACTOR 60000000 // Conversion factor for micro seconds to minutes
char auth[] = "xxxxxxxx";
char apn[] = "";
char user[] = "";
char pass[] = "";
const int sleepTimeM = 5;
const int MAX_DISTANCE = 225; //max distance to measure
const int Diameter1 = 182; //internal Diameter of tank 1 in cm
const int Depth1 = 220; //total depth of tank 1 in cm , from sensor to base inside
const unsigned int Period = 60000; //period between pings, in milliseconds. i.e 1 munute = 60,000. max 65535. Want longer? use unsigned long
const int PingPin1 = 5; // GPIO5, D1
const int EchoPin1 = 4; // GPIO4, D2
const int Area1 = PI * ((Diameter1 / 2) * (Diameter1 / 2)); //area of base of tank 1
int Litres1, Distance1, WaterDepth1, Decimal, Persentage;
#include <SoftwareSerial.h>
SoftwareSerial SerialAT(SIM800_TX_PIN, SIM800_RX_PIN);
TinyGsm modem(SerialAT);
BlynkTimer timer;
NewPing sonar = NewPing(PingPin1, EchoPin1, MAX_DISTANCE);
void setup()
{
delay(10);
// Debug console
Serial.begin(9600);
delay(10);
SerialAT.begin(57600);
delay(3000);
Serial.println("Initializing modem...");
modem.restart();
Blynk.begin(auth, modem, apn, user, pass);
Distance1 = sonar.ping_cm(); //get distance to the top of the water tank 1
if (Distance1 >= Depth1 || Distance1 == 0 ) Distance1 = Depth1; //check it does not go negative
WaterDepth1 = Depth1 - Distance1; //calculate the depth of the water
Litres1 = (Area1 * WaterDepth1) / 1000; //calculate the volume of the water in litres
Persentage = (Litres1 / 5000.00) * 100; //Get persentage
//delay(10);
Serial.println();
Serial.println();
Serial.println("Tank - water distance: " + String(Distance1)); //print depth
Blynk.virtualWrite(V2, Litres1);
Serial.println("Tank - water depth: " + String(WaterDepth1)); //print depth
Blynk.virtualWrite(V1, WaterDepth1);
Serial.println("Tank - Litres: " + String(Litres1));
Blynk.virtualWrite(V3, Litres1 / 10);
Serial.println("Tank - Percentage: " + String(Persentage)); //print litres
Blynk.virtualWrite(V4, Persentage);
//delay(10);
modem.sendAT(GF("+CFUN=0"));
delay(10);
ESP.deepSleep(sleepTimeM * uS_TO_m_FACTOR, WAKE_RF_DEFAULT); // Sleep for 5 Minutes
delay(100);
}
void loop()
{
}