I'm in the early stages of a home automation project - yet another automatic pet feeder project, to be specific. The automation part of the project involves using an Arduino to turn on/off some DC motors in sequence, based on some sensor inputs. That's not the issue, I don't have questions about that (yet!).
What I'm wondering about is using a commercial outlet timer (something like this) to control the timing of the process. The entire automation cycle would only be a minute or so of activity, which I want to happen twice a day. Rather than trying to come up with a long software timer or constantly polling a RTC module or something like that, I'd set the outlet timer to turn on at, say, 6:00 and turn back off at 6:05, then turn on at 18:00 and turn off at 18:05. The Arduino code would be written to do its tasks and then intentionally go into an infinite while() loop, until the power cycled and reset the code back to the beginning.
My big questions with this method are:
Will power cycling the Arduino like this damage the Arduino?
Are there any extra considerations I will need to think about in the code to allow for the system powering up at the start of each code cycle, like putting in a few seconds delay as the first executed command to allow the power to settle? I'm planning to run the project off a 120VAC/12VDC switching power supply - the power supply is what would be cycled by the outlet switch, which would in turn cycle power to the Arduino.
Are there other issues with this method that I, in my ignorance, haven't even thought of yet?
I would be interested in hearing from the experts on this.
I disconnect the Arduino Uno from the PC by unplugging the USB cable all the time which is a bit drastic and seems similar to using those electrical outlet timers to turn power on and off.
But maybe this is not good practice. Yikes.
Will power cycling the Arduino like this damage the Arduino?
No
The only thing which would worry me is the power cycling of, say, a cheap switchmode power supply, a decent supply should be fine.
Are there any extra considerations I will need to think about in the code to allow for the system powering up snip
Once the Arduino has 'booted up' and your code is running, the power supply should already be stable. However, See 3)
Are there other issues with this method that I, in my ignorance, haven't even thought of yet?
Possibly... you would have to give some consideration to what happens to the various driver transistors/MOSFETS during the period before the Arduino code runs and after it 'dies'.
Thanks for the reply, TonyWilk. Nice to know I won't damage the Arduino, at least, and I've learned my lesson in the past about cheap power supplies.
Could you elaborate a bit on what exactly I should be considering concerning the drivers when the code starts/stops? As it stands, I'm using a relay shield (this one) I happened to have lying around to switch the motors on and off.
0meganaught:
Could you elaborate a bit on what exactly I should be considering concerning the drivers when the code starts/stops? As it stands, I'm using a relay shield (this one) I happened to have lying around to switch the motors on and off.
That relay shield is fine, should have no trouble with that.
If you were making up a circuit yourself using transistors and/or MOSFETs driven from some output pin, then you have to consider what happens when the power comes on but the Arduino has not set that pin as an output yet, it is often as simple as putting a resistor in the right place to pull-up or pull-down before the Arduino output takes over. Similarly on power-off, you might have a 5V supply and a 12V supply - if the 5V supply falls faster than the 12V one, you can get a situation where things turn on for an instant. With that relay board, none of this applies in your case.
Yours,
TonyWilk
P.S. On the page you linked, do take note of: "Place 2 layers of electrical tape on the top of the [Arduino’s] usb connector. This will prevent the relay shield from making contact."
Thanks again, TonyWilk, that makes sense. Thanks for the heads-up on the contact warning, as well - I had seen that, but I would have been quite salty if I hadn't and the smoke got out.