BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Need help with soil moisture sensor


#1

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
DHT dht(DHTPIN, DHTTYPE);
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!");
    return;
  }
  // 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);   
    delay(150);
  }
  digitalWrite (4, LOW);
  //SensorValue = SensorValue/N; 
  Serial.println("SensorValue");
  Blynk.virtualWrite(V7, SensorValue);
  
  //soilMoisture = map(soilMoisture, 380, 0, 0, 100); 
}


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

  // Set ESP8266 baud rate
  EspSerial.begin(ESP8266_BAUD);
  delay(10);

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

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

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

#2

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


Blynk - FTFC


#3

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.


#4

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.


#5

Sorry that’s not possible.


#6

ok, no problem mate.


#7

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.


#8

so I should change it to

#define ESP8266 BAUD 9600

??


#9

http://help.blynk.cc/how-to-connect-different-hardware-with-blynk/arduino/esp8266-with-at-firmware

Blynk - RE-SEAR-CH


#10

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


#11

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


#12

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.


#13

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?


#14

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


#15

What does it say in this document http://help.blynk.cc/how-to-connect-different-hardware-with-blynk/arduino/esp8266-with-at-firmware ?


#16

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


#17

https://learn.sparkfun.com/tutorials/soil-moisture-sensor-hookup-guide

Also go buy a WeMos D1 Mini


#18

How are you managing that with an Uno?


#19

I have an hl-38 with hl_69


#20

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)