Problem using AikoEvents to control Relays within a sensor application

Hi everyone,

I have an issue I hope someone on this forum can help out with.
I also have no programming experience whatsoever, so go easy please. The code below I have cobbled together and adapted from various libraries and other projects I found on the internet, and it compiles.

What is it for:

This is an Arduino UNO, a datalogger shield (nuelectronics), a LCD and a SHT15 temperature and humidity sensor which I am using to log conditions within a reaction chamber. The code for this on its own works fine.
I would now like to control the humidity in said chamber using two solenoid valves connected via relays to the arduino.
The code (Aiko) for this I took from Jonathan Oxer's book "Practical Arduino: Cool Projects for Open Source Hardware" from the time-lapse camera example. Again, on its own, the code from the book obviously works fine and cycles the relays the way I want to.

However when I merge the code together, the relay on D19 (A5) switches and stays switched, whereas nothing happens with the relay on D18.

My Questions:

  1. Can someone help me find out why the relays do not cycle correctly in the merged code?
  2. How can I limit the cycles so that the chamber is filled with humid air (relay on e.g. D18) for one hour, then dry air (relay on e.g. D19) for an hour, the process is then repeated x times and finishes with one hour of dry air before closing the valve (rather than continuing ad infinitum)?

Combined Code:

// SHT15 Temperature & Humidity Logger

//----------------------------------------------------------------------------------------------------------------------------------
// Libraries 
//----------------------------------------------------------------------------------------------------------------------------------
 
#include <SdFat.h>                // SD card file system library GNU GPL V3 (Version 20100818) http://code.google.com/p/sdfatlib/
#include <DS1302.h>               // Real Time clock (RTC) lib (C) Henning Karlsen http://www.henningkarlsen.com/electronics/a_l_ds1302.php
#include <SHT1x.h>                // SHT Temp and Humidity Library
#include <LiquidCrystal.h>
#include <AikoEvents.h>
using namespace Aiko;
//----------------------------------------------------------------------------------------------------------------------------------
// Connections
//----------------------------------------------------------------------------------------------------------------------------------

//IMPORTANT: for SD card code to work with datalogging shield a jumper is needed between digital 10 and 5 

// Specify data and clock connections and instantiate SHT1x object - using pins 16 and 17 corresponds to the P2 4pin connector
#define dataPin  17
#define clockPin 16
SHT1x sht1x(dataPin, clockPin);

//create object to control an LCD.  
LiquidCrystal lcd(9, 8, 7, 10, 14, 2);  // this was 12,11,5,3,2 

// Aiko Settings
int HumidityInterval = 5;         // Delay between Humid Air (in seconds)
int DryInterval = 10;              // Delay between Dry Air (in seconds) must be different from Humidity interval
int dryAirPin = 19;                 // Reed relay on digital pin 19  
int humidAirPin = 18;               // Reed relay on digital pin 18

int greenLEDpin=2;        //LED file system / SD card syncing activity - not needed?

// RTC uses digital pin 3 (SCLK), pin 4 (I/O), pin 5 (CE)
// Init the DS1302 passing connection pin numbers 
DS1302 rtc(6, 4, 3);
//-----------------------------------------------------------------------------------------------------------------------------------



//define variables for SD card logging check these, sensiron SHT15 needs min 6.5 s between readings to avoid self-heating
int LOG_INTERVAL=7500; // mills between entries
int ECHO_TO_SERIAL=1; // echo data to serial port
int SYNC_INTERVAL=7500; // Sensor reading saved to SD card every x seconds
long syncTime = 0;     // time of last sync()

// The objects to talk to the SD card
Sd2Card card;
SdVolume volume;
SdFile root;
SdFile file;

//--------------------------------------------------------------------------
//Function Decleration 
//--------------------------------------------------------------------------


void sd_card(float,float);        //sd card logging code use void sd_card(float,float,float) if using temp_f


//--------------------------------------------------------------------------
//SETUP
//--------------------------------------------------------------------------

