Help with basic project to view Analogue value from Rain Detector

Hi,

I am a complete beginner when it comes to Arduino, NodeMCU and Programming in general. I am trying to learn by doing some basic projects, whilst connecting and visualising via Blynk.

I am currently trying to view the data taken from a rain sensor via the NodeMCU (A0) and display it in Blynk. I have set up my Blynk cloud but have an issue when verifying the current code I have. The error code I received can be seen below along with the code I have created so far. Any help would be much appreciated.

Arduino: 1.8.15 (Windows 10), Board: "NodeMCU 1.0 (ESP-12E Module), 80 MHz, Flash, Disabled (new aborts on oom), Disabled, All SSL ciphers (most compatible), 32KB cache + 32KB IRAM (balanced), Use pgm_read macros for IRAM/PROGMEM, 4MB (FS:2MB OTA:~1019KB), 2, v2 Lower Memory, Disabled, None, Only Sketch, 115200"



Edgent_ESP8266:20:12: error: redefinition of 'BlynkTimer timer'

   20 | BlynkTimer timer;

      |            ^~~~~

In file included from C:\Users\Conor\AppData\Local\Temp\arduino_modified_sketch_386518\Edgent_ESP8266.ino:18:

C:\Users\Conor\AppData\Local\Temp\arduino_modified_sketch_386518\BlynkEdgent.h:113:12: note: 'BlynkTimer timer' previously declared here

  113 | BlynkTimer timer;

      |            ^~~~~

Multiple libraries were found for "BlynkSimpleEsp8266_SSL.h"

 Used: C:\Users\Conor\Documents\Arduino\libraries\blynk-library-master

 Not used: C:\Users\Conor\Documents\Arduino\libraries\Blynk

exit status 1

redefinition of 'BlynkTimer timer'



This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
// Fill-in information from your Blynk Template here
#define BLYNK_TEMPLATE_ID "XXXXXXXX"
#define BLYNK_DEVICE_NAME "XXXXXX"

#define BLYNK_FIRMWARE_VERSION        "0.1.0"

#define BLYNK_PRINT Serial
//#define BLYNK_DEBUG

#define APP_DEBUG

// Uncomment your board, or configure a custom board in Settings.h
//#define USE_SPARKFUN_BLYNK_BOARD
#define USE_NODE_MCU_BOARD
//#define USE_WITTY_CLOUD_BOARD

#include "BlynkEdgent.h"

BlynkTimer timer;

// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void myTimerEvent()
{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V5, millis() / 1000);
}

void setup()
{
  Serial.begin(115200);
  delay(100);

  BlynkEdgent.begin();

  timer.setInterval(1000L, myTimerEvent);
}

void loop() {
  BlynkEdgent.run();
  timer.run(); // Initiates BlynkTimer
}

I think there’s currently a bug with the Blynk library that causes this problem.

Not sure if changing the timer object from timer to something else helps?

Pete.

Thanks, Pete!

I changed the timer to testing throughout the programme which seemed to fix the verification error I was having.

When uploading I now get:
Leaving... Hard resetting via RTS pin...

Does this mean my sketch wasn’t uploaded?

No, that tells you that the code has been uploaded and the board is rebooting (it’s 100% normal).

Pete.

Thank you. I Hadn’t noticed before as this is the first time having an issue when verifying and uploading.

I think I have everything setup and connected via wifi, but my Virtual pin (V5) is not updating the values as i change the state of my sensor. Do I need to add something to my code, so that it knows that data from A0 should be connected to V5?

Thanks for your help.

You have to set up a datastream in the web portal, and ensure that you don’t leave the MAX value at the default of “1”.

Pete.

I’ve already updated my Datastream as Pin V5, Integer, Min 0, Max 1024, Default 1024.

I also don’t see anything showing in the serial viewer, but i’m guessing this is as I don’t have the serialWrite in this piece of code. I’m not sure what else I need to add from this point. Everything looks good in my Blynk Cloud Dashboard.

You should see Blynk connection info in the serial monitor when it’s set to 115200 because of this…

Pete.

Yeah, switched the baud to 115200 which shows all the connection info perfectly. But no Sensor Data.

Is this the data you’re sending to V5 still?

You need to add some serial print statements to push your ‘sensor’ data to the serial monitor for debugging.

Pete.

Yeah, I’ve set everything up to go through V5.

I can add an int sensorValue = analogRead(A0) and Serial.println(sensorValue) which shows everything as expected in the serial monitor, but my values in the Blynk app don’t seem to update. How does my V5 know that I want it to send the A0 values? Is there a method for this?

Yes….

Blynk.virtualWrite(V5, sensorValue);

Pete.