Christian
Published © GPL3+

Professional Hydroponics CO2 Monitoring

Build a monitoring system that will track your CO2 levels

IntermediateFull instructions provided2 hours1,190

Things used in this project

Hardware components

IO Expander
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Wiring Diagram

Hydroponics CO2 Monitoring Wiring Diagram

Code

Professional Hydroponics CO2 Control

C/C++
Build a monitoring systems that will monitor your CO2 levels
#define CO2_SAMPLES_IN_MIN      5
#define CO2_INTERVAL            (SEC_IN_MIN / CO2_SAMPLES_IN_MIN)
#define MAX_CO2_FAILS           10
 
const char ONEWIRE_TO_I2C_CO2[] = "i2s4a";   // I2C BUS - CO2 Sensor
const char CO2_SENSOR[] =       "st16;ic0";  // SCD30 CO2 Sensor 100kHz
const char INIT_CO2[] =         "si;sc3,2";  // SCD30 Init; Config measurement interval to 50 sec
 
...
 
  float co2, co2_temp, co2_relative;
  static uint8_t co2_samples = 0;
  static float co2_data[CO2_SAMPLES_IN_MIN];
 
...
 
        // Check for CO2 sensor
        co2 = -1; co2_temp = -1; co2_relative = -1;
        if (SerialCmdNoError(ONEWIRE_TO_I2C_CO2) &&
            SerialCmdDone(CO2_SENSOR)) {
          if (init_co2) {
            if (SerialCmdNoError(INIT_CO2)) {
              init_co2 = false;
              co2_fail = false;
            }
          }
          else {
            if (co2_samples) {
              SerialCmd("sr");
              if (SerialReadFloat(&co2_data[co2_samples]))
              {
                SerialReadFloat(&co2_temp);
                SerialReadFloat(&co2_relative);
                co2_samples++;
              }
              else co2_fail++;
              SerialReadUntilDone();
            }
            else co2_fail++;
 
            if (co2_samples > 2) {
              qsort(co2_data, co2_samples, sizeof(float), comparefloats);
              co2 = co2_data[co2_samples / 2]; // Median Filter
              co2_samples = 0;
              co2_fail = false;
            }
            else {
                if (co2_fail >= MAX_CO2_FAILS) {
                  SerialCmdDone("sc10"); // Soft reset CO2 sensor
                  init_co2 = true;  
                  co2_fail = false;
                }
            }
          }
        }
        else {
          co2 = ERROR_NO_ROM;
          init_co2 = true;
        }
 
...
 
            if (co2 != ERROR_NO_ROM) {
              if (color_temp == ERROR_NO_ROM || clk.tm_min & 1 == 1) {
                Serial.print(";sa0;sd0,48,\"CO\";sf0;sd24,44,\"2\";sa1;sf1;sd70,48,\"");
                Serial.print((int)co2);
                Serial.print("\";sd127,48,\"");
                Serial.print(C2F(co2_temp), 1);
                Serial.print("\"");
              }
            }
 

Credits

Christian
24 projects • 135 followers
Senior Embedded Engineer
Contact

Comments

Please log in or sign up to comment.