Switching power on and off

I have successfully built an RFID reader/logger, and have it working as I want. Now that it must work for a living in a wildlife research application, it will have to sit out in the field for weeks awaiting a (rare) event before attempting to read an RFID tag in a fairly leisurely time-frame (several minutes if necessary). The device will then sit (preferably) unpowered until re-set by the operator (me). I have read a good deal about Arduino sleep modes, but it seems to me that simply switching the power off until the event happens would save a lot more power. For instance, I could use a NO reed switch to control a relay and power-up the Arduino. However, as an electronics noobie I have no idea how the voltage spikes and switch-bouncing at startup will affect (a) the Arduino, or (b) the way my code works.

As it happens, the power socket on my Uno makes a dicky contact, which I guess simulates what might happen. I have found that my code sometimes creates a number of empty files on the SD card, whereas it should create only one (at the start) which is finally closed off when the reader is presented with a master tag. It does writes data correctly to the last file created. I guess the mad file-creating behaviour may be caused by intermittent power supply as I connect the battery, in which case I can maybe correct it by building in a software delay at start-up - but is there any other software pitfall I should be on guard about?

And what about effects on the hardware? Since this device is for standalone use, I am contemplating building more units based on a minimal 'Arduino' (almost just the Atmega chip). Is there any extra component I really should include to avoid the possibility of damage at power-up and power-down?

Apologies if this scenario has already been discussed elsewhere on this forum - I don't know the lingo well enough to know what to search for!

As long as the voltage you're providing to the Arduino is within the supply voltage specifications, it doesn't matter if it turns on and off rapidly. The great thing about digital electronics like the Arduino is they are not mechanical, so they don't wear out in the same way an engine or a blender would.

Simply putting a short (~100ms) delay at the start of your program will probably be enough to prevent any spurious writes to your SD card.

Additionally, if you put a large (~470uF) capacitor from GND to V+, it will help to smooth out the voltage supplied to the Arduino. It will filter out any short spikes and make your Arduino a happy camper. Just make sure you follow the polarity of the cap when you install it.

As it happens, the power socket on my Uno makes a dicky contact, which I guess simulates what might happen.

Not really. When it is asleep it is already powered up. To solve the dicky contact problem, I suggest a short delay in setup, eg.

void setup ()
  delay (5000);  // wait 5 seconds
  // rest of setup

If it gets past that delay without being repowered, then any files you open should be OK.

But in your case what you really want is a sleep mode, like a deep sleep, and have the reed switch close pin 2 (ground it) thus waking it. Lots of detail here:

... it seems to me that simply switching the power off until the event happens would save a lot more power

Not at all. Using deep sleep as described in my page, and with various things turned off (like the ADC converter) you can get it to consume nano-amps of current. That's a lot less then the self-discharge rate of your batteries.

You certainly should use a "bare bones" board, not a development board like the Uno. The voltage regulator, power LED, USB chip etc. all consume heaps of current.

According to my (rough) figures, the self-discharge rate of AA alkaline batteries (not rechargeable) is around 80 uA (in effect). But the processor in sleep mode can be made to consume 0.35 uA. So the batteries are the worry, not the processor.

I suggest you power the RFID reader from a MOSFET (circuit on my page). Let the processor sleep. When the animal or whatever-it-is triggers the switch, the processor wakes up (in around 65 mS). It then powers up the RFID reader. Wait a second or so, and then take your reading. Log it. Power off the RFID reader. Go back to sleep in case it returns.

In fact, why bother with SD cards? The chip has EEPROM. Storing one RFID tag in that is well within its capabilities. Then later on you can load up a different sketch that reads in the EEPROM and prints out the number(s) you got. I would make the first couple of bytes of the EEPROM store a number telling you how many tags you have recorded. Read that in, and then write a new tag at the first free space. Then update the count bytes.

As for batteries, 3 x 1.5V batteries would give about the right voltage. Then you don't need voltage regulators.

Gents, thanks so much for those really helpful answers.

I did originally consider storing data on EEPROM because it is clearly cheaper, and I haven’t entirely ruled it out now - but it seemed easier to collect the data in the field (all weathers) using SD cards. I was also slightly put off by the limited number of times one can overwrite the EEPROM, apparently. If battery life proves to be a real problem, I will go back to that idea. I suppose I can use an Arduino with SD shield to download data in the field!

The beauty of all this is that I’m not reliant on an off-the-shelf product and can evolve the gadget according to need.

Thanks again.

You can do 100,000 writes to EEPROM.

... it will have to sit out in the field for weeks ...

One write per week is hardly going to wear it out in a big hurry.

One write per week is hardly going to wear it out in a big hurry.

Sure, I understand that. First things first, though. While I'm developing all the subteties of the gadget I reckon I could well make that number of writes in the form of test runs or errors. I need to get everything working exactly right before building 50 or more units.

How does one tell when the EEPROM is worn out?

One way to check is to write a memory check routine. Write all 0's to the memory, read it out, write all 1's to the memory, read it out, write 0b10101010 to the memory, read it out, etc. You could test half of the EEPROM at a time and move your data to the unused half. This method has a couple problems: 1) It writes to the EEPROM and therefore shorten's it's lifespan. and 2) If you do find an error in the EEPROM, you still have the problem of figuring out if that error corrupted your data or not. Of course there are many other ways to check your memory.

Someone checked out how many writes they could get out of an ATmega328's EEPROM. They got all the way to 1,230,163 cycles: Destroying An Arduino’s EEPROM | Hackaday It took them 47 days of 24/7 read/write cycles. You probably won't get anywhere near that over the course of your development.

If memory serves, the E2PROM un the '328 is good for about 100K writes and assuming 10K writes in development of the project it still leaves around 90K writes and if yon divide that figure by two that is 45K writes, at 100 tags/day that leaves about a year and a half of useful life in the internal E2prom, an external 16K E2Prom is a few pennies and easily incorporated into the device and replaceable easily whether by a socketed device or an assembly with a connector. The SDcard is just a BIG E2Prom with a difficult to use connector and a lot more work to use as it must be written to with a very special protocol. I personally would use an E2Prom and greatly simplify the project. Now that it has been simplified it is time to add a radio and an external device to read and store the data for later analysis so the ‘logger’ doesn’t have to be touched… Easy? But IMO a better way to go.


How does one tell when the EEPROM is worn out?

Write to it. Read it back. See if you got the same thing back.

But really, you won't wear out 100,000 writes in a hurry. Especially if you are cagy and only write something if it was different from before (eg. read in, if different to what you want to write, write out the new stuff).

If you really are writing a million times (in error) then you will destroy an SD card just as easily. And an SD card will be more expensive (or as expensive) to replace as the $5 processor chip.

Considering the availability of SD cards... I'd Still choose an external Eeprom (about 1/10th the price) I've seen 24C128's for $0.50 US and not nearly so hard to use.



My apologies, I missed your post until I returned to the subject some months later. That's very good advice - thanks!