Sequential watering

Hello,
I so sorry if this question isn't on right place. That is my first project, and I am not understand more about coding and ... but I make automatic watering system for my garden. But I want to make the system to start after day (today is 21 watering and the next watering to be on 23). I don't know how to write that into the code.
Thanks in advance.

Your post was MOVED to its current location as it is more suitable.

Could you also take a few moments to Learn How To Use The Forum.

Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum in the future.

Hello
Take some time and study this nice tutorial.

Your description is not clear for me; can you elaborate or rephrase?

Which Arduino are you planning to use? Do you already have other components that are needed? If so, which ones?

Hello, thanks for your answer. My setup is Arduino Nano, DS3231, relay and pump. That is my code that I use. I think to write in code (int StartDay = (and here to write the days that I want to start the pump) 1,3,5,7,9 and .... to 31). And If t.date == StartDay pump HIGH, else LOW. But when I started to list StartDays give an error.

#include <DS3231.h> //RinkyDink
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 2

OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

DS3231 rtc(SDA, SCL);
Time t;

int MorningHoursStart;
int MorningMinutesStart;
int EveningHoursStart;
int EveningMinutesStart;

int MorningHoursStop;
int MorningMinutesStop;
int EveningHoursStop;
int EveningMinutesStop;



int tempSensor = 2; //D2
int pumpRelay = 4;  //D4

float Celcius=0;
float Fahrenheit=0;

void setup() 
{
  pinMode (pumpRelay, OUTPUT);
  pinMode (tempSensor, INPUT);

  digitalWrite (pumpRelay, HIGH);
  Serial.begin(9600);
  rtc.begin();

 // Start Watering System
  MorningHoursStart = 00;
  MorningMinutesStart = 51;
  EveningHoursStart = 00;
  EveningMinutesStart = 00;
  
  // Stop Watering System
  MorningHoursStop = 01;
  MorningMinutesStop = 21;
  EveningHoursStop = 00;
  EveningMinutesStop = 00;


  sensors.begin();

  //rtc.setDate (21, 07, 2023);

  
}

void loop() 
{
  t = rtc.getTime();
  if (t.hour == MorningHoursStart && t.min == MorningMinutesStart && t.sec
   || t.hour == EveningHoursStart && t.min == EveningMinutesStart && t.sec ) {
    digitalWrite (pumpRelay, LOW);
  }
  if (t.hour == MorningHoursStop && t.min == MorningMinutesStop && t.sec
   || t.hour == EveningHoursStop && t.min == EveningMinutesStop && t.sec) {
    digitalWrite (pumpRelay, HIGH);
    }
    
  
  // Send date and time over serial connection
  Serial.print(t.date, DEC);
  Serial.print(" ");
  Serial.print(rtc.getMonthStr());
  Serial.print(" ");
  Serial.print(t.year, DEC);
  Serial.println(" ");  
  
  Serial.print(t.hour, DEC);
  Serial.print(":");
  Serial.print(t.min, DEC);
  Serial.print(":");
  Serial.print(t.sec, DEC);
  Serial.println(" ");

  delay (1000);
  
  //Temp
  sensors.requestTemperatures();
  Serial.print("Temperature: "); 
  Celcius=sensors.getTempCByIndex(0);
  Serial.print(Celcius);
  Serial.print(" °C  ");
  Fahrenheit=sensors.toFahrenheit(Celcius);
  Serial.print(Fahrenheit);
  Serial.println(" °F  ");
}

Hello
Take some time and make an internet research for " Setting up an alarm with the DS3231".

paulpaulson
Hello
when write the code for alarm how to describped days of month that I want start pump. Because when I try something like that give me an error:
int StartPump Days = 1,3,5,7,9.... to 31. I want to do that and after I will add it to my "if" when today is 7 start pump, if today is 8 not start the pump.

Hello
Did you read the datasheet, didnt´t you?

It sounds like you just want to check if the day is an odd number. Is it ok that in a 31 day month you will run on consecutive days (31st and 1st)?

Yes I want on odd number the pump start. But I don't know how to described these days into the code and I need help about that.

Hi
datasheet about?

No need to enumerate the days. Just get the day of month number from the clock and check if it's odd.

Can you help me to write the code?

Something like that?

int StartPumpDay = t.date % 2 == 1;
int NotStartPumpDay = t.date % 2 == 0;

void setup() 
{
  pinMode (pumpRelay, OUTPUT);
  pinMode (tempSensor, INPUT);

  digitalWrite (pumpRelay, HIGH);
  Serial.begin(9600);
  rtc.begin();

 // Start Watering System
  MorningHoursStart = 16;
  MorningMinutesStart = 58;
  EveningHoursStart = 00;
  EveningMinutesStart = 00;
  
  // Stop Watering System
  MorningHoursStop = 16;
  MorningMinutesStop = 59;
  EveningHoursStop = 00;
  EveningMinutesStop = 00;


  sensors.begin();

  //rtc.setDate (22, 07, 2023);

  
}

void loop() 
{
  t = rtc.getTime();
  if (t.hour == MorningHoursStart && t.min == MorningMinutesStart && t.sec && t.date == StartPumpDay
   || t.hour == EveningHoursStart && t.min == EveningMinutesStart && t.sec && t.date == StartPumpDay ) {
    digitalWrite (pumpRelay, LOW);
  }
  if (t.hour == MorningHoursStop && t.min == MorningMinutesStop && t.sec && t.date == StartPumpDay
   || t.hour == EveningHoursStop && t.min == EveningMinutesStop && t.sec && t.date == StartPumpDay) {
    digitalWrite (pumpRelay, HIGH);
    }
  if (t.hour == MorningHoursStop && t.min == MorningMinutesStop && t.sec && t.date == NotStartPumpDay
   || t.hour == EveningHoursStop && t.min == EveningMinutesStop && t.sec && t.date == NotStartPumpDay) {
    digitalWrite (pumpRelay, HIGH);
    }

Not quite. You need to check for oddness after you read the day from the clock.

Please edit your posts that have code, select all code and click </>; next sage your post.

It makes it easier to read, will not be mangled by the forum software and is

Maybe somewhere in loop(); it will only be executed once if placed befor setup() and will probably not work anyway.

easier to copy.

int StartPumpDay;
int NotStartPumpDay;

void setup() 
{
  pinMode (pumpRelay, OUTPUT);
  pinMode (tempSensor, INPUT);

  digitalWrite (pumpRelay, HIGH);
  Serial.begin(9600);
  rtc.begin();

 // Start Watering System
  MorningHoursStart = 16;
  MorningMinutesStart = 58;
  EveningHoursStart = 00;
  EveningMinutesStart = 00;
  
  // Stop Watering System
  MorningHoursStop = 16;
  MorningMinutesStop = 59;
  EveningHoursStop = 00;
  EveningMinutesStop = 00;

  StartPumpDay = t.date % 2 == 1;
  NotStartPumpDay = t.date % 2 == 0
void loop() 
{
  t = rtc.getTime();
  if (t.date == StartPumpDay) {
    digitalWrite (pumpRelay, LOW);
    }

Like that or what is the syntax to check today date and understand that it's even or odd?

No, you need to getTime before you do the StartPumpDay calculation. And you need to do it in loop if you intend to have this code running for multiple days.

{
  t = rtc.getTime();
  if (t.date == StartPumpDay) {
    digitalWrite (pumpRelay, LOW);
    }

Yes, I first have rtc.getTime() and after is if? I think it is correct if not please edit me.

But I think here have something wrong.

StartPumpDay = t.date % 2 == 1;
NotStartPumpDay = t.date % 2 == 0