Aquaponics Water Cycle and Temperature Monitor

I wanted to monitor the water temperature and the watering cycle of my aquponics grow beds.
And also send an alarm if one of the water cycles quick working.
I was able to use Blynk to monitor my grow beds.

I am using a NodeMCU ESP 12E and the Dallas DS18B20 temperature probes and three water level
switches.

In my Sketch I have used various publishers that I have found via Open Source and GitHub.

I need to apologize for my variables and descriptions because my programing background is Basic
and AllenBradly PLCs where the use of memory is very limited and so I was conservative in my descriptions.

/**************************************************************

  • IoT Multiple Temperature Monitor with Blynk
  • Blynk library is licensed under MIT license
  • This example code is in public domain.
  • Multiple OneWire Sensor: DS18B20
  • Developed by Marcelo Rovai - 25 August 2017
    **************************************************************/

/* ESP & Blynk */
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <Bounce2.h>

const int sBed = D1; // South Grow Bed
const int mBed = D2; // Middle Grow Bed
const int nBed = D3; // North Grow Bed

int Time = 7.2e+6; //7.2e+6 = aprox 2 hours for no flow ararm

int tD = 3000; //Timed delay

float SBed;
float MBed;
float NBed;

// Used for no flow alarm

unsigned long S = 0;
unsigned long M = 0;
unsigned long N = 0;

// float TimeS;

unsigned long startTime1;
unsigned long startTime2;
unsigned long startTime3;
unsigned long endTime1;
unsigned long endTime2;
unsigned long endTime3;
unsigned long TimeS;
unsigned long TimeM;
unsigned long TimeN;
byte timerRunning1;
byte timerRunning2;
byte timerRunning3;

/* Blynk credentials */
char auth = “********************8”;

/* WiFi credentials /
char ssid = "
";
char pass = "
";

/* TIMER */
#include <SimpleTimer.h>
SimpleTimer timer;

/* DS18B20 Temperature Sensor */
#include <OneWire.h>
#include<DallasTemperature.h>
#define ONE_WIRE_BUS 2 // DS18B20 on arduino pin2 corresponds to D4 on physical board
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature DS18B20(&oneWire);
int temp_0;
int temp_1;

// Initialise the Pushbutton Bouncer object
Bounce bouncer = Bounce();

void setup()
{

Serial.begin(115200);
Blynk.begin(auth, ssid, pass);
DS18B20.begin();
timer.setInterval(1000L, getSendData);
Serial.println(" ");
Serial.println(“Testing Dual Sensor data”);

pinMode(sBed, INPUT);
pinMode(mBed, INPUT);
pinMode(nBed, INPUT);

// Setup pushbutton Bouncer object
bouncer.attach(sBed);
bouncer.interval(60000);
bouncer.attach(mBed);
bouncer.interval(60000);
bouncer.attach(nBed);
bouncer.interval(60000);

}

void loop()
{
timer.run(); // Initiates SimpleTimer
Blynk.run();
int isReedSwitchOpen = !digitalRead(02);
if(isReedSwitchOpen){
BLYNK_LOG(“Switch Open”);
Blynk.email("sparcdude@gmail.com", “From Blynk”, “The Reed Switch Has Been Opened”);

}
SouthBed();
MiddleBed();
NorthBed();
}

void SouthBed(){
if (timerRunning1 == 0 && digitalRead(sBed) == HIGH){
startTime1 = millis();

  timerRunning1 = 1;
}

if (timerRunning1 == 1 && digitalRead (sBed) == LOW ){

delay(tD);

  endTime1 = millis();
  timerRunning1 = 0;             
  TimeS = ((endTime1 - startTime1) /60000);
  Serial.print("sBed cycle time in minuets: ");
  Serial.println(TimeS);
  SBed = (TimeS = ((endTime1 - startTime1) /60000));
  Serial.println (SBed);
  Blynk.virtualWrite(2, SBed); 
  Blynk.virtualWrite(6, 0);  
}
 S = millis(); 

}

void MiddleBed(){
if (timerRunning2 == 0 && digitalRead(mBed) == HIGH){
startTime2 = millis();

  timerRunning2 = 1;
}
if (timerRunning2 == 1 && digitalRead (mBed) == LOW){

delay(tD);

  endTime2 = millis();
  timerRunning2 = 0;
  TimeM = ((endTime2 - startTime2) /60000);
  Serial.print("mBed cycle time in minuets: ");
  Serial.println(TimeM);
  MBed = (TimeM = ((endTime2 - startTime2) /60000));
  Serial.println (MBed);
  Blynk.virtualWrite(3, MBed);
  Blynk.virtualWrite(7, 0);
}
 M = millis();

}

void NorthBed(){
if (timerRunning3 == 0 && digitalRead(nBed) == HIGH){
startTime3 = millis();

  timerRunning3 = 1;
}  
if (timerRunning3 == 1 && digitalRead (nBed) == LOW){

delay(tD);

  endTime3 = millis();
  timerRunning3 = 0;
  TimeN = ((endTime3 - startTime3) /60000);
  Serial.print("nBed cycle time in minuets: ");
  Serial.println(TimeN);
  NBed = (TimeN = ((endTime3 - startTime3) /60000));
  Serial.println (NBed);
  Blynk.virtualWrite(4, NBed);
  Blynk.virtualWrite(8, 0);
}
N = millis();

}

