Geyser controler

good afternoon everyone, i need some advise please i want to control my geyser to have it on for a specific amount of time every day, (quite a simple task) however in south Africa we have power outages several times a week and although the code works it does not store the last on state, is there any way to do this with out EEPROM as i fear it will use up all its writes rather quickly

#include <EEPROM.h>
#include <avr/wdt.h>
#include<Wire.h>
#include <DS3231.h>
const int OnHour = 16;
const int OnMin = 01;
const int OffHour = 20;
const int OffMin = 30;
int geyser = 7;

DS3231 rtc(SDA, SCL);
Time ti;
void setup() {
  Serial.begin(9600);
  wdt_enable(WDTO_8S);
  rtc.begin();
  pinMode (geyser, OUTPUT);
}

void loop () {

  Serial.print(rtc.getTimeStr());
  wdt_reset();
  static int currentMinute = -1;
  ti = rtc.getTime();
  if (ti.min != currentMinute)
  {
    currentMinute = ti.min;
    Serial.print(ti.hour);
    Serial.print(" hour(s), ");
    Serial.print(ti.min);
    Serial.println(" minute(s)");
  }
  if (ti.hour == OnHour && ti.min == OnMin)
  { digitalWrite(geyser, HIGH);
    Serial.println("GEYSER ON");
  }
  else if (ti.hour == OffHour && ti.min == OffMin) {
    digitalWrite(geyser, LOW);
    Serial.print("GEYSER OFF");
  }
  delay (1000);
}

To store the last on state you'll need a way to detect that power has been lost, then have enough power stored to save the last known state before the power really runs out. Could you show the circuit that you have to detect loss of power ? It may be that the circuit that you have to detect loss of power is not sending a signal to indicate a loss of power has occured.

That is a very good question, it did not cross my mind that i will need a separate circuit
to detect a power failure

I think that you can get away with using the EEPROM. If you write the date and time once only when you turn the geyser on, you will only be writing a few times a day I would expect so the chip will outlast the plumbing by many years.

Note though that currently, you're turning the system on repeatedly. That's not ok for the EEPROM.

if you are still concerned though, take a look at a FRAM.

Thank You Wildbill
my times i need is from 16h00 to 20h30, so on at 16h00 and off at 20h30 every day, how long do you think it would be ok like that

You should get a minimum of 100,000 writes to the EEPROM.

Another possibility is to upgrade your ds3231 RTC to a ds3232. This model has a small amount of ram memory which is backed up the coin cell, like the clock time is. Because it is ram memory rather than eeprom, you have unlimited writes.

1 Like

so if i write it twice a day i should get at least 136 years out of it my calculations are correct

You can play around with where the data goes in the EEPROM too. Use the first byte to tell you where to write the timestamp and change it periodically (monthly?)

With 136 years to play with though, it's not really worth adding the complexity.

Correct. The main danger is if you don't write your code correctly, it could perform a large number of writes in a short time. If it performed 100 writes per second, and you did not realise that was happening, the eeprom would last only a few minutes.

Probably longer, those numbers are usually the lower cap. Of the tests I've seen people get anywhere between 20% and 60% above the rated lifetime.

Check back with us in 140 years and keep us updated, though you may have to get a moderator to reopen this thread.

1 Like

I've never done it but couldn't the circuit be as simple as a 555 threshold trigger, a large capacitor, and a digital pin?

it possibly could be i will play and see, thanks guys

The words "arduino detect power failure" produces results and there are even examples of saving to whatever during power loss.

Actually, I'm not sure you care about detecting the power outage. At startup, you can check when the geyser was last heated and for how long, assuming you store on & off time & date in EEPROM.

Then you can decide whether there's a need to heat off-cycle to make up for heating that should have occurred but didn't.

Oh. I have been assuming "geyser" was just the term used in South Africa for "garden sprinkler", and that a pump or valve was being activated.

From reading threads from ZA and down under, I've concluded that a geyser there is a water heater. May be more subtlety or nuance to it though.

Hi Guys, sorry for the late reply, i will definitely play around with this, i have almost zero experience with eeprom but i am sure i will come right with it thanks for the advice

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