/*
- TimeAlarmExample.pde
*/#include <Time.h>
#include <TimeAlarms.h>int hidPin = 13;
int pumpPin1 = 10;
int pumpPin2 = 11;void setup()
{
Serial.begin(9600);
Serial.println("Timer Test");
Serial.println();setTime(8,29,50,1,1,10); // set time to current time/date - disregard actual time, I know it's wrong.
Alarm.alarmRepeat(8,30,0, LightOn); // Set time to come ON
Alarm.alarmRepeat(8,35,0, LightOff); // Set time to shut OFF
Alarm.timerRepeat(90, PumpOn1); // Timer for every 90s
Alarm.timerRepeat(90, PumpOn2);pinMode(hidPin, OUTPUT);
pinMode(pumpPin1, OUTPUT);
pinMode(pumpPin2, OUTPUT);}
void LightOn()
{
digitalWrite(hidPin, HIGH);
Alarm.delay(0);
Serial.println("HID ON");
Alarm.delay(0);
}void LightOff()
{
digitalWrite(hidPin, LOW);
Alarm.delay(0);
Serial.println("HID OFF");
Alarm.delay(0);
}void PumpOn1(){
digitalWrite(pumpPin1, HIGH);
Serial.println("Pump 1 ON");
Alarm.delay(2000); // Pump stays on for 2 seconds
digitalWrite(pumpPin1, LOW);
Serial.println("Pump 1 OFF");}
void PumpOn2(){
digitalWrite(pumpPin2, HIGH);
Serial.println("Pump 2 ON");
Alarm.delay(2000);
digitalWrite(pumpPin2, LOW);
Serial.println("Pump 2 OFF");}
void loop(){
Alarm.delay(0);
}
Ok, so I've been screwing around with the above code for about an hour now. I got everything to work, and I'm making progress, but for some reason I cannot get pumpPin1 and pumpPin2 to stay HIGH at the same time. hidPin will stay HIGH with one of the pumpPins also HIGH, but pumpPin1 and pumpPin2 will not go HIGH together. I'm using LEDs to test this all out, but later on I will be using relays to trigger a light to stay on for 18hrs, and then using pumpPin1 and pumpPin2 to control water pumps via relays, etc.
This is for a greenhouse project (legal lol) and the pumps are used to water the plants... It's not really an issue that the pins aren't both activated at the same time, but I'd like to know what I need to do to make them come on at the same time. I think I need to use the millis() command or whatever that is... or is there a different way? I will also be putting more code in, so I can't have processes screwing with each other.
I will lay out what I need to control,
1 or possibly 2 lights on different timing schedules, 1 for 18hrs on/6 off the other could be for 20hrs on 4/off, etc
3 separate watering pumps which will need to come on once every minute or two for a few seconds each
Temperature control by using a DHT11 temp/humidity sensor, would like to set varying temps throughout the day, slowly warming when the lights turn on, like, 6am temp 72F (low temp), 9am temp 75F, etc
CO2 injection using a sensor from CO2meter.com, keeping the CO2 levels in a set range by using a solenoid valve on a CO2 tank, using either a photoresistor or timer method to allow solenoid to work during light hours but stay OFF during a lights off period.
I will be adding more features later, as I learn more, but right now I only need to code the above items.
Any help on my timer code/questions, how to improve it, etc, would be greatly appreciated, and then any questions I have about the other items I can address at a later time; baby steps ![]()
Thanks so much guys!