Hi Guys,
I live between a remote property and my house in the city(near the beach). It is summer here at the moment and i cannot leave my remote property to go to the beach as my gardens will die of dehydration.
I have 4 zones i would like to water. I have got half working code minus a few features i would like to implement.
I would like to somehow water 1 zone at a time with intervals ie 10mins and cycle through these zones at a set time once per day.
I have implemented the onebutton library and i am working on getting this to control manual operation.
I would also like to implement a DHT11 to take a reading at a set time and based on this reading do something at another certain time.
Example// If say the temp is above 30Deg Celcius at 2:00pm then run the watering intervals again at 6:00pm
I have a UNO with a RTC, DHT11 and Relayboard.
Here is my current code... It is most likely allot of excess as i have used code from others projects and tried to Taylor it for my needs.
If anyone could help me specifically with getting the 4 zones to cycle and with the temp sampling to create an event. That would be awesome. Thanks
#include <elapsedMillis.h>
#include "OneButton.h"
#include <Wire.h>
#include "RTClib.h"
#include <Time.h>
#include <TimeAlarms.h>
#include <idDHT11.h>
RTC_DS1307 RTC;
//Timers to replace Delay()
elapsedMillis timer0;
elapsedMillis timer1;
#define interval_1 3000
#define interval 1000
int idDHT11pin = 2; //Digital pin for comunications
int idDHT11intNumber = 0; //interrupt number (must be the one that use the previus defined pin (see table above)
void dht11_wrapper();
// Lib instantiate
idDHT11 DHT11(idDHT11pin,idDHT11intNumber,dht11_wrapper);
// RELAYS
int zone1 = 3;
int zone2 = 4;
int zone3 = 5;
int zone4 = 6;
//BUTTONS
OneButton button(7, true);
// the setup routine runs once when you press reset:
void setup() {
button.attachDoubleClick(doubleclick);
button.attachClick(click);
Serial.begin(9600);
Wire.begin();
RTC.begin();
if (! RTC.isrunning()) {
Serial.println("RTC is NOT running!");
// following line sets the RTC to the date & time this sketch was compiled
}
// initialize the digital pin as an output.
pinMode(zone1, OUTPUT);
pinMode(zone2, OUTPUT);
pinMode(zone3, OUTPUT);
pinMode(zone4, OUTPUT);
//Set relay pins high so they are off
digitalWrite(zone1, HIGH);
digitalWrite(zone2, HIGH);
digitalWrite(zone3, HIGH);
digitalWrite(zone4, HIGH);
Serial.println("Startup Completed");
//Alarm.alarmRepeat(23,00,0, zone1on); // 8:30am every day
//Alarm.alarmRepeat(06,00,0, zone1off); // 8:30am every day
//Alarm.alarmRepeat(21,55,30, zone2on); // 8:30am every day
}
void dht11_wrapper() {
DHT11.isrCallback();
}
// the loop routine runs over and over again forever:
void loop() {
displaytemp();
button.tick();
displaytime();
//Alarm.delay(1000); // wait one second between clock display
delay(10);
}
void displaytemp(){
if (timer1 > interval_1) {
timer1 -= interval_1;
Serial.print("\nRetrieving information from sensor: ");
Serial.print("Read sensor: ");
//delay(100);
int result = DHT11.acquireAndWait();
switch (result)
{
case IDDHTLIB_OK:
Serial.println("OK");
break;
case IDDHTLIB_ERROR_CHECKSUM:
Serial.println("Error\n\r\tChecksum error");
break;
case IDDHTLIB_ERROR_TIMEOUT:
Serial.println("Error\n\r\tTime out error");
break;
case IDDHTLIB_ERROR_ACQUIRING:
Serial.println("Error\n\r\tAcquiring");
break;
case IDDHTLIB_ERROR_DELTA:
Serial.println("Error\n\r\tDelta time to small");
break;
case IDDHTLIB_ERROR_NOTSTARTED:
Serial.println("Error\n\r\tNot started");
break;
default:
Serial.println("Unknown error");
break;
}
Serial.print("Humidity (%): ");
Serial.println(DHT11.getHumidity());
Serial.print("Temperature (oC): ");
Serial.println(DHT11.getCelsius());
}
}
void allon () {
zone1on();
zone2on();
zone3on();
zone4on();
}
void alloff () {
zone4off();
zone3off();
zone2off();
zone1off();
}
void zone1on() {
digitalWrite(zone1, LOW); //
Serial.println("Zone 1 on");
}
void zone1off() {
digitalWrite(zone1, HIGH); //
Serial.println("Zone 1 off");
}
void zone2on() {
digitalWrite(zone2, LOW); //
Serial.println("zone 2 on");
}
void zone2off() {
digitalWrite(zone2, HIGH); //
Serial.println("Zone 2 off");
}
void zone3on() {
digitalWrite(zone2, LOW); //
Serial.println("Zone 3 on");
}
void zone3off() {
digitalWrite(zone2, HIGH); //
Serial.println("Zone 3 off");
}
void zone4on() {
digitalWrite(zone2, LOW); //
Serial.println("Zone 4 on");
}
void zone4off() {
digitalWrite(zone2, HIGH); //
Serial.println("Zone 4 off");
}
void doubleclick() {
allon();
Serial.println("Double Click");
}
void click() {
alloff();
Serial.println("Click");
}
void displaytime() {
if (timer0 > interval) {
timer0 -= interval;
DateTime now = RTC.now();
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();
}
}