Need help with soil moisture sensor

Hi guys, I need help for my college project.

I want my soil moisture sensor to display value on blynk app with a virtual pin on “Labelled Value” widget.
And I am not getting the code for it. It always shows 0 on serial monitor and never display value on blynk app either.
I checked my sensor and its working fine with a simple code showing o/p on serial monitor but for blynk it isn’t working.I use Arduino uno with esp8266 wifi shield.

The code is in getsoilMoistureData();
And 2 defines are on top 2 lines.
Plz help.

//App project setup:
    //Value Display widget attached to V5
    //Value Display widget attached to V6
#define BLYNK_PRINT Serial

#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
#include <DHT.h>
char auth[] = "**************************";

char ssid[] = "*******";
char pass[] = "**************";

// Hardware Serial on Mega, Leonardo, Micro...
#define EspSerial Serial

#define ESP8266_BAUD 115200

ESP8266 wifi(&EspSerial);

#define DHTPIN 2          // What digital pin we're connected to

#define DHTTYPE DHT11     // DHT 11
BlynkTimer timer;

#define soilMoisturePin A0
#define soilMoisture 4
#define SensorValue V7

// 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 h = dht.readHumidity();
  float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit
  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V5, h);
  Blynk.virtualWrite(V6, t);

void getSoilMoistureData()
int SensorValue = 0;
digitalWrite (4, HIGH);
 // delay (500);
  int N = 3;
  for(int i = 0; i < N; i++) // read sensor "N" times and get the average
    int SensorValue = analogRead(A0);   
  digitalWrite (4, LOW);
  //SensorValue = SensorValue/N; 
  Blynk.virtualWrite(V7, SensorValue);
  //soilMoisture = map(soilMoisture, 380, 0, 0, 100); 

void setup()
   // Debug console
digitalWrite(4, LOW);
timer.setInterval(100L, getSoilMoistureData);

  // Set ESP8266 baud rate

  Blynk.begin(auth, wifi, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, wifi, ssid, pass, "", 8442);
  //Blynk.begin(auth, wifi, ssid, pass, IPAddress(192,168,1,100), 8442);

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

void loop()

That screenshot is useless for us… please post full code here (properly formatted as directed in Welcome Topic).

Blynk - FTFC

Why are using an Arduino, leave it out of the project as it will be much better without it.

Don’t they teach you how to search websites at college?

Soil moisture sensors have been covered several times on this site.

sorry I’m new to this project making and arduino
but as I’m on it now can’t change they wont let me do it.

A link to it will bw helpful aswell, thanks.

Sorry that’s not possible.

ok, no problem mate.

You didn’t mention if you are somehow connecting your devices to the App, and if any other data is coming through… The UNO requires SoftwareSerial to communicate with the ESP, and preferably at 9600 BAUD. Change that first.

so I should change it to

#define ESP8266 BAUD 9600


Blynk - RE-SEAR-CH

My esp8266 is connected with wifi and its working completely fine even on the blynk app
and I’m even getting values for my temperature and humidity.
but I am not getting my soil moisture value as the code is incorrect. I need help with soil moisture code and its global define pins

How are you staying connected and/or getting serial monitor output when you are using same Serial connection for ESP?

Idk my friend
But you suggest me what should I change in it?
As I am not a pro just a beginner.
A answer in simple language is what I want so I can actually understand what you say. thank you.

You issue is not really Blynk specific… Read the link I already sent… study the >documentation< for Blynk and for >Arduino< as well as whatever examples are for that sensor. You don’t have to be a Pro to learn… how did you write the code you already have without research and learning?

1 Like

just tell me if I should change my esp baud to 9600 for its proper working?

What does it say in this document ?

I’m using hardware serial and it says for software serialbaud should be 9600.

Also go buy a WeMos D1 Mini

1 Like

How are you managing that with an Uno?

I have an hl-38 with hl_69

Those product codes really mean nothing as they are just china manufacture codes and they vary.

The code will work on all varients (unless it is an SPI/I2C)

1 Like