- Joined
- Aug 29, 2021
- Messages
- 399
- Reputation
- 451
- Reaction score
- 1,997
- Points
- 0
- Currently Smoking
- Bread
Thanks for the tip, i was stucked searching for... sure I'll do. Thanks.. pass the booff
#define BLYNK_TEMPLATE_ID "xxx"
#define BLYNK_DEVICE_NAME "xxx"
#define BLYNK_AUTH_TOKEN "xxx"
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "Tony";
char pass[] = "marm1te1sterr1ble";
BlynkTimer timer;
int humidity = 0; //humidity value for actuating the relay pump
const int Pump_Pin = 5; //initialize a GPIO 5 --> D1 pin
void pump(int pin){ //function to check and set relay on/off depending on humidity %
if(humidity>=60){
digitalWrite(pin, LOW); //set pin D1 on/off
Blynk.virtualWrite(V2, LOW); //display a led indicator pump is on/off on blynk app
}else{
digitalWrite(pin, HIGH);
Blynk.virtualWrite(V2, HIGH);
}
}
void moisture(int pin, const int AirValue, const int WaterValue, int virPin ) { //function for a 0-100 % humidity level
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);
//Serial.print(soilmoisturepercent); //check from serial monitor moisture%
//Serial.println("%");
humidity = soilmoisturepercent; //set a value for a globally variable called in pump()
}
void runMe(){
moisture(A0, 1044, 600, V1); //Arduino Pin, Raw Air Value, Raw Water Value, Blynk Virtual Pin
pump(Pump_Pin); //passing digital pin of esp8266, virtual pin linked + humidity % top check needed for trigger
//Serial.print(analogRead(A0)); //use for calibration
//Serial.println("<--");
}
void setup()
{
Serial.begin(9600);
pinMode(Pump_Pin, OUTPUT);
digitalWrite(Pump_Pin, HIGH); // Built-in D1 off
Blynk.begin(auth, ssid, pass);
timer.setInterval(5000L, runMe); //This line runs 'runMe' every 5 seconds, but it has to be put in the setup funtion.
}
void loop()
{
Blynk.run();
timer.run(); //The above timer will only run if you activate the timer function in the void loop...confusing isn't it...
}
Good for you buddyHey, there I got a working code... might not be the best but at least it works as it should.
C++:#define BLYNK_TEMPLATE_ID "xxx" #define BLYNK_DEVICE_NAME "xxx" #define BLYNK_AUTH_TOKEN "xxx" #define BLYNK_PRINT Serial #include <ESP8266WiFi.h> #include <BlynkSimpleEsp8266.h> char auth[] = BLYNK_AUTH_TOKEN; char ssid[] = "Tony"; char pass[] = "marm1te1sterr1ble"; BlynkTimer timer; int humidity = 0; //humidity value for actuating the relay pump const int Pump_Pin = 5; //initialize a GPIO 5 --> D1 pin void pump(int pin){ //function to check and set relay on/off depending on humidity % if(humidity>=60){ digitalWrite(pin, LOW); //set pin D1 on/off Blynk.virtualWrite(V2, LOW); //display a led indicator pump is on/off on blynk app }else{ digitalWrite(pin, HIGH); Blynk.virtualWrite(V2, HIGH); } } void moisture(int pin, const int AirValue, const int WaterValue, int virPin ) { //function for a 0-100 % humidity level 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); //Serial.print(soilmoisturepercent); //check from serial monitor moisture% //Serial.println("%"); humidity = soilmoisturepercent; //set a value for a globally variable called in pump() } void runMe(){ moisture(A0, 1044, 600, V1); //Arduino Pin, Raw Air Value, Raw Water Value, Blynk Virtual Pin pump(Pump_Pin); //passing digital pin of esp8266, virtual pin linked + humidity % top check needed for trigger //Serial.print(analogRead(A0)); //use for calibration //Serial.println("<--"); } void setup() { Serial.begin(9600); pinMode(Pump_Pin, OUTPUT); digitalWrite(Pump_Pin, HIGH); // Built-in D1 off Blynk.begin(auth, ssid, pass); timer.setInterval(5000L, runMe); //This line runs 'runMe' every 5 seconds, but it has to be put in the setup funtion. } void loop() { Blynk.run(); timer.run(); //The above timer will only run if you activate the timer function in the void loop...confusing isn't it... }
thanks ... sharing one
#define BLYNK_TEMPLATE_ID "TMPL-ccc"
#define BLYNK_DEVICE_NAME "cc"
#define BLYNK_AUTH_TOKEN "ccc"
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "Tony";
char pass[] = "marm1te1sterr1ble";
BlynkTimer timer;
int humidity = 0; //humidity value for actuating the relay pump
const int Pump_Pin = 5; //initialize a GPIO 5 --> D1 pin
const float SETPOINT = 55.0; // Set the desired moisture setpoint (between 45% and 65%)
const float HYSTERESIS = (65.0 - 45.0) / 5; // Set the hysteresis value (15% of the setpoint range)
void controlPump(int pin) {
// Water pump state (high = on, low = off)
digitalWrite(pin, LOW); //set pin D1 on/off
if (humidity < SETPOINT - HYSTERESIS) {
// If the moisture level is below the setpoint minus the hysteresis value, turn the pump on
digitalWrite(pin, HIGH);
Blynk.virtualWrite(V2, HIGH);
} else if (humidity > SETPOINT + HYSTERESIS) {
// If the moisture level is above the setpoint plus the hysteresis value, turn the pump off
digitalWrite(pin, LOW); //set pin D1 on/off
Blynk.virtualWrite(V2, LOW); //display a led indicator pump is on/off
}
}
/*void pump(int pin){ //function to check and set relay on/off depending on humidity %
if(humidity>=60){
digitalWrite(pin, LOW); //set pin D1 on/off
Blynk.virtualWrite(V2, LOW); //display a led indicator pump is on/off
}else{
digitalWrite(pin, HIGH);
Blynk.virtualWrite(V2, HIGH);
}
}*/
void moisture(int pin, const int AirValue, const int WaterValue, int virPin ) { //function for a 0-100 % humidity level
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);
//Serial.print(soilmoisturepercent); //check from serial monitor moisture%
//Serial.println("%");
humidity = soilmoisturepercent; //set a value for a globally variable called in pump()
}
void runMe(){
moisture(A0, 1024, 600, V1); //Arduino Pin, Raw Air Value, Raw Water Value, Blynk Virtual Pin
controlPump(Pump_Pin); //passing digital pin of esp8266, virtual pin linked + humidity % top check needed for trigger
Serial.print(analogRead(A0)); //use for calibration
Serial.println("<--");
}
void setup()
{
Serial.begin(9600);
pinMode(Pump_Pin, OUTPUT);
digitalWrite(Pump_Pin, LOW); // Built-in D1 off
Blynk.begin(auth, ssid, pass);
timer.setInterval(5000L, runMe); //This line runs 'runMe' every 5 seconds, but it has to be put in the setup funtion.
}
void loop()
{
Blynk.run();
timer.run(); //The above timer will only run if you activate the timer function in the void loop...confusing isn't it...
}
Even if I am not sure about the answer of this specific device, usually sensors are pre-calibrated by manufacturers, but their accuracy is not-so good(mostly fine for avg needs). You should calibrate them for better accuracy in a controlled environment (means that you specifically create a environment with the knowledge of what’s inside).This is some cool ass shit. Wayyyyy to complicated for me, but Im fascinated. Question though, does this npkphc-s sensor need some kind of calibration to get accurate readings?
You did really good with your code brother.Hello Bob ,
I took your suggestion and tried to implement -setpoint- and -hysteresis-, what do you think?
C++:#define BLYNK_TEMPLATE_ID "TMPL-ccc" #define BLYNK_DEVICE_NAME "cc" #define BLYNK_AUTH_TOKEN "ccc" #define BLYNK_PRINT Serial #include <ESP8266WiFi.h> #include <BlynkSimpleEsp8266.h> char auth[] = BLYNK_AUTH_TOKEN; char ssid[] = "Tony"; char pass[] = "marm1te1sterr1ble"; BlynkTimer timer; int humidity = 0; //humidity value for actuating the relay pump const int Pump_Pin = 5; //initialize a GPIO 5 --> D1 pin const float SETPOINT = 55.0; // Set the desired moisture setpoint (between 45% and 65%) const float HYSTERESIS = (65.0 - 45.0) / 5; // Set the hysteresis value (15% of the setpoint range) void controlPump(int pin) { // Water pump state (high = on, low = off) digitalWrite(pin, LOW); //set pin D1 on/off if (humidity < SETPOINT - HYSTERESIS) { // If the moisture level is below the setpoint minus the hysteresis value, turn the pump on digitalWrite(pin, HIGH); Blynk.virtualWrite(V2, HIGH); } else if (humidity > SETPOINT + HYSTERESIS) { // If the moisture level is above the setpoint plus the hysteresis value, turn the pump off digitalWrite(pin, LOW); //set pin D1 on/off Blynk.virtualWrite(V2, LOW); //display a led indicator pump is on/off } } /*void pump(int pin){ //function to check and set relay on/off depending on humidity % if(humidity>=60){ digitalWrite(pin, LOW); //set pin D1 on/off Blynk.virtualWrite(V2, LOW); //display a led indicator pump is on/off }else{ digitalWrite(pin, HIGH); Blynk.virtualWrite(V2, HIGH); } }*/ void moisture(int pin, const int AirValue, const int WaterValue, int virPin ) { //function for a 0-100 % humidity level 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); //Serial.print(soilmoisturepercent); //check from serial monitor moisture% //Serial.println("%"); humidity = soilmoisturepercent; //set a value for a globally variable called in pump() } void runMe(){ moisture(A0, 1024, 600, V1); //Arduino Pin, Raw Air Value, Raw Water Value, Blynk Virtual Pin controlPump(Pump_Pin); //passing digital pin of esp8266, virtual pin linked + humidity % top check needed for trigger Serial.print(analogRead(A0)); //use for calibration Serial.println("<--"); } void setup() { Serial.begin(9600); pinMode(Pump_Pin, OUTPUT); digitalWrite(Pump_Pin, LOW); // Built-in D1 off Blynk.begin(auth, ssid, pass); timer.setInterval(5000L, runMe); //This line runs 'runMe' every 5 seconds, but it has to be put in the setup funtion. } void loop() { Blynk.run(); timer.run(); //The above timer will only run if you activate the timer function in the void loop...confusing isn't it... }
thanks very much for your time ! Hope everything is good. sharing a boof
It's not that hard. If an old stoner can do it...This is some cool ass shit. Wayyyyy to complicated for me, but Im fascinated.
The Windows application does have calibration commands for pH, EC & TDS and so on, but not for the NPK values...Question though, does this npkphc-s sensor need some kind of calibration to get accurate readings?
You did really good with your code brother.
But the more important question...Does the code do what you'd expect?
Don't forget the time you invest into building your device. But I find this the fun part of tinkeringI spent very little in comparison with how much does it costs in the market..