Fail safe for power failure?

Hi everyone! I am still very new to the arduino world but I am learning more everyday. I have a few projects in mind to start on and one in particular has me contemplating on what is probably a simple question. Is there a way to write a fail safe for power failure into your program? For instance if you were using a servo to open and close something and your battery powering your arduino died, could you have the program set to automatically reset the servo to close something even if the program had just said to open it?

You've posed a long standing and very difficult question that can't be given a general answer. In general is possible for a computer to store its present state in case something fails (especially if it is given a timely warning that the power might fail), and to try to recover that state and/or take corrective action after the problem is fixed, but it is extremely difficult to anticipate all the possible failures or the proper corrective actions.

To compound the problem you often don't have a way of knowing which or when other parts of the system might fail. Servos can't (or shouldn't) be powered by the Arduino, so how do you know the servo power supply is good, the servo itself did not fail to perform its task, etc. ?

If the battery powering the Arduino dies, the program stops running. It's a little difficult to do anything at that point.

However, the Arduino could monitor the battery voltage, and if it falls to a certain level, the program could perform the fail-safe actions and then stop. Some experimentation would be in order to determine what the fail-safe voltage should be. There needs to be enough battery capacity left to reliably perform the fail-safe actions. So it's a compromise between maximizing battery life and having enough left to do the fail-safe.

You haven't described the circumstances in which the battery might become discharged - presumably it's a condition you expect and usually deal with effectively. If not, I don't think you should be looking for a programming solution.

Doubling the battery capacity without changing your battery management scheme might solve the problem.

...R

Most fail-safe solutions are based on hardware and not software. For Example, if you need to switch something, and normally you want it to stay off even if your arduino stops working, you use the Normally Open part of a Relay, rather than Normally Closed. I believe most servos will allow you to move them while off, but not on, with no damage, but you may want to make sure this is the case. Maybe you'll need to include a manual release lever for safety.

Since you are dealing with unknown conditions, its hard to program to account for them, thus why its often not done in software, (Not saying that it can't be, it depends on the situation, and you need to be able to sense the problem). It is just another part of the engineering design where you should consider and decide how you want it to behave before proceeding too far and always take time to choose products that will work within your design margin rather than choosing the cheapest one.

This is along the lines of what I was thinking but didnt know how far fetched the idea was. I didnt know if the idea was even a plausible one.

Robin2:
You haven't described the circumstances in which the battery might become discharged - presumably it's a condition you expect and usually deal with effectively. If not, I don't think you should be looking for a programming solution.

Doubling the battery capacity without changing your battery management scheme might solve the problem.

...R

I do plan to account for this type of problem in any way possible and using voltage regulators and larger battery capacities will certainly help but power failure for any reason is what im hoping to find a way to stave off. Say the power supply comes unplugged or the chord shorts out... I am just looking into ways to battle power failure for whatever reason. I am still very new and only know the basics. I just started using capacitors and was wondering if they can be used as a sort of generator to store enough power to help in the event of a power failure. I didnt know if one could act as a sort of generator in this way? Sorry if thats a stupid thought lol.

mirith:
Most fail-safe solutions are based on hardware and not software. For Example, if you need to switch something, and normally you want it to stay off even if your arduino stops working, you use the Normally Open part of a Relay, rather than Normally Closed. I believe most servos will allow you to move them while off, but not on, with no damage, but you may want to make sure this is the case. Maybe you'll need to include a manual release lever for safety.

Since you are dealing with unknown conditions, its hard to program to account for them, thus why its often not done in software, (Not saying that it can't be, it depends on the situation, and you need to be able to sense the problem). It is just another part of the engineering design where you should consider and decide how you want it to behave before proceeding too far and always take time to choose products that will work within your design margin rather than choosing the cheapest one.

This is a big challenge that I face as the computer programming aspect comes very natural to me but the actual application of the engineering is very very hard for me to get. I am very new to all the possible hardware and am slowly learning but with more and more knowledge comes more and more project ideas and thus more and more questions lol.

jremington:
You've posed a long standing and very difficult question that can't be given a general answer. In general is possible for a computer to store its present state in case something fails (especially if it is given a timely warning that the power might fail), and to try to recover that state and/or take corrective action after the problem is fixed, but it is extremely difficult to anticipate all the possible failures or the proper corrective actions.

To compound the problem you often don't have a way of knowing which or when other parts of the system might fail. Servos can't (or shouldn't) be powered by the Arduino, so how do you know the servo power supply is good, the servo itself did not fail to perform its task, etc. ?

I was worried that the question was going to have a very simple answer so in a way it is a relief that this is a long standing problem engineers face as it says something about the way I am thinking. On the other hand it would be nice if it was as simple and writing another few lines of code lol.

KvotheComplex:
I do plan to account for this type of problem in any way possible and using voltage regulators and larger battery capacities will certainly help but power failure for any reason is what im hoping to find a way to stave off. Say the power supply comes unplugged or the chord shorts out... I am just looking into ways to battle power failure for whatever reason. I am still very new and only know the basics. I just started using capacitors and was wondering if they can be used as a sort of generator to store enough power to help in the event of a power failure. I didnt know if one could act as a sort of generator in this way? Sorry if thats a stupid thought lol.

I feel strongly that you need to carefully separate the various ways in which power might fail and treat each as a separate risk to be minimized.

Wires becoming unplugged or wires being damaged are very very different from a battery running flat.

You need to think along these lines ....
what would cause the plug to be disconnected

  • make a list, together with actions that would prevent the problem
    what would cause the cable to be damaged ...

what might cause the battery to be discharged before the expected time ...

etc., etc.,

These example risks should have very low probability even if you took no steps to reduce risk.

You also need to think about things that you might do that would have an even lower risk of failure than these very low probabilities. Remember that everything you add carries with it some risk of failure.

Based on what you have said I would have a rechargeable (NiCd?) battery permanently connected to the board and kept charged by the main battery. If a diode separates the main battery from the circuit (so the standby can't discharge into the main) that should cover disconnection of the main battery and cable damage. Also the Arduino should be easily able to detect the failure of the main battery supply and would have plenty of time to raise an alarm or do an orderly shut down with the standby battery.

Whether all this is any real advantage is another matter.

...R

KvotheComplex:
Hi everyone! I am still very new to the arduino world but I am learning more everyday. I have a few projects in mind to start on and one in particular has me contemplating on what is probably a simple question. Is there a way to write a fail safe for power failure into your program? For instance if you were using a servo to open and close something and your battery powering your arduino died, could you have the program set to automatically reset the servo to close something even if the program had just said to open it?

Yes it is possible. It takes both external hardware circuitry and software functions to pull it off. Key things required:

A means of continuously measuring the DC power supply output voltage (battery or AC power supply) so your program can take action when required.
A means of having enough 'temporary storage power' (say via large filter capacitors) to be able to move the servo to it's fail safe position even as the primary power is failing.

The rest is just software to coordinate the whole event. Using Interrupts most likely will be involved to insure you can detect an impending power outage in time to perform the default action. The key calculation to make prior to design is the worst case amount of current the servo requires to move from where it might be to it's fail safe condition, as that determines how much temporary storage power you will requires, and hence the size of the cap(s) that will be needed.

Lefty

retrolefty:
Yes it is possible. It takes both external hardware circuitry and software functions to pull it off. Key things required:

A means of continuously measuring the DC power supply output voltage (battery or AC power supply) so your program can take action when required.
A means of having enough 'temporary storage power' (say via large filter capacitors) to be able to move the servo to it's fail safe position even as the primary power is failing.

The rest is just software to coordinate the whole event. Using Interrupts most likely will be involved to insure you can detect an impending power outage in time to perform the default action. The key calculation to make prior to design is the worst case amount of current the servo requires to move from where it might be to it's fail safe condition, as that determines how much temporary storage power you will requires, and hence the size of the cap(s) that will be needed.

Lefty

This is exactly what I was thinking could be done however I am very fond of the idea suggested a few post back about wiring in and programming a rechargeable battery to charge itself off the main power supply and run if and when the main power supply has went out. I will also need to have some form of manual shut off in the case of other hardware failures.

You still haven't shared with us any of the risk analyses that was also in my post about a wired-in battery.

Remember switches can fail (fail open or fail closed) also.

I still think you are chasing a ghost.

...R