Aquaponics Growroom Sketch Working

THIS IS NOT A QUESTION

Just posting my Aquaponics sketch works on 1.04 it’s not fully completed but still usable, or you may wish to play with it.
It contains ball valves, float switches, extractor fan, inlet & outlet working with DHT11 relays and all that jazz

I will post the full completed sketch when I obtain all the hardware needed

//Define PIN's
#include <Time.h>
#include <TimeAlarms.h>
#define outletballvalveopen  3
#define outletballvalveclosed 7
#define ballvalvearth 6
#define solenoidPin 1
#define airpump 2
#define inletballvalve 5
#define floatswitchaqua 6
#define floatswtchtreserve 7
#define ventilationPin 8
#define relaylights 9
#define waterpump 10
#define airwaterjet 11
#define dht_dpin A4
#define DHTTYPE DHT11
const int buttonPin = 2;
byte compFunc; 
byte dht_dat[5]; 
int buttonState = 0; 
void setup()
{ 
  Serial.begin(9600);
  pinMode(buttonPin, INPUT); 
  pinMode(ballvalvearth ,OUTPUT);
  pinMode(outletballvalveclosed ,OUTPUT);
  pinMode(ventilationPin,OUTPUT);
  pinMode(solenoidPin, OUTPUT);
  pinMode(relaylights, OUTPUT);
  pinMode(waterpump, OUTPUT);
  pinMode(airpump, OUTPUT);
  pinMode(outletballvalveopen, OUTPUT);
  pinMode(inletballvalve, OUTPUT);
  pinMode(airwaterjet, OUTPUT);
  pinMode(floatswtchtreserve, INPUT);
  pinMode(floatswitchaqua, INPUT);
  digitalWrite(ventilationPin,HIGH);
  digitalWrite(solenoidPin, HIGH);
  digitalWrite(relaylights, HIGH);
  digitalWrite(waterpump, HIGH);
  digitalWrite(airpump, HIGH);
  digitalWrite(outletballvalveopen, HIGH);
  digitalWrite(inletballvalve, HIGH);
  digitalWrite(airwaterjet, HIGH);
  Serial.println(F("_________AquaDuino by ArkAnArky_________"));
  setTime(05,59,30,1,07,13); // 
  Alarm.alarmRepeat(06,00,00, MorningAlarm);  // 6:00am every day
  Alarm.alarmRepeat(18,00,00,EveningAlarm);  // 6:00pm every day
  delay(300); 
  delay(700); 
}
void loop(){ 
  buttonState = digitalRead(buttonPin);
  InitDHT();
  ReadDHT();               
  switch (compFunc){
  case 0:
    Serial.print(dht_dat[0], DEC);
    Serial.println (F("% Humidity  "));
    Serial.println (F("Temperature = "));
    Serial.print(dht_dat[2], DEC);
    Serial.println (F("*C "));
    digitalClockDisplay();
    Alarm.delay(1000); 
    break;
  case 1:
    Serial.println (F("Error 1: DHT start condition 1 not met."));
    break; 
  case 2:
    Serial.println (F("Error 2: DHT start condition 2 not met."));
    break;
  case 3:
    Serial.println (F("Error 3: DHT checksum error."));
    break;
  default:
    Serial.println (F("Error: Unrecognized code encountered."));
    break;
  } 
  if(dht_dat[0] >= 40 && dht_dat[2] >= 30){
    digitalWrite(ventilationPin, LOW);
    digitalWrite(inletballvalve, LOW);
    delay(500);
    digitalWrite(airwaterjet, LOW);
    Serial.println (F("ventilation running"));
  } 
  else {
    digitalWrite(ventilationPin, HIGH);
    digitalWrite(airwaterjet, HIGH);
    delay(500);
    digitalWrite(inletballvalve, HIGH);
    Serial.println (F("ventilation off"));
  }
  if (floatswitchaqua, LOW);
  Serial.println (F("aquarium water level low."));
  digitalWrite(outletballvalveopen, LOW);
  delay(2000);
  digitalWrite(outletballvalveclosed, HIGH);
  if (floatswitchaqua, HIGH);
  digitalWrite(outletballvalveclosed, LOW);
  delay(2000);
  digitalWrite(outletballvalveopen, HIGH);
  Serial.println (F("aquarium water level normal."));
  Serial.println (F(" \n\n"));
  delay(2000); 
}
void InitDHT()
{
  pinMode(dht_dpin,OUTPUT);
  digitalWrite(dht_dpin,HIGH);
}
void ReadDHT()
{
  compFunc=0;
  byte dht_in;
  byte i;
  digitalWrite(dht_dpin,LOW);
  delay(50);
  digitalWrite(dht_dpin,HIGH);
  delayMicroseconds(40); 
  pinMode(dht_dpin,INPUT);
  dht_in=digitalRead(dht_dpin);
  if(dht_in){
    compFunc=1; 
    return;
  } 
  delayMicroseconds(80);
  dht_in=digitalRead(dht_dpin);
  if(!dht_in){
    compFunc=2;  
    return;
  } 
  delayMicroseconds(80);
  for (i=0; i<5; i++)dht_dat[i] = read_dht_dat();
  pinMode(dht_dpin,OUTPUT);
  digitalWrite(dht_dpin,HIGH);
  byte dht_check_sum =dht_dat[0]+dht_dat[1]+dht_dat[2]+dht_dat[3];
  if(dht_dat[4]!= dht_check_sum){
    compFunc=3;
  }//DHT checksum error
}
byte read_dht_dat(){
  byte i = 0;
  byte result=0;
  for(i=0; i< 8; i++){
    while(digitalRead(dht_dpin)==LOW);
    delayMicroseconds(45);
    if (digitalRead(dht_dpin)==HIGH) result |=(1<<(7-i));
    while (digitalRead(dht_dpin)==HIGH);
  }
  return result;
  if (buttonState == HIGH) {
    digitalWrite(ballvalvearth ,HIGH);
    digitalWrite(outletballvalveclosed,HIGH);
    Serial.println (F("outletballvalveopen"));
  } 
  else {
    Serial.println (F("WATER ADJUSTING"));
  }
  if (buttonState == LOW) { 
    digitalWrite(outletballvalveclosed,LOW);
    digitalWrite(ballvalvearth ,LOW);
    digitalWrite(outletballvalveopen,HIGH);
    Serial.println (F("outletballvalveclosed"));
  } 
  else {
    digitalWrite(outletballvalveopen,LOW);
    digitalWrite(ballvalvearth ,HIGH);
    digitalWrite(outletballvalveclosed,HIGH); 
  }
}
void MorningAlarm(){
  Serial.println (F("Good-morning Arky"));
  Serial.println (F("Aquaduino System Starting"));
  digitalWrite(solenoidPin, LOW);
  digitalWrite(relaylights, LOW);
  digitalWrite(waterpump, LOW);
  digitalWrite(airpump, LOW);
  digitalWrite(outletballvalveclosed, LOW);
  digitalWrite(outletballvalveopen, HIGH);
  digitalWrite(inletballvalve, HIGH);
}
void EveningAlarm(){
  Serial.println (F("Goodnight Arky"));
  Serial.println (F("Aquaduino System Sleeping"));           
  digitalWrite(solenoidPin, HIGH);
  digitalWrite(relaylights, HIGH);
  digitalWrite(waterpump, HIGH);
  digitalWrite(airpump, HIGH);
  digitalWrite(outletballvalveopen, LOW);
  digitalWrite(outletballvalveclosed, HIGH);
  digitalWrite(inletballvalve, LOW);
}
void digitalClockDisplay()
{
  Serial.print(hour());
  printDigits(minute());
  printDigits(second());
  Serial.println (); 
}
void printDigits(int digits)
{
  Serial.print(":");
  if(digits < 10)
    Serial.print('0');
  Serial.print(digits);
}

