Arduino uno executing program during power failure

Hellow,
Can i make atimer with arduino UNO for aschool
Which achieves the following:

  • when power switches off it keeps executing the program, installed in arduino ,in real time.
  • when power turns on back, the timer completes the time period in real time.
    Please can you send me the code?

Your post makes very little sense to me. You should explain to un in detail the functionality you need and maybe draw a diagram if possible.
Else how will we be able to advise / help you ?

If power switches off then where will the arduino itself draw power from ?

Not sure what you mean...

No one is going to do your homework for you. If you make an effort and ask intelligent questions when you get stuck then you will get lots of help. If you just ask folk here to do it for you then you won't get anywhere.

Please read How to get the best out of this forum then come back when you have something to ask about.

1 Like

Excuse me: I want to make a timer for the school so that it gives an audible alert every forty minutes (the duration of each lecture is forty minutes) with a twenty minute break after the end of the fourth lecture. Of course, the number of daily lectures is nine lectures. The problem that I face in the event of a power outage for a period of five minutes, for example, and its return again: How do I keep the timer working during the power outage so that it continues to work at the same real time?

Thats a little better :slight_smile:

So do you need the arduino to keep counting during power failures or do you need it to pause counting during that time ?

Ok, first things first…

Sketch up a block diagram of how things are being tied together… showing the primary and backup power sources inc charger.

I expect you’ve also got a real-time clock (RTC), keeping time-of-day, so that should be considered.

Also include your primary failure detection plan, and any peripherals you’re going to be connecting. Displays, buzzers etc.

Where possible provide links to the parts you’re choosing, so we can verify they’ll work together.

After the hardware us defined, you’ll need to put a bit more thought into the schematic/wiring and detailed theory of operation, and user interface. Weekdays only? LCD? keyboard? PC interface? Time setting, or NTP locked ?

Once all that’s in the bag, we can discuss the software requirements, and structure.

Happy planning!

Hi;
I think @jafar2021 wants to keep the timing system running during the power outage.

@jafar2021 what you need is a backup power supply for your controller so it runs while there is no mains power.

Google

arduino battery backup

Tom.. :grinning: :+1: :coffee: :australia:

I need the arduino to keep counting during power failures

Well, quite obviously it will not. :face_with_raised_eyebrow:

As has been pointed out, if you wish to provide a complete backup power system with a battery and a charger, that may be one approach.

If we allow that it will only actually give alerts when it is powered, this is much easier. You need a Real Time Clock - "RTC" which contains a lithium battery like any electronic clock, to provide just enough power to keep time with its crystal.

But you also need a memory to "know" what it was doing when the power went off and what it must do next. A cheap DS1307 RTC module is criticised for some limitation in timekeeping accuracy but should be perfectly satisfactory for your project and contains a small amount of RAM which is backed up by the battery, so your program could save in that RAM; the next alarm period and a code for what should be done at that time (or more than one alarm time).

1 Like

NO you don't, you need to check the time on a Real Time Clock (RTC).

I have built EXACTLY this type of system for two of our local schools, using an array of times for classes, breaks and end of day held in EEPROM. The RTC returns the Day of the week, so the bell would not sound on these days it is not needed. There was also an EEPROM table for Holidays, that can be updated with a simple BATCH file from my laptop. A switch and button were added to the controller for the staff to manually turn the bell output on or off as well as sounding the bell manually.

Output uses an optically isolated relay across the bell power feed, and as the RTC keeps time, there is no need for a battery backup for the board, just for the RTC. If the system missed the 'activate bell' time, it was ignored as each time activation is independant. While this was built on a custom PCB, it was fully prototyped using an Arduino, Relay, a switch & button.

Break each part of the project down, write a 'logic flow' diagram', wire it up, get it working, then move onto the next. When you have each part working, combine them part by part, test, then move on.

1 Like

The Real Time Clock approach is the simplest way when it comes to cost and circuit complexity.
Nevertheless you could use an of the shelf PowerBank like the one used for cellphones , to power the arduino (like a UPS) and just use a code that counts time without a RTC.

Without an RTC, you COULD be drifting minutes over a few weeks.

What is the type of RTC you have used??
Which is better DS1307 or DS3231??
Is the DS1307 sufficient??

I used a DS3234 RTC, along with a 32.768kHz crystal and 2 12.5pF capacitors, and a CR2032 Battery for the backup.

What the difference between DS3231 and DS3234 ??

You have the internet, download the datasheets & start reading!

Please can you send me the circuit diagram snd the code you have used?

Nope! It belongs to the client.

It depends on whether you need to maintain the time over more than a day. If you are going to start it up each day, that should be fine. If you require this to be your main clock, probably not as its long term accuracy is questionable!

Your initial description suggested that there might be a need to keep track of whether an event was missed during the power outage, in which case you need a record of what events have actually been actioned, so the DS1307 contains battery-backed RAM which makes this recording of actioned events easy and durable (it does not wear out as EEPROM does if you update it millions of times). The DS3231 lacks this RAM.