Soil moisture gives wrong value

good day to everybody
im very new here and in advance i thanks you for your future time and advices you gonna give and please forgive my ignorance…
im building a soil sensor using the soil sensor v1.2 connected with the blynk app.
all is working but the reading are actually opposite …more then 1000 if im looking the arduino monitor when dry and the blynk gauge shows 99
im using a code found on the net and for the guy seams working.
here the link of the project

thanks

Well, just browsing through the code in that link tells me that the person who wrote it doesn’t understand how to write good code for Blynk, deep sleep or EEPROM usage.
In fact, the use of EEPROM is really a thing of the past now and even it’s successor SPIFFS is pretty-much obsolete now. And, storing values to the ESP8266’s non-volatile memory isn’t even necessary anyway as they could easily be retrieved from, the Blynk server instead.

There are quite a few examples of how to use these soil moisture sensors here, so you’d probably be better looking through some of those instead.

Pete.

1 Like

thanks pete for your replay…
been already spending litterally 2 days before with other problems like :
usb cable not transfering datas then i had to find out the 5G is not working for the d1 mini
and then now the sensor gives wrong value.
i have been already looking all day here and i can only find 1 topic very similar but the guy his using so many more things then me …
i got a code to set dry and wet parameters and i want it to send it to blynk…
i have try to add part of the other code to connected to blynk but im not capable…
if you know ( or can make and explain me ) any simple code NOT using the dht11 sensor but the soil sensor v1.2 … that will be super awesome…
thanks

#define BLYNK_PRINT Serial
 
#include <ESP8266WiFi.h>

#include <BlynkSimpleEsp8266.h>



// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "FDbIFhuANy7UZ70kjj-uPGDJ3o_AT6yg";
 
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Lowi309C";
char pass[] = "RA6JNAAt6XNBZQ";
 


const int dry = 1024; // value for dry sensor
const int wet = 633; // value for wet sensor


void setup()
{
  // Debug console
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
  
 
}
 
void loop()
{
  Blynk.run();
  int sensorVal = analogRead(A0);

  // Sensor has a range of 1024to 633
  // We want to translate this to a scale or 0% to 100%
  // More info: https://www.arduino.cc/reference/en/language/functions/math/map/
  int percentageHumididy = map(sensorVal, wet, dry, 100, 0); 

  Serial.print(percentageHumididy);
  Serial.println("%");

  Blynk.virtualWrite(V9,percentageHumididy);
}

this is a code i put together…
in the monitor the sensor work well but if i look at it true blynk the gauge is not working…
how can i make it work so i can read in the app the percentage that i see in the monitor ??
thanka again :hugs:

Please dont run this code, it breaks the number one rule of Blynk which is to have a virtualWrite command in the void loop, so it will flood the Blynk server with data.

You should read this…

http://help.blynk.cc/getting-started-library-auth-token-code-examples/blynk-basics/keep-your-void-loop-clean

Pete.

ok pete
thanks again for the link …
ill give it one more look at it cause i feel im close but is also very time consuming due to little knoledge.
thanks again
wish you an electric day

im trying to combine the 2 codes to make one so i can see on the blynk app what i see in the monitor… but i keep getting name types that dosent exist…
please help me … i know that for you guys will take you not even a minute…is now a week im working on this stuff.
i want to understand my im very new at it… need assistance.

#define BLYNK_PRINT Serial
 
#include <ESP8266WiFi.h>

#include <BlynkSimpleEsp8266.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[] = "";

 int sensorValue = analogRead(A0);
 
BlynkTimer timer; // Announcing the timer

void setup()
{
  timer.setInterval(1000L, sensorDataSend); //timer will run every sec 
}
void sensorDataSend()
{
  sensorValue = analogRead(A0);         // reading sensor from analog pin
  Blynk.virtualWrite(V1, sensorValue);  // sending sensor value to Blynk app
}
const int dry = 1024; // value for dry sensor
const int wet = 633; // value for wet sensor


  // Debug console
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
  

  Blynk.run();
  int sensorValue = analogRead(A0);

  // Sensor has a range of 239 to 595
  // We want to translate this to a scale or 0% to 100%
  // More info: https://www.arduino.cc/reference/en/language/functions/math/map/
  int percentageHumididy = map(sensorVal, wet, dry, 100, 0); 

  Serial.print(percentageHumididy);
  Serial.println("%");
  
  delay(100);
  }
   
 
