ESP32U code problem {moisture sensor} in arduino IDE ambient

Hi guys, pleased to be here.

I have a problem with the compiling of the code that i finded on the web about a project of moisture sensors.
In the code I am using also Blynk libraries in order to make communicate ESP32 with the Blynk cloud.
Anyway I am not able to understand why the code doesn't working despite Arduino IDE load it regularly.

The problem that I meet it's in the Blynk (dashboard and app), more precisely when I link the moisture sensor to ESP32 using the breadboard. In this scenario I expect a value zero% when the sensor it's outside the water and 100% when the sensor is in the water, instead the value remain 100% indipendently that the sensor is in the water or not.
I link some image to understand better my words.

Here you can see the project to understand better my words:

Image : App blynk configuration
Image : Wiring diagram

This is the code with the modification for the ESP32U (the verifier give me no error about the code so i think that the problem is during the write of the code):

Blynk is a platform with iOS and Android apps to control
  ESP32, Arduino, Raspberry Pi and the likes over the Internet.
  You can easily build mobile and web interfaces for any
  projects by simply dragging and dropping widgets.

    Downloads, docs, tutorials: https://www.blynk.io
    Sketch generator:           https://examples.blynk.cc
    Blynk community:            https://community.blynk.cc
    Follow us:                  https://www.fb.com/blynkapp
                                https://twitter.com/blynk_app

  Blynk library is licensed under MIT license
 *************************************************************
  Blynk.Edgent implements:
  - Blynk.Inject - Dynamic WiFi credentials provisioning
  - Blynk.Air    - Over The Air firmware updates
  - Device state indication using a physical LED
  - Credentials reset using a physical Button
 *************************************************************/

/* Fill in information from your Blynk Template here */
/* Read more: https://bit.ly/BlynkInject */

// configurazione Blynk
#define BLYNK_TEMPLATE_ID "template id"
#define BLYNK_TEMPLATE_NAME "moisture sensor"
#define BLYNK_FIRMWARE_VERSION        "0.1.0"
 

#define BLYNK_PRINT Serial
//#define BLYNK_DEBUG
 
#define APP_DEBUG
 
#include "BlynkEdgent.h"
 

 
//  Blynk configuration
BlynkTimer timer;
 
// variables
 

 
int power;
 
int flood alarm;
bool alarm siren;
const int pin1= 34;
const int pin2= 35;
const int pin3= 32;
const int pin4= 33;
const int pin5= 25; 
int moisture sensor 1;
int moisturesensor 2;
int moisture sensor 3;
int moisture sensor 4;
int moisture sensor 5;



float temperature1;
float moisture1;
 
float temperature2;
float moisture2;
 
float windvelocity;
 
void setup()
{
  Serial.begin(115200);
  delay(2000);
 
  BlynkEdgent.begin();
 
 
  digitalWrite(4, HIGH); //reverse logic!
 
  //pin alarm
  pinMode(5, INPUT_PULLUP); //sensor
  pinMode(7, OUTPUT); //siren alarm
 
  digitalWrite(7, LOW);
  
  //pin alimentazione
  pinMode(8, INPUT); //feedback
  
  
  //timer
  timer.setInterval(2000L, trasmissionData);
}
 
void trasmissionData(){
  // read sensor
  moisturesensor1 = analogRead(34);
  moisturesensor2 = analogRead(35);
  moisturesensor3 = analogRead(32);
  moisturesensor4 = analogRead(33);
  moisturesensor5 = analogRead(25);
  
  
  floodalarm = digitalRead(5);
  
  
  // trasmission data sensor
  Blynk.virtualWrite(V1, 100 - (moisturesensor1/10));
  Blynk.virtualWrite(V2, 100 - (moisturesensor2/10));
  Blynk.virtualWrite(V3, 100 - (moisturesensor3/10));
  Blynk.virtualWrite(V4, 100 - (moisturesensor4/10));
  Blynk.virtualWrite(V5, 100 - (moisturesensor5/10));
  
 
  
  // alarm
  if(alarmflood == LOW) {
    Blynk.virtualWrite(V13, 1);
    digitalWrite(7, sirena);
    sirenalarm = !sirenalarm;
  }
  else {
    Blynk.virtualWrite(V13, 0);
    digitalWrite(7, LOW);
  }
 
  
}
 
BLYNK_CONNECTED() {
  Blynk.syncAll();
}
 
 
void loop() {
  BlynkEdgent.run();
  timer.run();
}

Hi @cas3se

It will not be possible for us to help you with that problem based on such a vague description. Please provide a detailed explanation of what you mean by this, including:

  • What did you do?
  • What were the results you expected from doing that thing?
  • What were the results you observed that did not match your expectations?

Make sure to include the full and exact text of any error or warning message you might have encountered.

Hi,

I too have struggled with this board. The documentation implies that GPIO numbers are used to reference pins, whereas it appears that the NANO numbers are to be used instead. I have tried to get the onboard RGB to work and the example given using pins 46, 0 & 45 does not work, but using 14, 15 & 16 does.

Pin 46 does not produce an invalid pin error which does not help. Prefixing the NANO number with 'D' produces an error message for 'pins' greater than 12. I have not tried Analog pins yet, but. assume an 'A' prefix is required.

Your code appears to reference NANO pin numbers as well as GPIO numbers in different places, if I read it right. This is probably the main issue with your code if it works on other boards.

It is possible that A4-A7 may not work correctly if WiFi is in use.

It would be nice if GPIO numbers could be used as well as NANO numbers, in the manner of ESP8266 boards.

Good luck!

Hi @robey

Would you mind providing a link to the documentation you are referring to?

I don't see a reason for doing that. However, there is a conversion function in the core:

Unfortunately the developer didn't add a declaration for the function to the header file so you will need to add the prototype in your own code to use the function. For example:

byte LEDGPIO = 46;
unsigned int duration = 1000;

int8_t gpioNumberToDigitalPin(int8_t gpioNumber);

void setup() {
  pinMode(gpioNumberToDigitalPin(LEDGPIO), OUTPUT);
}

void loop() {
  digitalWrite(gpioNumberToDigitalPin(LEDGPIO), HIGH);
  delay(duration);
  digitalWrite(gpioNumberToDigitalPin(LEDGPIO), LOW);
  delay(duration);
}

Hi ptillisch,

Thanks for your prompt reply.

The guidance I took was from the 'nano-esp32 Cheat Sheet' RGB section.

Cheat Sheet RGB info

Coming from a NANO tradition using D1, A0 etc is easy but for those of us from the Esp tradition where pin names and GPIO numbers can be used together, it took a bit of time for the penny to drop that the GPIO info is for cross referencing, not for use in code. Especially with the Cheat Sheet example.

If the above distinction was clearer, then the mods to 'The Core' which are be beyond me, at least, would not be required.

If the documentation could be updated / an entry in the FAQs made, I am sure it would save others a little time / head aches. If both Pin Name and GPIO referencing could be used, as they are in WEMOS esp8266 boards, then that would be helpful to many, I am sure. Especially when porting ESP32 code as cas3se tried.

Many thanks

Thanks! I have submitted a correction: