I'm working on an agriculture system and one of my partners (who was taking care of the automation side of things) has gone MIA and we are left with arduino code running our systems that we have a basic understanding of. We're in a bit of a pickle until we can get another person on board who has this kind of expertise and would greatly appreciate any help from anyone who can assist us in modifying a few parameters of the program.
The arduino is controlling one of the generic 8 relay boards hooked up to mains voltage and 8 outlets. The outlets control lights, cO2, water pumps, and fans (which are programmed to activate when temp/humidity reaches certain levels).
We presently understand how to alter how long the relays are activated for, but what we are trying to understand is how to modify the interval at which these relays are activated (cO2/water is every 150 minutes, we would like to alter this). So for example, how would I alter the code to release cO2 every 90 minutes and activate the water pump every 5 minutes?
Any help on this matter would be greatly appreciated! Thank you so much!
#include <dht.h>
#include <dht.h>
dht DHT;
#define dataPin 7
//#define DHT11_PIN 7
#define CH1 1 // Connect Digital Pin 8 on Arduino to CH1 on Relay Module
#define CH2 2 // Connect Digital Pin 7 on Arduino to CH3 on Relay Module
#define CH3 3 // Connect Digital Pin 8 on Arduino to CH1 on Relay Module
#define CH4 4 // Connect Digital Pin 7 on Arduino to CH3 on Relay Module
#define CH5 5 // Connect Digital Pin 8 on Arduino to CH1 on Relay Module
#define CH6 6 // Connect Digital Pin 7 on Arduino to CH3 on Relay Module
#define CH7 9 // Connect Digital Pin 8 on Arduino to CH1 on Relay Module
#define CH8 8 // Connect Digital Pin 7 on Arduino to CH3 on Relay Module
int seconds = 0;
int minutes = 1;
int hours = 0;
int days = 0;
int temp = 28; // not used
int tempset = 25; // turn on fan temp
int minmil = 1000; //clock 60000
int watertime = 8000; //water for 8 seconds =8000
int co2time = 8000; //water for 8 seconds =8000
void setup() {
//Setup all the Arduino Pins
pinMode(CH1, OUTPUT);//Lights
pinMode(CH2, OUTPUT);//Water
pinMode(CH3, OUTPUT);// CO2
pinMode(CH4, OUTPUT);//FAN
pinMode(CH5, OUTPUT);//FAN
pinMode(CH6, OUTPUT);//FAN
pinMode(CH7, OUTPUT);//FAN
pinMode(CH8, OUTPUT);
}
void loop() {
int readData = DHT.read11(dataPin); // Reads the data from the sensor
float t = DHT.temperature; // Gets the values of the temperature
float h = DHT.humidity; // Gets the values of the humidity
Serial.print(minutes,2);
Serial.print(" minutes ");
Serial.print(hours,2);
Serial.print(" hours ");
Serial.print(days,2);
Serial.print(" days ");
Serial.println();
//int chk = DHT.read11(DHT11_PIN);
seconds=seconds+1;
if (seconds >= 59) {
minutes = minutes + 1;//adds to count
seconds = 0;
}
if (minutes >= 59) {
hours = hours + 1;
minutes = 0;
}
if (hours >= 23) {
days = days + 1;
hours = 1;
}
if (days >= 31) {
days = 1;
}
if ((days <= 3) && (hours < 19)) {
digitalWrite(CH1, LOW);//Lights on for first 3 days 12 hours per Day
}
if ((days <= 3) && (hours >= 19)) {
digitalWrite(CH1, HIGH);//Lights on for first 3 days 12 hours per Day
}
if ((days > 3) && (hours < 16)) {
digitalWrite(CH1, LOW);//Lights on for first 3 days 12 hours per Day
}
if ((days > 3) && (hours >= 16)) {
digitalWrite(CH1, HIGH);//Lights on for first 3 days 12 hours per Day
}
if (tempset < t) { // TURN ON FANS IF ABOVE TEMP SET POINT
digitalWrite(CH4, LOW);//Lights on for first 3 days 12 hours per Day
digitalWrite(CH5, LOW);//Lights on for first 3 days 12 hours per Day
digitalWrite(CH6, LOW);//Lights on for first 3 days 12 hours per Day
digitalWrite(CH7, LOW);//Lights on for first 3 days 12 hours per Day
}
if (tempset >= t) { // TURN ON FANS IF ABOVE TEMP SET POINT
digitalWrite(CH4, HIGH);//Lights on for first 3 days 12 hours per Day
digitalWrite(CH5, HIGH);//Lights on for first 3 days 12 hours per Day
digitalWrite(CH6, HIGH);//Lights on for first 3 days 12 hours per Day
digitalWrite(CH7, HIGH);//Lights on for first 3 days 12 hours per Day
}
// if (( (hours % 2) == 0) && (minutes == 30)) { //Water every 2 hours @ 30 minute Mark
if (minutes == 3) { //Water every 2 hours @ 30 minute Mark
digitalWrite(CH2, LOW);//
delay(watertime); //how long water pump is engaged
minutes = minutes + 1;
}
else {
digitalWrite(CH2, HIGH);//
}
// if (( (hours % 2) == 0) && (minutes == 45)) { //CO2 Released every 2 hours @ 45 minute Mark
if (minutes == 5) { //CO2 Released every 2 hours @ 45 minute Mark
digitalWrite(CH3, LOW);//CO2
delay(co2time); //how long CO2 is released
minutes = minutes + 1;
}
else {
digitalWrite(CH3, HIGH);// no CO2
}
delay(minmil); // (60000) - 1 minute Delay
}
Question: how could we alter the code in order to release co2 every 90 minutes?