void loop()
{
 
  Blynk.run();        // run Blynk magic
  timer.run();        // run timer every second
}

here is the code… please assist me with it

Well, your code is a mess!

Your void setup only has one line in it…

void setup()
{
  timer.setInterval(1000L, sensorDataSend); //timer will run every sec 
}

These two lines of code, which aren’t in any function (void) should be in your void setup…

  // Debug console
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);

You then have these tw0 lines of code, one at the top and one near the bottom…

 int sensorValue = analogRead(A0);

  int sensorValue = analogRead(A0);

These in initialise the sensorValue variable as an read the A0 pin and store the result in sensorValue.

However, you want to be initialising the sensorValue variable once, near the top of your code so that sensorValue is a global variable, then taking a reading of A0 within a function which is called using a timer. The other lines of code that go with this process are…

  int percentageHumididy = map(sensorVal, wet, dry, 100, 0); 

  Serial.print(percentageHumididy);
  Serial.println("%");
  
  delay(100);

and these need to be inside the same timed function, BUT, the delay is not required and should be removed.

Having variable definitions in the middle of your code can be confusing. Put them near the top so that they are easy to find…

I think it would be helpful if you spent some time learning the basics of C++ coding, so that you understand the structure of an Arduino sketch.

Pete.

dear pete
thank you very much for your time and advice… but even with those i miss part of the code and im really getting frustrated and confused…
i just want to read the soil moisture from the blynk app and move on in my life…
please do it for me and ill send you few euros in your account… i cant spend anymore time on this project… is now a week and it will tale you nothing to write to code and show me how it works… please i cant spend anymore time on this…is really frustrating

No thank you, I also have a life and am not interested in helping people who just want a readymade solution. I’m happy to help educate people who are interested in learning C++ coding, but you clearly don’t have the attention span for that.

Pete.

attention span ???
its a week im working on it …and of course i want lo learn it…
i made a theremin with the arduino and i put together i code to read id card to make a magic tricks… so im very interested .
if i was doing this project with the dht11 sensor i will be done already coping and paste…
anyway … for you will take 1 mintues and of course i will learn from it cause i can undestand it…instead…i need to spend i dont know how much more time with it…
anyway…thanks

#define BLYNK_PRINT Serial
 
#include <ESP8266WiFi.h>

#include <BlynkSimpleEsp8266.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[] = "LowC";
char pass[] = "RA6JNZQ";

 
 int sensorValue = analogRead(A0);
 

const int dry = 1024; // value for dry sensor
const int wet = 633; // value for wet sensor

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 sendSensor()
{
  float sensorValue = analogRead(A0);

   Blynk.run();
 
  int sensorVal = analogRead(A0);

  // Sensor has a range of 239 to 595
  // We want to translate this to a scale or 0% to 100%
  // More info: https://www.arduino.cc/reference/en/language/functions/math/map/
  int percentageHumididy = map(sensorVal, wet, dry, 100, 0); 

  Serial.print(percentageHumididy);
  Serial.println("%");

  
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V1, percentageHumididy);
 
}

void setup()
{
  // Debug console
  Serial.begin(9600);

  Blynk.begin(auth, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);



  // Setup a function to be called every second
  timer.setInterval(1000L, sendSensor);
}

void loop()
{
  Blynk.run();
  timer.run();
}


  
 

i finally made it !!! :smiley: :smiley: :smiley:
i started over using as abase the code for the dht11 sensor i finally read what i see in the monitor on the app.
so happy and thanks again pete… i just got so frustrated after so long time working on it that i was losing hopes…
thanks again pete and my money compensation was just out of frustration… i love to learn and do thinkgs by my self, but some time we need some help thats why we got profesional .

thanks again…

Can you provide the schematics for the above code? Would like to have a look.

@Koushal_B I recommend you to create a new " need help with my project " topic and provide as much details as possible.