Hello, Please do not post a new issue into an old topic (that one was 2 years old!!)… I moved your post into your own current topic.
Please also properly format all posted code, as required and demonstrated in the Welcome Topic along with solid details of your issue and what you have been trying
Then i recommend you test it first with a basic, non-Blynk, sketch to confirm it is working correctly with your ESP… then it is easy to port that code function over to Blynk.
hi @Gunner I have tried with basic, non blynk. Now the sensor working correctly. now the problem is Blynk.virtualWrite (V5,moisture_percentage); not working in blynk app. But Blynk.virutalWrite(V1,temperature); is working fine in the app.
#include <Blynk.h>
#define BLYNK_PRINT Serial
#include <SimpleDHT.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
char auth[]="8e6dd1bed4d44071a156d4490160885";
char ssid[]="iPhone";
char pass[]="1234567899";
const int moist_pin =A0;
int fan = D0;
int valve = D1;
int dht = D2;
int SensorValuePercent = 0;
SimpleDHT11 dht11(dht);
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
pinMode(fan,OUTPUT);
pinMode(valve,OUTPUT);
pinMode(moist_pin,INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
Blynk.run();
byte temperature = 0;
byte humidity = 0;
byte moiture_percentage = 0;
int err = SimpleDHTErrSuccess;
if ((err = dht11.read(&temperature, &humidity, NULL)) != SimpleDHTErrSuccess) {
Serial.print("Read DHT11 failed, err="); Serial.println(err);delay(1000);
return;
}
Serial.print("Current temperature: ");
Serial.print((int)temperature); Serial.print(" *C, ");
Blynk.virtualWrite(V1, temperature);
if (temperature <= 30){
digitalWrite(fan,LOW);
delay(100);
}
if (temperature >= 31){
digitalWrite(fan,HIGH);
delay(100);
}
if (temperature >= 35){
Blynk.notify("Temperature Too High,FAN ON");
digitalWrite(fan,HIGH);
delay(100);
}
float moisture_percentage;
int moist_analog;
Blynk.virtualWrite(V5,moisture_percentage);
moist_analog = analogRead(moist_pin);
moisture_percentage = (100 - ( (moist_analog/1024.00) * 100));
Serial.print(moisture_percentage);
Serial.print("%\n\n");
if (moisture_percentage >= 20){
digitalWrite(valve,HIGH);
delay(100);
}
else {
digitalWrite(valve,LOW);
delay(100);
}
delay(5000);
}
Hi,
I have already done that before, but cannot upload to board (error: espcomm_upload_mem failed). compiled without error. already googled the soloution, still dont know. here is the coding. thats why I still using the very bad void loop coding. pls help. thanks
Both of these are trying to run at the exact same time… either combine them into one function or put a small delay in between so that both timers are offset.
timer.setInterval(1000, temperature); // Starts a timer to call function every second
delay(100);
timer.setInterval(1000, soilMoisture); // Starts a timer to call function every second, but with a starting gap of 100ms after the previous timer