/***************************************************

  • Send Sensor data to Blynk
    **************************************************/
    void getSendData()
    {
    DS18B20.requestTemperatures();
    temp_0 = DS18B20.getTempFByIndex(0); // Sensor 0 will capture Temp in Fahrenheit
    temp_1 = DS18B20.getTempFByIndex(1); // Sensor 0 will capture Temp in Fahrenheit

Serial.print(“Temp_0: “);
Serial.print(temp_0);
Serial.print(” oF . Temp_1: “);
Serial.print(temp_1);
Serial.println(” oF”);

Blynk.virtualWrite(10, temp_0); //virtual pin V10
Blynk.virtualWrite(11, temp_1); //virtual pin V11

// No flow alarms

     if (timerRunning1 == 1 && S >= startTime1 + Time){
    
  Serial.println("South Bed Stoped");
  Blynk.virtualWrite(6, 1);
}  
     if (timerRunning1 == 1 && M >= startTime2 + Time){

  Serial.println("Middle Bed Stoped");
  Blynk.virtualWrite(7, 1);
}  
     if (timerRunning1 == 1 && N >= startTime3 + Time){
 
  Serial.println("NOrth Bed Stoped");
  Blynk.virtualWrite(8, 1);
}  

}

100% • 75% • 50%

/media/joe/USB Disk/Aquopnic Water Level Monitor_bb.jpg

Uploading: image.png…

100% • 75% • 50%


Serial.println(" ");
Serial.println(“Testing Dual Sensor data”);

pinMode(sBed, INPUT);
pinMode(mBed, INPUT);
pinMode(nBed, INPUT);

// Setup pushbutton Bouncer object
bouncer.attach(sBed);
bouncer.interval(60000);
bouncer.attach(mBed);
bouncer.interval(60000);
bouncer.attach(nBed);
bouncer.interval(60000);

}

void loop()
{
timer.run(); // Initiates SimpleTimer
Blynk.run();
int isReedSwitchOpen = !digitalRead(02);
if(isReedSwitchOpen){
BLYNK_LOG(“Switch Open”);
Blynk.email("sparcdude@gmail.com", “From Blynk”, “The Reed Switch Has Been Opened”);

}
SouthBed();
MiddleBed();
NorthBed();
}

void SouthBed(){
if (timerRunning1 == 0 && digitalRead(sBed) == HIGH){
startTime1 = millis();

  timerRunning1 = 1;
}

if (timerRunning1 == 1 && digitalRead (sBed) == LOW ){

delay(tD);

  endTime1 = millis();
  timerRunning1 = 0;             
  TimeS = ((endTime1 - startTime1) /60000);
  Serial.print("sBed cycle time in minuets: ");
  Serial.println(TimeS);
  SBed = (TimeS = ((endTime1 - startTime1) /60000));
  Serial.println (SBed);
  Blynk.virtualWrite(2, SBed); 
  Blynk.virtualWrite(6, 0);  
}
 S = millis(); 

}

void MiddleBed(){
if (timerRunning2 == 0 && digitalRead(mBed) == HIGH){
startTime2 = millis();

  timerRunning2 = 1;
}
if (timerRunning2 == 1 && digitalRead (mBed) == LOW){

delay(tD);

  endTime2 = millis();
  timerRunning2 = 0;
  TimeM = ((endTime2 - startTime2) /60000);
  Serial.print("mBed cycle time in minuets: ");
  Serial.println(TimeM);
  MBed = (TimeM = ((endTime2 - startTime2) /60000));
  Serial.println (MBed);
  Blynk.virtualWrite(3, MBed);
  Blynk.virtualWrite(7, 0);
}
 M = millis();![image|281x500](upload://fsREGSkczCGayDyc8WQ1feAbloo.jpeg) 

}

void NorthBed(){
if (timerRunning3 == 0 && digitalRead(nBed) == HIGH){
startTime3 = millis();

  timerRunning3 = 1;
}  
if (timerRunning3 == 1 && digitalRead (nBed) == LOW){

delay(tD);

  endTime3 = millis();
  timerRunning3 = 0;
  TimeN = ((endTime3 - startTime3) /60000);
  Serial.print("nBed cycle time in minuets: ");
  Serial.println(TimeN);
  NBed = (TimeN = ((endTime3 - startTime3) /60000));
  Serial.println (NBed);
  Blynk.virtualWrite(4, NBed);
  Blynk.virtualWrite(8, 0);
}
N = millis();

}

/***************************************************

  • Send Sensor data to Blynk
    **************************************************/
    void getSendData()
    {
    DS18B20.requestTemperatures();
    temp_0 = DS18B20.getTempFByIndex(0); // Sensor 0 will capture Temp in Fahrenheit
    temp_1 = DS18B20.getTempFByIndex(1); // Sensor 0 will capture Temp in Fahrenheit

Serial.print(“Temp_0: “);
Serial.print(temp_0);
Serial.print(” oF . Temp_1: “);
Serial.print(temp_1);
Serial.println(” oF”);

Blynk.virtualWrite(10, temp_0); //virtual pin V10
Blynk.virtualWrite(11, temp_1); //virtual pin V11

// No flow alarms

     if (timerRunning1 == 1 && S >= startTime1 + Time){
    
  Serial.println("South Bed Stoped");
  Blynk.virtualWrite(6, 1);
}  
     if (timerRunning1 == 1 && M >= startTime2 + Time){

  Serial.println("Middle Bed Stoped");
  Blynk.virtualWrite(7, 1);
}  
     if (timerRunning1 == 1 && N >= startTime3 + Time){
 
  Serial.println("NOrth Bed Stoped");
  Blynk.virtualWrite(8, 1);
}  

}

file:///media/joe/USB%20Disk/Aquopnic%20Water%20Level%20Monitor_bb.jpg

2 Likes