Aquaponics?
I am building one experiment of aquaponics too......
And of course there is a bit it theory in it that will require some data to be stored and checked.
So one day I heard about Arduino and now I am trying to put together the two things.....
Could you please tell me if I am right in this?

  • I will need to see on my PC (that I will leave dedicated to this experiment) all the parameters of temperature, PH, Flow, DO, ORP.... Bla bla bla for a total of probably sensors.
  • data will have to get stored for analysis in xls file or txt
  • since there are two stages in my system that every 15 minutes will have to swap (flod and flood), I would like that my Arduino send to the solenoid valves a signal to close one and open the other circuit.
    -probably 3 water level alarms that if reached they will shut down the pumps
    -one sensor on the main power line that in case of no power will send a signal to the generator to kick in.
    Now,
    Do you think all of this can be accomplished with an Arduino system or do I have to look for another product?
    I will like to have your opinion and see how your aquaponics set up works....
    All the best and thanks for your time
    Andrea

AquaArkyAnArky,

I would add an RTC, plants are quite sensitive when it comes to hours of daylight.
Should the arduino now reset at 6pm for some reason (no power for 5 min for example), date and time will be set using the (wrong) info found in your sketch, resulting in a day of 36 hours. Correcting the time later may also result in a second "shock".

Should you have no power for 5 mins while using an RTC, arduino can read the correct time and reduce harm to a single shock of 5 minutes...

If air-humidity is an important factor for your plants, using a DHT11 may... by the way not be the best choice. I bought 5 in an auction and they all spew data, but I notice a difference in humidity-readings up to 40% and temperature up to 3 degrees c.

Andrea,
You project seems possible, but it probably requires quite some time to get each part working and to combine them in one project.

