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();
}
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.
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
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?