DIY DIY - Affordable? Soil NPK, pH & EC sensor (NPKPHC-S)

Yeah that might be some issue with formatting, I can post a screenshot instead.. anyway thanks a lot I’ll try it out as soon as possible …
Hey Don,

Don't know if it's because of formatting on the forum, but that code won't compile in a 100 years bro...
I've reedited it and added some comments.

Try it out and let me know. :d5:
C++:
// Comment this out to disable prints and save space
#define BLYNK_ PRINT Serial


#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

char auth[] = "BLYNK_AUTHL_TOKEN";
char ssid[] = "Name of your WiFi";
// Your WiFi credentials.
char pass[] = "Pass of your WiFi";
const int analogInPin = A0;  //You need to use the GPIO pin number for a ESP device. Also, only one 'Analog' pin on the ESP chip. --> https://www.electronicshub.org/wp-content/uploads/2021/02/ESP8266-NodeMCU-ADC-Pin.jpg
BlynkTimer timer;


void setup() {

  Serial.begin(115200);
  Blynk.begin(auth, ssid, pass);
  timer.setInterval(1000L, myTimerEvent);
}



void loop() {

  Blynk.run();  //These two need to be put in the loop function.
  timer.run();
}


void myTimerEvent() {

  int humidity = ((1024 - analogRead(analogInPin)) * 100) / (1024 - 610);  //Don't know if the calculation is right, but usually you find some example code for a certain sensor...
  if (humidity >= 100) {
    humidity = 100;
  }
  else if (humidity <= 0){
    humidity = 0;
  }
  Blynk.virtualWrite(V1, humidity);  //You write the value humidity to 'virtual pin 1, then in your blynk app you select V1 from the drop down list and bob's your uncle ;)
  Serial.print(humidity);
  Serial.println("%");
}
 
the formula I do have tested it and it works pretty well, gives a fair result.

also, using analog A0,following the documentation it says to use the analog formatted device in Blynk application… should I use the digital pin instead ? With v1
 
Yf4EekZ.jpg
 
the formula I do have tested it and it works pretty well, gives a fair result.

also, using analog A0,following the documentation it says to use the analog formatted device in Blynk application… should I use the digital pin instead ? With v1
You can read out directly from A0 from within the Blynk app, but then you disregard the calculation you just made.
Write the value of 'humidity' to V1 and read that out from within the app.
 
What kind of sensor is it if I may ask?
 
ESP8266 NodeMCU 340 ESP-12E V3 WiFi

dtqWmQd.jpg

52tk2EN.jpg
 
Change this line
Code:
Blynk.virtualRead(A0, humidity);
to
Code:
Blynk.virtualWrite(V1, humidity);
 
I will1 inside the pot and 1 inside the tank as probe for low level water…
 
ESP8266 NodeMCU 340 ESP-12E V3 WiFi

dtqWmQd.jpg

52tk2EN.jpg
Ah, that sensor...
I've written a function for it.
Try this in your code
C++:
void runMe(){
  moisture(A0, 787, 446, V1);   //Arduino Pin, Raw Air Value, Raw Water Value, Blynk Virtual Pin
}


void moisture(int pin, const int AirValue, const int WaterValue, int virPin ) {

  int i;
  int value = 0;
  int numReadings = 5;
  int soilMoistureValue = 0;
  int soilmoisturepercent = 0;

  for (i = 0; i < numReadings; i++){
    value = value + analogRead(pin);
    delay(1);
  }
  soilMoistureValue = value / numReadings;
  soilmoisturepercent = map(soilMoistureValue, AirValue, WaterValue, 0, 100);
  Blynk.virtualWrite(virPin, soilmoisturepercent);
}

Call it by adding this line in void setup()
C++:
timer.setInterval(5000L, runMe);
 
Last edited:
Back
Top