My coding is about watering plant. For the sensors (DHT11, ph sensor and soil moisture), I connect to the arduino. For the relay (which is connect to water pump), I connect to the nodemcu. All of the sensor and relays are function well but the problem is, my blynk does not show notification even when it meet the requirement.
Details about hardware:
- Arduino ESP8266 CH-340 V2 NodeMCU Lua Wifi Controller Board.
- Arduino Compactible DCCduino Uno R3.
- Phone : Android 10
This is the Arduino Code :
#include <EEPROM.h>
#include <SoftwareSerial.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <dht.h>
#define SensorPinPH A0
#define Offset 0.00
#define samplingInterval 20
#define printInterval 800
#define ArrayLength 40
int pHArray[ArrayLength];
int pHArrayIndex=0;
LiquidCrystal_I2C lcd(0x27, 16, 2);
SoftwareSerial ArduinoUno (3, 2);
float i, j, k, m;
#define SensorPin A1
#define dht_apin A2
dht DHT;
float sensorValue = 0;
void setup()
{
Serial.begin(9600);
ArduinoUno.begin(4800);
pinMode(A0, INPUT);
pinMode(A1, INPUT);
pinMode(A2, INPUT);
lcd.begin();
}
void loop() {
static unsigned long samplingTime = millis();
static unsigned long printTime = millis();
static float pHValue,voltage;
if(millis()-samplingTime > samplingInterval)
{
pHArray[pHArrayIndex++]=analogRead(SensorPinPH);
if(pHArrayIndex==ArrayLength)pHArrayIndex=0;
voltage = avergearray(pHArray, ArrayLength)*5.0/1024;
pHValue = 3.5*voltage+Offset;
samplingTime=millis();
}
if(millis() - printTime > printInterval) //Every 800 milliseconds, print a numerical, convert the state of the LED indicator
{
Serial.print("Voltage:");
Serial.print(voltage,2);
Serial.print(" pH value: ");
Serial.println(pHValue,2);
printTime=millis();
}
DHT.read11(dht_apin);
sensorValue = analogRead(SensorPin);
delay(500);
i = sensorValue;
int i1 = i + 2000;
ArduinoUno.print(i1);
ArduinoUno.println("\n");
Serial.println(i1,2);
j = DHT.humidity;
int j1 = j + 4000;
ArduinoUno.print(j1);
ArduinoUno.println("\n");
Serial.println(j1,2);
k = DHT.temperature;
int k1 = k + 6000;
ArduinoUno.print(k1);
ArduinoUno.println("\n");
Serial.println(k1,2);
m = pHValue;
int m1 = m + 8000;
ArduinoUno.print(m1);
ArduinoUno.println("\n");
Serial.println(m1,2);
delay(30);
}
double avergearray(int* arr, int number){
int i;
int max,min;
double avg;
long amount=0;
if(number<=0){
Serial.println("Error number for the array to avraging!/n");
return 0;
}
if(number<5){ //less than 5, calculated directly statistics
for(i=0;i<number;i++){
amount+=arr[i];
}
avg = amount/number;
return avg;
}else{
if(arr[0]<arr[1]){
min = arr[0];max=arr[1];
}
else{
min=arr[1];max=arr[0];
}
for(i=2;i<number;i++){
if(arr[i]<min){
amount+=min; //arr<min
min=arr[i];
}else {
if(arr[i]>max){
amount+=max; //arr>max
max=arr[i];
}else{
amount+=arr[i]; //min<=arr<=max
}
}//if
}//for
avg = (double)amount/(number-2);
}//if
return avg;
}
This is the NodeMCU code:
#define BLYNK_PRINT Serial
#include <SoftwareSerial.h>
#include <BlynkSimpleEsp8266.h>
#include <ESP8266WiFi.h>
const int PumpMotor = D3;
BlynkTimer timer;
// ================= CONNECT TO WIFI ================
char auth[] = "***************";
char ssid[] = "****************";
char pass[] = "**************";
float rpm;
int a, b;
SoftwareSerial NodeMCU(D2, D1);
void kecepatan () {
while (NodeMCU.available() > 0) {
rpm = NodeMCU.parseFloat();
if (NodeMCU.read() == '\n') {
if (rpm >= 2000 && rpm <= 3023){
int rpm1 = rpm;
int rpm2 = rpm1 - 2000;
Blynk.virtualWrite(V1,rpm2);
if (rpm2 >=1000){
digitalWrite(PumpMotor,LOW);
delay(2000);
digitalWrite(PumpMotor,HIGH);
Serial.println("Too Dry, water already plant automatically!");
Blynk.notify("Too Dry");
}
}
if (rpm >= 4000 && rpm <= 5023){
int rpm3 = rpm;
int rpm4 = rpm3 - 4000;
Blynk.virtualWrite(V2,rpm4);
}
if (rpm >= 6000 && rpm <= 7023){
int rpm5 = rpm;
int rpm6 = rpm5 - 6000;
Blynk.virtualWrite(V3,rpm6);
if (rpm6 >= 38){
Blynk.notify("Temperature too hot, Press WATER button if you want water your plant");
Blynk.virtualWrite(V3,rpm6);
}
}
if (rpm >= 8000 && rpm <= 9023){
int rpm7 = rpm;
int rpm8 = rpm7 - 8000;
Blynk.virtualWrite(V4,rpm8);
if (rpm8 <= 5){
Blynk.notify("Water Too Acidic, Please Change Your Water");
Blynk.virtualWrite(V4,rpm8);
}
if (rpm8 >= 8){
Blynk.notify("Water Too Alkaline, Please Change Your Water");
Blynk.virtualWrite(V4,rpm8);
}
}
}
}
}
BLYNK_WRITE(V5)
{
b = param.asInt();
if (b==HIGH){
digitalWrite(PumpMotor,LOW);
delay (3000);
digitalWrite(PumpMotor,HIGH);
}
else{
digitalWrite(PumpMotor,HIGH);
}
}
void setup() {
Serial.begin(9600);
NodeMCU.begin(4800);
Blynk.begin(auth, ssid, pass);
pinMode(D2, INPUT);
pinMode(D1, OUTPUT);
pinMode(PumpMotor, OUTPUT);
digitalWrite(PumpMotor,HIGH);
timer.setInterval(400L, kecepatan);
}
void loop() {
Blynk.run();
timer.run();
}
I am very new to Arduino and Blynk. I hope someone can help me to get the notification from Blynk. Thank you in advanced.