ds3231 RTC and arduino nano

Hi everyone.
I am using arduino nano, ds3231 module, one relay and one push button.
I intend to:

  1. Turn relay as output 'high' on 06 hour and 18 hour for 20 mins,
  2. When the push button as input is 'high' (when button is pushed on anytime of day, excluding already 'high' 06 and 18 hour ), turn relay output 'high ' for 15 minutes (15 minutes countdown from 'button push time', and turn relay output 'low' when 15 minutes countdown finishes.
    Here I am:
  3. not being able to select a library to fulfill both the purposes
  4. not at all being able to make a code for countdown after button push and turn relay off once countdown/timer stops.
    I don't want to use 'delay' or 'millis' as arduino will be 'on' everytime and will be sensing 3 other sensors continuously as in put.
    I searched the net for days to find a way to use any(?) Time function of so many libraries, of which I didn't understand what code mean in those '.h' fik3s. (I can only read simple/basic code) to manipulate any function to fulfill my purpose.
    Any hint, direction, reading material, code to start my project is welcome and highly appreciated.

Please, post your codes with code tags (</>).

Hint: You can use the Millis() function, you can get the delays you need but since it is non blocking you can change things on the fly. Another option is to use a RTC (Real Time Clock) and utilize the alarm function. I would suggest you find pieces of code that will do part of what you want and play with it so as to understand how it operates. After a few pieces of code this will become very doable. There is also some great examples included with the Arduino IDE, just go to files and examples.

I don't understand why this is not working.
<
[
const byte relayB = 7; // output pin no for relayB
const byte pushButton = 9; // input pin for pushbutton
const byte led = 13; // outputpin for LED
byte relayBState; // to store state of relayB

unsigned long currentMillis;
unsigned long previousMillis = 0;
unsigned long debounceOnTime = 200; // debounce time for push button
const unsigned long offTime = 10000; // time to stop relay after button is pushed

void setup()
{
pinMode (relayB,OUTPUT);
pinMode (pushButton, INPUT_PULLUP);
pinMode (led, OUTPUT);
digitalWrite (relayB, HIGH);
digitalWrite (led, LOW);

Serial.begin(9600);
}

void loop()
{
currentMillis = millis();
relayBState = digitalRead(relayB);
if ((digitalRead(pushButton) == LOW) && (relayBState == HIGH))
{
//Serial.println ("BUTTON is PUSHED");
if ((relayBState == HIGH) && (currentMillis - previousMillis == debounceOnTime))
{
digitalWrite(led, HIGH);
digitalWrite(relayB, LOW);
previousMillis = currentMillis;

    Serial.println("LED IS ON NOW");
    Serial.println ("RELAY IS TURNED ON");
    Serial.println("motor is running.....");
   }
}
  else  if ((relayBState == LOW) && (currentMillis - previousMillis == offTime))
          {
            digitalWrite(led, LOW)  ;
            digitalWrite(relayB, HIGH);
            previousMillis = currentMillis;

            Serial.println("LED isOff now!");
            Serial.println ("RELAY is turned OFF!");
            Serial.println("motor is NOT RUNNINGG.");
          }

}
]

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.