Aquaponics Thread

For my aquaponics setup. Aquaponics update 1-10-16 - YouTube

Things you can help me with:
-I would like to make it farenheit, I assume it’s simple but I would also like to get it with some decimal points if at all possible. If I use slcd.print(dht.getHumidity(), 3) or any other number it gives me some weird binary.
-ideas for integrating a button.
-ideas for submersible ph and temperature sensors
-ideas for auto-feeding mechanisms

I’m thinking of coding the second relay to go 12 hours on 12 hours off for the growlight.

#include <DHT.h> //RHT03 (humidity/temperature) sensor library
#include <SerialLCD.h> //LCD screen library
#include <SoftwareSerial.h> //not 100% sure what this does

SerialLCD slcd(11,12); //setting LCD to pin 12
DHT dht; //creating dht variable from library DHT.

void setup()
{
    dht.setup(3); // Set the Sensor to pin 3
    slcd.begin(); // Start up the LCD
    slcd.backlight(); //light up the LCD
    slcd.setCursor(0,0); // Line 1
    slcd.print ("Aquaponics stuff"); 
    slcd.setCursor(0,1); // Line 2
    slcd.print("by Lucas");
    pinMode(4, OUTPUT); // setting Relay 1 as an output
    pinMode(5, OUTPUT); //         Relay 2
    pinMode(6, OUTPUT); //         Relay 3
    pinMode(7, OUTPUT); //         Relay 4
    delay(2000); // 2 second delay
}

void loop() {
    slcd.clear(); //Clears what was previously displayed on LCD
    slcd.setCursor(0,0); // Line 1
    slcd.print("  Humidity:");
    slcd.print(dht.getHumidity(), DEC); // shows the humidity%
    slcd.print("%");
    slcd.setCursor(0,1);
    slcd.print("Temperature:");
    slcd.print(dht.getTemperature(), DEC); // shows the temperature
    slcd.print((char)223); // Degree symbol
    slcd.print("C"); // Its in Celcius
    delay(2000); // 2 second delay
    
  if (dht.getTemperature() >= 25) { // if temperature rises to or 
    digitalWrite(4, HIGH);          // equals 25 degrees Celcius,
    digitalWrite(5, HIGH);          // all 4 relays are switched on
    digitalWrite(6, HIGH);          // to cut power. 
    digitalWrite(7, HIGH);
  } 
    else {                          // if not, the relays are 
      digitalWrite(4, LOW);         // switched off.
      digitalWrite(5, LOW);
      digitalWrite(6, LOW);
      digitalWrite(7, LOW);
    
  }
    
   }

Namaste.

For fahrenheit,

deg F = 1.8*(def C) + 32;

I got some new code! :slight_smile:
-I integrated a button to slide between 3 different pages (only really using 2 right now)

  • figured out my dht library had a .tofarenheit command

I still cannot figure out how to print out anything with a decimal point afterward.* only base 10 and can’t seem to change that.

#include <DHT.h> //RHT03 (humidity/temperature) sensor library
#include <SerialLCD.h> //LCD screen library
#include <SoftwareSerial.h> //Arduino Software

SerialLCD slcd(11,12); //setting LCD to pin 12
DHT dht; //creating dht variable from library DHT.
const int buttonPin = 2; //set the button to pin 2.
int buttonState; //create an integer called buttonState
int x = 0;                            // ...x = 0
int y = 0;                            // ...y = 0

void setup() {
    dht.setup(3); // Set the Sensor to pin 3
    slcd.begin(); // Start up the LCD
    slcd.backlight(); //light up the LCD
    slcd.setCursor(0,0); // Line 1
    slcd.print ("   Aquaponics"); 
    slcd.setCursor(0,1); // Line 2
    slcd.print("    by Lucas");
    pinMode(4, OUTPUT); // setting Relay 2 as an output
    pinMode(5, OUTPUT); //         Relay 4
    pinMode(6, OUTPUT); //         Relay 1
    pinMode(7, OUTPUT); //         Relay 3
    pinMode(buttonPin, INPUT); // sets input 2 to an input
    delay(3000); // 3 second delay
}

