As stated in previous answers, at least on the AVR version of the
Arduino core, delay()
is a busy wait that keeps the CPU running. In
his answer, Duncan C correctly states that “CMOS logic circuits do use
more power when switching states than when idle”. It is then expected
that instructions that switch a large number of gates or flip-flops
consume more power than instructions that only switch a few ones.
Out of curiosity, I disassembled a call to delay()
to see what kind of
instructions it executes. I found that the “hot path” is a loop that
executes 44 instructions per iteration:
- 23 of them do arithmetic or logic (add, subtract, compare, XOR)
- 13 move data around (register load, register copy, I/O, read RAM)
- 7 alter the program flow (function call, return, jump, conditional
branches, conditional skip)
- 1 alters a bit in a status register
I do not know how this compares with “typical” code, but the large
proportion of instructions that do arithmetic and logic computations
suggests that delay()
should be way more energy hungry than, say, a
long sequence of nop
instructions. In the end, the only way to
know for sure whether delay()
changes anything to the power
consumption of a specific program would be to measure it.
As a side note, an easy way to save some power on AVR boards is to
#include <avr/sleep.h>
and insert a call to sleep_mode()
at the end
of loop()
. The sleep with not last for long though, as the Arduino
core sets Timer 0 to interrupt the CPU every 1024 µs.
yield()