# Aquaponics Water Cycle and Temperature Monitor

**URL:** <https://forums.losant.com/t/aquaponics-water-cycle-and-temperature-monitor/2247>\
**Category:** Show Losant\
**Created:** [October 5, 2019, 9:46pm UTC](https://forums.losant.com/t/aquaponics-water-cycle-and-temperature-monitor/2247 "2019-10-05T21:46:18Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joseph\_Gerard](https://avatars.discourse-cdn.com/v4/letter/j/e47c2d/32.png) [@Joseph\_Gerard](https://forums.losant.com/u/Joseph_Gerard)\
**Post date:** [October 5, 2019, 9:46pm UTC](https://forums.losant.com/t/aquaponics-water-cycle-and-temperature-monitor/2247/1 "2019-10-05T21:46:19Z")

</div>

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](https://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();

```auto
  timerRunning1 = 1;
}

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

```

delay(tD);

```auto
  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();

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

```

delay(tD);

```auto
  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();

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

```

delay(tD);

```auto
  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

```auto
     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);
}  

```

}

 ![image](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/6/6c63ecf0f284c871da67ad1f4e9b2ac7983e9da4.jpeg)

100% • 75% • 50%

/media/joe/USB Disk/Aquopnic Water Level Monitor\_bb.jpg

Uploading: image.png…

 ![image](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/0/0a1cce2e73a082e9cc2c75c848ec87641c0984bf.jpeg)

100% • 75% • 50%

 ![image](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/0/0a1cce2e73a082e9cc2c75c848ec87641c0984bf.jpeg)  
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);
}  

```

}

 ![image](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/0/0a1cce2e73a082e9cc2c75c848ec87641c0984bf.jpeg)

 ![image](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/f/f1ebe132fc1731ab91ac6eef39f1b5426c59854a.jpeg)

 ![image](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/6/6c63ecf0f284c871da67ad1f4e9b2ac7983e9da4.jpeg)

 ![image](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/a/affe0d2a278af5a880cdedc07d9c51dd93e22eea.png) file:///media/joe/USB%20Disk/Aquopnic%20Water%20Level%20Monitor\_bb.jpg
