Back to the Arduino sketch

Customer Happiness Check-In

NewImage

 plant key:

genovese basil parsley sweet basil stevia stevia lettuce
genovese basil thyme sweet basil stevia stevia kale

I’m starting to see multiple plants in most of the rockwools. I’ll trim these. A concern I have is the long stems of the lettuce and kale. I attribute this to not getting enough PAR light.

Open Source

The Arduino code I am talking about in this post is TheLeafSpa.ino – located at this GitHub location.

Completing Logging

I got logging sensor data working and documented in this post.  There are other things I want to log:

enum logRow_t {
  SensorData,
  PumpOn,
  PumpOff,
  LEDOn,
  LEDOff,
  CO2On,
  CO2Off,
  CardInserted,
  CardRemoved,
} logRowType;

This includes all state changes (as seen in the enum above).  The code I worked on for logging sensor data made it easy to capture the function of logging an event happened:

/*
    writeEventHappened(...) log each of the events like turning the pump, LED, CO2 on or off.
*/
void writeEventHappened(logRow_t event) {
  File logFile = openFile();
  if (!logFile) {
    DEBUG_PRINTLNF("Could not write sensor data. Log File could NOT be opened!");
  } else {
    String sensorString = String(30);
    sensorString = String(event) + ",";
    sensorString += getDateTimeString() + ",";
    logFile.println(sensorString);
    logFile.flush();
    logFile.close();
  }
}

Testing on additional logging functionality works. Now on to adjusting the CO2…

Adjusting the CO2

Time to jump on this and just do it.  This is the last on my list of firmware needed to be written for the Grow Chamber.  Back in the February 1st build log, I discussed exploring parameters to use when adjusting the CO2.  I ended up deciding: I’ll start with something simple like (assumes LED light is on – or no point in adding CO2!)  if CO2 < 800ppm, turn CO2 valve on for 5 seconds.  If > 800ppm but < 1,200ppm, turn CO2 valve on for 2 seconds.

The first thing is to include a boolean flag in the sketch that lets the code know if the LED light is on or off:

void turnLightOn() {
  writeEventHappened(LEDOn);
  fLEDon = true;
  digitalWrite(LEDPin, ON);
}
void turnLightOff() {
  writeEventHappened(LEDOff);
  fLEDoff = false;
  digitalWrite(LEDPin, OFF);
}

Second, the wiki page for the Grove CO2 Sensor notes there is a 3 minute warm up time before taking readings.  I added a warm up flag and a one time alarm:

  fInWarmUp = true;
  Alarm.timerOnce((const unsigned long)secsWarmUp, warmUpOver);

Connecting With the Grow Chamber

Time to connect the Arduino/sensors and Relay goo with the Grow Chamber, water pump, LEDs, and CO2.  The shelves needed some holes for power cords.  I got some step drill bits and had a terrific time drilling holes.

NewImage

I wish I had known how much fun drilling holes were when I was much younger.  At least now I can have these special moments :-).  

I hooked up the cords to the Relay Switch:

NewImage

 

and hooked up the DC side of the relay wires to the corresponding pins on the Arduino.

#define pumpPin 4 //put the pin for the relay that will control the pump into pin 4 of the Arduino.  Make sure the pump is plugged into the right socket.
#define LEDPin  5 //same thing as for the pumpPin...
#define CO2Pin  6 //same things as for the other pins...

The color of the wires from the relay map to the dots on the Relay socket. 

Testing

I boldly start testing.  Surprise, surprise – some stuff worked and some stuff didn’t.

What worked:

  • turning pump on/off at the periodicity I wanted and for the length I wanted.
  • sensor measurements.
  • logging
What didn’t work:
  • LED, CO2 not turning on/off.
  • serial output stops after a few times the pump has been activated.
More stuff to work on another day.
Advertisements