To both of you, personally I still grow on soil and one thing I'd be very concerned about is safety.
Should one of the pumps/valves/sensors dysfunction, you may have to swim to correct it.

Hi Andrea

Sorry for delayed response I’m not quite sure about some questions but here goes
"I will need to see on my PC (that I will leave dedicated to this experiment) all the parameters of temperature, PH, Flow, DO, ORP.... Bla bla bla for a total of probably sensors."

= you can store all the data on a sd card you can get a reader on eBay for next to nothing then read the data from the sd card

"I would like that my Arduino send to the solenoid valves a signal to close one and open the other circuit. "

=yes you set your pins high or low connect them to a relay also only £5 for a 8 channel relay on eBay

"Probably 3 water level alarms that if reached they will shut down the pumps
-one sensor on the main power line that in case of no power will send a signal to the generator to kick in. "
yes you can use float switches or even just two screws connected + &- when the water touches them they become conductive like a switch sending a signal to the arduino from that you can create any action you like,
I use ball valves they cost between £15 an £30 on eBay depending on size they are listed as DN15= 1/2" BSP, DN20= 3/4" BSP, DN25= 1" BSP,

you could use a leisure battery instead of a generator the water pump is the most elec hungry maybe connected to a solar panel to keep it topped up as Simpson said a real time clock is a must you can still use the time alarms I am still messing about with my system its pretty big I have grown with aquaponics before and as long as you look after the pump even replace it when it gets a bit noisy everything is fine I have a back up power system battery operated you can get the arduino to send you a text message if something fails or just updates it can post to twitter also you can even go as far as cctv and have a video sent to your phone if something stops working this is all done by water alarms

Simpson I like soil as much as the next man but the yields from aquaponics and the bonus of farming my own trout I cant turn back I look at it like a car if you look after your system your system looks after you

Andrea if you need any further help I have been doing aquaponics for a while and have some good tricks to save money and what corners should not be cut

Hope I covered everything

I only just finished writing & debugging my aquaponics system last week. My system is running on an Attiny85, i only use 3 inputs & 3 outputs.
I use 2x float switches to tell me when the nft's are full or when they are empty, there is a delay of 1 hour between refilling the nft's.
I use an ldr to let me know when it is dark, i then check the level of water in the nft, & drain the system before going to sleep and waiting for morning. My growing medium is polystyrene beads, they have a porous surface areas & are chemically inert, so the worms are very happy @ the moment. I am not a big fish eater, so goldfish are in the tank :slight_smile: When the nft's drain, the microbial fluid (Fish water) is collected in a shallow pond just below, it is filtered by various aquatic plants, that act as bio filters & double as fish/yabby food. As the water rises in this pond, a raised centre outlet drains the excess into the tank below, where yabbies (Australian Freshwater Crayfish) gobble up any left over residues.

I have a reserve tank, that keeps the water level up due to hydration, there is no need for mcu control as the float valve is a mechanical device which does this for me.
I filter the fish water when it enters the nft, too remove large pieces, which is collected and used for fertilizer.

I chose an Attiny85 as i didn't have a necessity for a screen, i really only needed a pump, a solenoid, and a way to tell if the system was full or empty.
I am currently trying to design a PH EC board based on the Attiny85 (since i ordered 20 of them), and integrate smaller modular systems, that act as a whole unit.

Carp are not a tasty fish to me, your mileage may vary, but they can & will survive in muddy water, minus temperatures, water above 20 celsius, and are quite fearless at going to the surface for air.

Find me a good recipe & i'll eat them :slight_smile:

Hi guys, thanks a lot for your help and sorry for my late reply....... I had some time off to finish my installation and get the parts from the US
This is a project between me and my friend, involving out kids for a school presentation in few months.
We are willing to invest a bit of money(only where necessary) to get proper and reliable results that can keep our kids (and of course my) attention up and running......
Yurt got all the sensors and relays.
Now it's time to go on the keyboard and try to have some number on screen....

If I was a Software programmer it would been easy.....
Since I am not, I have opted for this software called Lab View that I think it will help me a lot in developing this application.

The tricky part is not only acquiring the datas but also write the right software that will keep an eye on all the values and eventually take action (water level too high or water temperature to high or switch from "flood" to "flow" mode.......)

I think we started with a simple idea and on the way we got fancy...... So now we have 3 pumps, 4 solenoids, 2 3-way valves, 6 temperature sensor (DS18B20), 5 PH sensors, 3 DO, 3 flowmeters, 1 ambient temp and humidity sensor, 2 underwater lights plus some other small gadgets......

I am building a screen representation of all the system so if someone has ideas it will be easier talk about the same thing.....

I am going back to the books......
If you have some experience in Software development please drop a message, we will need all the help possible to don't look to 'Neanderthal' on our kids eyes.....
Regards
Andrea