void loop() {
  delay(dht.getMinimumSamplingPeriod()); //Delay for smallest time
  float temperature = (dht.toFahrenheit(dht.getTemperature())); //make a float called temperature to hold the temperature in Farenheit.
  float humidity = (dht.getHumidity()); // make a float called humidity to hold the humidity in %.
  buttonState = digitalRead(buttonPin); //Checks the button state and assigns it to buttonState
  
 if (buttonState == HIGH) {     // if button state is high
    x = (x + 1);                // x is x + 1
   if (x == 3) {                // if x = 3
    x = 0;                      // x goes back to 0
   }
   }
   
 if (temperature >= 70) {       // if temperature rises to or 
     digitalWrite(4, HIGH);       // equals 70F then right column
     digitalWrite(5, HIGH);       // of relays is turned on.
     y = 0;                       // setting y variable to 0.
  } 
 else {                           // if not, the relays are turned 
     digitalWrite(4, LOW);        // off allowing power flow.
     digitalWrite(5, LOW);
     y = 1;                       // setting y variable to 1
    }
     slcd.clear(); //Clears what was previously displayed on LCD
     slcd.setCursor(0,0); // Line 1
     
  if (x == 0){                        //Page 1
        slcd.print("Temperature:");   
        slcd.print(temperature, DEC); // print temperature 
        slcd.print(char(223));
        slcd.print("F");
        slcd.setCursor(0,1);          // Line 2
        slcd.print("  Humidity:");
        slcd.print(humidity, DEC);    //print humidity
       
        slcd.print("%");
      }
  else if (x == 1){                   //Page 2
        slcd.print("Insert some code");
  }
  else if (x == 2){                   //Page 3
    slcd.print("Right Column:");
      if (y == 0) {                   // if relay is on
        slcd.print("OFF");            // power is off
      }
      else if (y == 1) {              // if relay is off
        slcd.print("ON");             // power is on.
      }
      
    slcd.setCursor(0,1);              // Line 2
    slcd.print("Left Column:ON");     //Left column always has power.
    /// NEED SHIT HERERERERERE
   }
       }

*I still cannot figure out how to print out anything with a decimal point afterward.** only base 10 and can't seem to change that.

All of your variables are declared as integers and by definition integers have no decimal portion, think of integers as counting numbers

LucasThom7:
I still cannot figure out how to print out anything with a decimal point afterward.* only base 10 and can’t seem to change that.

As wwbrown points out, integers don’t have a decimal portion.

A common trick when using integer math is to scale the integer by some value. You just keep in mind while programming the value is scaled.

For example, if you wanted to represent the number 1.001 as an integer, you’d scale it by one thousand and use 1001.

These scaled integers can present a problem when you’re ready to print the number. There are several ways around this and the method I’m about to show you is probably the most cumbersome way to output scaled integers but it’s the way I know how to use (since I wrote the function).

/*
 *   DecPoint160116b
 *   
 *   By Duane Degn
 *   January 16, 2016
 *   
 *   A program to demonstrate one way (likely not the best way)
 *   to output scaled integers.
 *   
 *   The line: "printScaledIntegerUnsigned(1009, SCALED_MULTIPLIER_THOUSAND);"
 *   will produce the output "1.009".
 *   
 *   There are separate functions for signed integers and unsigned integers
 *   to make it easier to output time variables which generally use
 *   unsigned long variables.
 *   
 */

const unsigned long SCALED_MULTIPLIER_THOUSAND = 1000;
const unsigned long SCALED_MULTIPLIER_MILLION = 1000000;
long signedTime;

void setup() 
{
  Serial.begin(9600);
  Serial.println("Scaled Integer Decimal Point Demo");
  signedTime = millis(); // so we have an initial "previousTime"
}