void setup()
{
  
  // start serial port
  Serial.begin(9600);
  Serial.println("Temperature & Humidity Sensor is Starting Up");
  
  //Welcome Message
  lcd.begin(16, 2);
  lcd.clear();
  lcd.setCursor(0, 0);          // set the cursor to column 0, line 0
  lcd.print("Sensor");
  lcd.setCursor(0, 1);          // set the cursor to column 0, line 1
  lcd.print("initialising...");      
  
  delay(2000);   // remove this delay?
  
  // initialize the SD card
  if (!card.init()) error("card.init");
  
  // initialize a FAT volume
  if (!volume.init(card)) error("volume.init");
  
  // open root directory
  if (!root.openRoot(volume)) error("openRoot");
  
  // create a new file
  char name[] = "LOGGER00.CSV";
  for (uint8_t i = 0; i < 100; i++) {
    name[6] = i/10 + '0';
    name[7] = i%10 + '0';
    if (file.open(root, name, O_CREAT | O_EXCL | O_WRITE)) break;
  }
  if (!file.isOpen()) error ("file.create");


  
  file.writeError = 0;

  // write header
  file.println("Milliseconds since start, Date, Time, Temperature (*C), Humidity");    
  if (ECHO_TO_SERIAL) Serial.println("Milliseconds since start, Date, Time, Temperature (*C), Humidity");
  
  pinMode(greenLEDpin, OUTPUT); //set SD card activity LED pin to output mode
  digitalWrite(greenLEDpin,HIGH);


  // attempt to write out the header to the file
  if (file.writeError || !file.sync()) {
    error("write header");
  }

  
  // Set the clock to run-mode, and disable the write protection
  rtc.halt(false);
  rtc.writeProtect(false);
  
  // Set RTC date and time (if needed!) 
  //rtc.setDOW(FRIDAY);        // Set Day-of-Week to FRIDAY
  //rtc.setTime(12, 0, 0);     // Set the time to 12:00:00 (24hr format)
  //rtc.setDate(6, 8, 2010);   // Set the date to August 6th, 2010
  
  // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);
    
  digitalWrite(greenLEDpin,LOW);


  pinMode(dryAirPin, OUTPUT);      // Set the dry air pin as an output
  digitalWrite(dryAirPin, LOW);
  pinMode(humidAirPin, OUTPUT);    // Set the humid air pin as an output
  digitalWrite(humidAirPin, LOW);
  //pinMode(ledPin, OUTPUT);        // Set the LED pin as an output
  //digitalWrite(ledPin, LOW);
 
  Events.addHandler(humidAir, HumidityInterval * 1000); // Every 'HumidityInterval' seconds
  Events.addHandler(dryAir, DryInterval * 1000); // Every 'HumidityInterval' seconds
  
  
} //end setup

//--------------------------------------------------------------------------
//Loop
//--------------------------------------------------------------------------

void loop(void)
{ 
  {
  Events.loop();
  }
  // clear print error
  file.writeError = 0;
  
  // delay for the amount of time we want between readings
  delay((LOG_INTERVAL -1) - (millis() % LOG_INTERVAL));
  
  //get individual sensor temperatures 
  float temp_c;
  // float temp_f;
  float humidity;
  
  // Read values from the sensor
  temp_c = sht1x.readTemperatureC();
  // temp_f = sht1x.readTemperatureF();
  humidity = sht1x.readHumidity();

  //log data to SD card
  
  if ((millis()-syncTime) > SYNC_INTERVAL){
    sd_card(temp_c,humidity);
    syncTime=millis();
 
 
  }
  
// (note: line 1 is the second row, since counting begins with 0):
 // Print a message to the LCD.
  lcd.clear();
  lcd.setCursor(0, 0);          // set the cursor to column 0, line 0
  lcd.print("Temperature");
  lcd.setCursor(0, 1);          // set the cursor to column 0, line 1
  lcd.print(temp_c);      //send the data to the computer
  lcd.print((char)223);         // degree symbol
  lcd.print("C");
   
  delay (3750);
 
  lcd.clear();
  lcd.setCursor(0, 0);          // set the cursor to column 0, line 0
  lcd.print("Humidity");
  lcd.setCursor(0, 1);          // set the cursor to column 0, line 1
  lcd.print(humidity);
  lcd.print("%");
        
  
  delay(3750);
}  //end loop


void humidAir()
{
  digitalWrite(dryAirPin, LOW);   // Turn off dry air relay
  digitalWrite(humidAirPin, HIGH); // Turn on humid air relay
 
}

void dryAir()
{
  digitalWrite(dryAirPin, HIGH);   // Turn on dry air relay
  digitalWrite(humidAirPin, LOW); // Turn off humid air relay
 
}


//SD card error function 
void error(char *str)
{
  boolean flag=false;
  Serial.print("error: "); Serial.println(str);
  while(1){
    digitalWrite(greenLEDpin, HIGH);
    delay(100);
    digitalWrite(greenLEDpin, LOW);
  }
    
    ;
}


void sd_card(float temp_c,float humidity)      //void sd_card(float temp_c,float temp_f,float humidity)
{
  
  //log milliseconds since starting
  long m = millis();
  file.print(m); file.print(",");              // milliseconds since start, I disabled this because it messes up the Columns when logged
  
  //save current date and time
  file.print(rtc.getDateStr()); file.print(","); 
  file.print(rtc.getTimeStr()); ;file.print(","); 
  
  file.print(temp_c);file.print(", "); 
  //file.print(temp_f);file.print(", "); 
  file.println(humidity);file.print(", "); 


  if (ECHO_TO_SERIAL){
    Serial.print(m); Serial.print(", ");         // milliseconds since start

    Serial.print(rtc.getDateStr()); Serial.print(", "); 
    Serial.print(rtc.getTimeStr()); Serial.print(", "); 
    Serial.print(temp_c);Serial.print(", "); 
    //Serial.print(temp_f);Serial.print(", "); 
    Serial.println(humidity);



  // blink LED to show we are syncing data to the card & updating FAT!
  digitalWrite(greenLEDpin, HIGH);
  if (!file.sync()) error("sync");
  digitalWrite(greenLEDpin, LOW);
  
  if (file.writeError) error("write data");

return;
}
}

Using BlinkWithoutDelay instead of Aiko solved the problem....