Hi!
I could use some assistance with the following project:
I'm trying to control two relays which activate a pump and some led lights. The pump is activated by moisture readings, and I have no problems getting this to work as I want it to.
However, controlling the other relay through an RTC (DS1302) has so far proven to be too difficult for me.
I've tried the TimeAlarms function (as you can see in the code below), but to no effect.
Can somebody please help me with what I am missing?
#include <DS1302.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Time.h>
#include <TimeAlarms.h>
DS1302 rtc(6, 7, 8);
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
int moistureSensor = 0;
const int pumpPin = 2;
const int lightPin = 4;
void setup() {
rtc.halt(false);
rtc.writeProtect(false);
Serial.begin(9600);
rtc.setDOW(FRIDAY); // Set Day-of-Week to FRIDAY
rtc.setTime(16, 19, 30); // Set the time to 12:00:00 (24hr format)
rtc.setDate(6, 8, 10); // Set the date to August 6th, 2010
pinMode(pumpPin, OUTPUT);
pinMode(lightPin, OUTPUT);
Alarm.alarmRepeat(16,25,0, LightOn);
Alarm.alarmRepeat(16,26,0, LightOff);
lcd.begin(16, 2);
lcd.print(" Test ");
lcd.setCursor(0,1);
lcd.print("moisture sensor ");
delay(2000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("High value = dry");
lcd.setCursor(0,1);
lcd.print("Low value = wet");
delay(1000);
lcd.clear();
lcd.print(" optimum value");
lcd.setCursor(0,1);
lcd.print(" > 350----650 <");
delay(1000);
lcd.clear();
}
void loop() {
int sensorValue = analogRead(moistureSensor);
lcd.setCursor(0,0);
lcd.print(" Moisture value ");
lcd.setCursor(0,1);
lcd.print("");
lcd.print(sensorValue);
delay(2000);
lcd.setCursor(0,1);
lcd.clear();
lcd.setCursor(0,1);
lcd.print(sensorValue);
lcd.clear();
if (sensorValue >= 600)
{
digitalWrite(pumpPin, HIGH);
}
delay(3000);
{
digitalWrite(pumpPin, LOW);
}
delay(10000);
}
void LightOn()
{
digitalWrite(lightPin, HIGH);
}
void LightOff()
{
digitalWrite(lightPin, LOW);
}