void loop() 
{
  unsigned long nowMicroseconds = micros();
  // Let's use a scaled integer to hold seconds scaled by
  // a factor of one million.
  unsigned long nowSecondsScaledByMillion = nowMicroseconds;

  unsigned long nowMilliseconds = nowMicroseconds / 1000;
  
  // Let's use a scaled integer to hold seconds scaled by
  // a factor of one thousand.
  unsigned long nowSecondsScaledByThousand = nowMilliseconds;

  Serial.println();
  Serial.println("Time since program start:");
  Serial.println();
  Serial.print("(normal integer)        microseconds = ");
  Serial.print(nowMicroseconds);
  Serial.println(" us");
  Serial.print("(normal integer)       milliseconds = ");
  Serial.print(nowMilliseconds);
  Serial.println(" ms");
  Serial.print("(scaled by 1000000 integer) seconds = ");
  printScaledIntegerUnsigned(nowMicroseconds, SCALED_MULTIPLIER_MILLION);
  Serial.println(" s");
  Serial.print("(scaled by 1000 integer) seconds = ");
  printScaledIntegerUnsigned(nowMilliseconds, SCALED_MULTIPLIER_THOUSAND);
  Serial.println(" s");
  Serial.print("1.009 = ");
  printScaledIntegerUnsigned(1009, SCALED_MULTIPLIER_THOUSAND);
  Serial.println();
  Serial.print("123.456 = ");
  printScaledIntegerUnsigned(123456, SCALED_MULTIPLIER_THOUSAND);
  Serial.println();
  
  signedTimeDemo(nowMilliseconds);
  
}

byte printScaledIntegerUnsigned(unsigned long scaledValue, unsigned long scaleFactor)
{
  byte characterCount = 0;
  unsigned long tempValue;

  if (scaledValue >= scaleFactor)
  {
    // digits left of decimal point
    tempValue = scaledValue / scaleFactor;
    Serial.print(tempValue);
    scaledValue %= scaleFactor; // This value will be on the right of the decimal point.
  }
  else // zero before decimal point
  {
    Serial.print("0");
  }
  Serial.print(".");
  
  // print out right side one digit at a time
  // we need to print one digit at a time to catch zeros
  // immediately after the decimal point
  while (scaleFactor > 1)
  {
    scaleFactor /= 10;
    tempValue = scaledValue / scaleFactor;
    Serial.print(tempValue); // single digit
    scaledValue %= scaleFactor;    
  }
  return characterCount; // in case calling program wants to know number of characters
}

byte printScaledIntegerSigned(long scaledValue, unsigned long scaleFactor)
{
  byte characterCount = 0;
  if (scaledValue < 0)
  {
    Serial.print("-");
    scaledValue *= -1;
    characterCount++;
  }
  characterCount += printScaledIntegerUnsigned((unsigned long) scaledValue, scaleFactor);
  return characterCount;
}

void signedTimeDemo(long newTime)
{
  long previousTime = signedTime;
  signedTime = newTime;
  
  Serial.print("previousTime - signedTime = ");
  printScaledIntegerSigned(previousTime - signedTime, SCALED_MULTIPLIER_THOUSAND);
  Serial.println(" s");

  Serial.print("-1.010 = ");
  printScaledIntegerSigned(-1010, SCALED_MULTIPLIER_THOUSAND);
  Serial.println();
  Serial.print("-123.456 = ");
  printScaledIntegerSigned(-123456, SCALED_MULTIPLIER_THOUSAND);
  Serial.println();
  
}

This line of code below:

  printScaledIntegerSigned(-1010, SCALED_MULTIPLIER_THOUSAND);

Will produce the following output.

-1.010

Here’s the output from loop of main program.

Time since program start:

(normal integer)        microseconds = 4097688 us
(normal integer)       milliseconds = 4097 ms
(scaled by 1000000 integer) seconds = 4.097688 s
(scaled by 1000 integer) seconds = 4.097 s
1.009 = 1.009
123.456 = 123.456
previousTime - signedTime = -0.345 s
-1.010 = -1.010
-123.456 = -123.456

You’ll want to replace the “Serial.print” calls with “slcd.print” calls.