hi i am trying to switch on a certain electrical device at certain time daily.
For that i have used timealarm library but the problem is whenever there is a power cutt the arduino resets which also resets the time. I have also tried to power it with an external 9v battery, its powering my arduino board but is not able to trigger the relay as battery drains out very soon.
is there any way to sort out this problem.
Use a latching relay that doesn't need to be powered continuously.
4 AA batteries will last much longer than a 9volt.
Learn how to put the arduino to sleep when it's not doing anything so the batteries last even longer.
Nick Gammon has written an excellent page on the subject.
Power saving techniques for microprocessors
All together it's possible for the batteries to last month's using these techniques.
Hi, welcome to this forum,
Sure,
An Arduino itself isn't very good in keeping time accurately and as you mention, will forget time if the power is cut. But you can add an RTC-chip/module, a GPS-module or fetch time from the internet (if it's connected).
After the power is turned on (again), arduino can read time using one of those sources.
In most cases a Real Time Clock module is used, which doesn't cost much.
Or use a low power Solid State Relay (SSR) instead of a Mechanical Relay.
50% of the power in 9 Volt battery is wasted in the on board Linear Regulator - Ouch!
A lower Voltage Battery pack is more efficient.
Two 18650 Lipo (6000mah) batteries will run Arduino 30 times longer than 9v battery.