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

Soil moisture value opposite

So digitalWrite isn’t working?

Was this working before? I’d look at what device you’re using and try to use the GPIO numbers rather than the D numbers. As I’m sure @PeteKnight would also suggest.

If it’s the wemos, check this post:

https://community.blynk.cc/t/c-blynk-code-examples-for-basic-tasks-work-in-progress/

1 Like

yes digitalWrite isn’t working, it works with my first coding above (bad void loop). I’m using nodemcu.

Make sure you have setup the pinMode() for the needed digital pins.

How are you checking the status of the ‘fan’ pin (D0)?

Pete.

Move your void setup above all other functions that you have.

Especially before any calls to digitalWrite.

In the code you posted above, you have your

void temperature()

and

void soilMoisture()

above your

void setup()

I don’t think it actually matters where the void setup() and void loop() functions are in the code, the Arduino iDE compiler looks for the special names of these functions and handles them accordingly.

Pete.

2 Likes

Blynk app (D0 pin) and I put LED on nodemcu D0 pin. Is that what u asked?

Already have it in void setup()

1 Like

Can you post your latest code?

1 Like

What type of widget do you have connected to pin V1, and what results are you seeing from that?

How EXACTLY ate you connecting a physical LED to your NodeMCU, and what results are you seeing with that?

What results are you seeing in your serial monitor?

Do you have access to a multimeter?

Pete.

I use value display widget, result is 30,

Positive LED on D0 pin, negative on ground. LED not turn on.

reading of temperature and soil moisture

I dont have access to a multimeter. If i use other code to trigger D0 pin to HIGH, it work. LED turn ON.

I’m confused about the code you’re using. The last code you posted had this line in the void temperature() function contained this line:

This should be writing an integer temperature value to the widget attached to V1, not “LOW”.

Your code includes these lines in the void temperature() function:

I wanted to know if this data was printing to the serial monitor.

Pete.

2 Likes

Im sorry, value display widget pin V1 shows temperature reading: 30

serial monitor result:

Current temperature: 30 *C

Everything work except digitalWrite. Both sensors working, in the app and in serial monitor. Blynk.notify also works if sensor reach the setpoint.

#include <Blynk.h>
#define BLYNK_PRINT Serial
#include <SimpleDHT.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
char auth[]="8e6dd1bed4d44071a156d44901605";
char ssid[]="iPhone";
char pass[]="12345678999";

const int moist_pin =A0;
int fan = D0;
int valve = D1;
int dht = D2;
int SensorValuePercent = 0;
SimpleDHT11 dht11(dht);
BlynkTimer timer;

void setup() {
  Serial.begin(9600);
  pinMode(fan,OUTPUT);
  pinMode(valve,OUTPUT);
  pinMode(moist_pin,INPUT);
  Blynk.begin(auth, ssid, pass);
  timer.setInterval(2000L, temperature);
  delay(100);
  timer.setInterval(2000L, soilMoisture);
}

void temperature(){
  
  byte temperature = 0;
  byte humidity = 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, "); 

  
  if (temperature <= 30){
  digitalWrite(fan,LOW);
  }
  if (temperature >= 31){
  digitalWrite(fan,HIGH);
  }
  if (temperature >= 35){
  Blynk.notify("Temperature Too High");
  digitalWrite(fan,HIGH);
  }
  Blynk.virtualWrite(V1, temperature);
}
void soilMoisture() {
  float moisture_percentage;
  int moist_analog;
  moist_analog = analogRead(moist_pin);
  moist_analog = map(moist_analog, 0, 1023, 100, 0);
  Serial.print(moist_analog);
  Serial.print("&\n\n");
  
  Blynk.virtualWrite(V5,moist_analog);
  if (moist_analog <= 10){
  digitalWrite(valve,HIGH);
  Serial.println(valve);
  }
  else {
  digitalWrite(valve,LOW);
  }
  
}

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

I just found out, everything works only when the play button in Blynk app is not press. when i press the play button in Blynk app, only sensors are working, D0 and D1 not working, both in app and hardware. pls help me…
@PeteKnight @JustBertC Sorry, this is my first ever project.

This implies that you have widgets attached to pins D0 and D1 in your app. If this is the case, please remove them and re-test.

Pete.

1 Like

It works now after D0 and D1 was removed from Blynk app. Now how the condition of D0 and D1 can be monitor in Blynk app? I tried Blynk.virtualWrite(V6,fan) with LED widget and value display widget. Not working

In the app we’re you using D0 and D1 or V0 and V1?

I use V6 pin in app. Only to monitor fan condition. Because when i use D0 and D1 in app, after press play button in blynk app, D0 and D1 not working both in app and hardware

I think in the app that you need to use V0 and V1 instead of D0 and D1 because Dx is direct control of pins whereas Vx is access to virtual pins which you are using in your code.

1 Like