Could someone assist me in resolving the issue with my code regarding about IoT Based Flood Detector And Monitoring System using tipping bucket

The concept of my project involves collecting rain data using a tipping bucket rain gauge. This rain gauge is connected to an Arduino UNO, and the Arduino is linked to a NodeMCU ESP8266 for Wi-Fi connectivity, allowing me to monitor the data using the Blynk platform. I’ve included the code for both the Arduino and ESP8266 below.

|Arduino

#include <Arduino.h>

const byte interruptPin = 3;
const int interval = 100;
volatile unsigned long tiptime = millis();

void setup() {
  Serial.begin(9600);
  
  pinMode(interruptPin, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(interruptPin), count, FALLING);
}

void loop() {
  delay(100);
}

void count() {
  unsigned long curtime = millis();

  if ((curtime - tiptime) < interval) {
    return;
  }

  unsigned long tipcount = curtime - tiptime;
  tiptime = curtime;

  double rainrate = 914400.0 / tipcount;

  Serial.print("Cup tip: ");
  Serial.print(tipcount);
  Serial.print("ms"); 
  Serial.print("\t"); // Separate values with a tab
  Serial.print("Rain rate: ");
  Serial.print(rainrate);
  Serial.println("mm/hr");  
}

NodeMCU ESP8266

#define BLYNK_TEMPLATE_ID "TMPL63xopzArS"
#define BLYNK_TEMPLATE_NAME "Project Attempt 1"
#define BLYNK_AUTH_TOKEN "vkTYm8Xp2qDCOoxApWcxR8WPcR76F9Ua"
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

volatile unsigned long tiptime = millis(); //
const int interval = 100;//

char auth[] = "vkTYm8Xp2qDCOoxApWcxR8WPcR76F9Ua";//Enter the Auth code which was send by Blink
char ssid[] = "IfUrNotInMyBlacklistUMayConnect";
char pass[] = "001010011";

void setup()
{
  Serial.begin(9600); // See the connection status in Serial Monitor
  Blynk.begin(auth, ssid, pass);
}

void loop()
{
  char buffer[20]="";
  if(Serial.available()>0){
    // char data=Serial.read();
    Serial.readBytesUntil('\n', buffer, 20);
    Serial.println(buffer);
  }
  Blynk.run(); // Initiates Blynk
}

void count()
{
  unsigned long curtime = millis();//

   if ((curtime - tiptime) < interval)
  {
    return;//
  }

  unsigned long tipcount = curtime - tiptime;//
  tiptime = curtime;//

  double rainrate = 914400.0 / tipcount;//
  Blynk.virtualWrite(V0, tipcount);   // Send cup tip data to V0 (SuperChart)
  Blynk.virtualWrite(V1, rainrate);   // Send rain rate data to V1 (SuperChart)
}

The primary objective of my project is to display the cup tips and rain rate every time data is interrupted by the tipping bucket sensor. The ESP8266 is used to establish a wireless connection for Blynk so that the data can also be visualized within the Blynk app. However, I’ve encountered issues as the system isn’t working as expected. It’s worth noting that the data from the Arduino successfully transfers to the ESP8266, but the challenge lies in displaying this data on the Blynk platform, which is currently not functioning as intended I’m seeking guidance on how to resolve this problem. What steps should I take to troubleshoot and resolve the issue?

I don’t understand why you are using the obsolete Arduino uno and esp8266 together instead of using only one esp8266. :thinking:

Crazy choice of hardware!
As ever, you should place the Uno where it belongs (in the bin) and use the NodeMCU for everything.

However, if you wish to persist with this madness then the problem seems to lie with what you’re doing in your void loop - or more accurately what you aren’t doing.

You’re receiving the data from the Uno, via the serial buffer, but doing nothing other than printing this data to the serial monitor.

You need to be parsing this data into a useable format and storing the relevant elements of the data in variables then sending these to Blynk.

Also, if you’re using the NodeMCU’s serial port for this incoming data you can’t also use it for Blynk messages…

Or for your own serial debug messages…

You’d be better-off creating a SoftwareSerial port for the inbound data, but in reality you’d be far better-off simply binning the Uno.

Pete.

1 Like