Engineering mission · M-003
The Energy-Constrained Computer
A tiny logger must run for 90 days on a small battery with 1 KB of free memory. Choose how it samples, sleeps and stores.
About 2 h · intermediate · 5 steps · Free
The situation
A conservation group wants to record temperature, humidity and light level inside a nesting box over a whole season. Opening the box disturbs the animals, so the device must run for at least 90 days without anyone touching it.
The device in this mission is hypothetical. It has a small microcontroller, three sensors, a short-range radio that sends data to a base station a few metres away, and a battery with 220 mAh of usable charge. It has 2 KB of RAM, but only 1,024 bytes are free for storing readings, because the rest is used by the program.
A first prototype design (the baseline) wakes once every second, reads all three sensors, and transmits once a minute. It works on the bench, but nobody has checked how long the battery will last.
Your job is to check the baseline, then redesign it to meet the 90-day requirement while still giving the scientists useful data. You will choose a sampling rate, a sleep strategy and a way to represent the data in memory. Several designs can meet the requirement, and each gives up something different. You must explain what your choice gives up and why that is acceptable for the scientists' question.
You will learn to
- Calculate average current and battery life from a duty cycle.
- Identify which part of a duty cycle dominates energy use.
- Choose a data representation that fits memory limits while keeping the required resolution.
- Justify a sampling rate from what the measurement is for, not from what is easy.
Constraints
- C1Usable battery charge: 220 mAh. The device must run at least 90 days.
- C2Baseline currents: 12 mA for 20 ms per sample (all three sensors), radio 25 mA for 100 ms per transmission, sleep 0.05 mA.
- C3Free RAM for readings: 1,024 bytes.
- C4Temperature must be recorded to 0.1 °C resolution over −20 to +50 °C.
- C5The scientists need at least one reading of each quantity every 5 minutes.
- C6You may change the sampling interval, the transmission interval and the data representation, but not the current figures.
Background
Charge, current and time
Battery capacity is given in milliamp-hours (mAh). A 220 mAh battery could, in principle, supply 1 mA for 220 hours or 0.1 mA for 2,200 hours. Real batteries deliver somewhat less in cold or at high currents, which is why this mission gives a usable figure.
A device that sleeps most of the time draws very different currents in different states. To find battery life, work out the charge used in one repeating cycle, divide by the cycle length to get the average current, then divide capacity by that average.
A worked example
This example is not the baseline. A device has a 10-second cycle. It wakes 10 times for 50 ms at 10 mA, transmits once for 200 ms at 30 mA, and sleeps for the rest of the time at 0.02 mA. Its battery has 500 mAh.
- Awake: 10 × 0.050 s = 0.5 s, plus 0.2 s of radio, so it sleeps 10 − 0.7 = 9.3 s.
- Charge: 0.5 × 10 + 0.2 × 30 + 9.3 × 0.02 = 5 + 6 + 0.186 = 11.186 mA·s per cycle.
- Average current: 11.186 / 10 = 1.1186 mA.
- Battery life: 500 / 1.1186 ≈ 447 hours, about 18.6 days.
You can check this, and later your own design, with Python:
# Worked example: one 10-second cycle
period_s = 10.0
samples = 10 # one reading per second
active_ma, active_s = 10.0, 0.050 # awake to read and process each sample
radio_ma, radio_s = 30.0, 0.200 # one transmission per cycle
sleep_ma = 0.02
awake_s = samples * active_s + radio_s
sleep_s = period_s - awake_s
charge_mas = samples * active_s * active_ma + radio_s * radio_ma + sleep_s * sleep_ma
avg_ma = charge_mas / period_s
battery_mah = 500.0
hours = battery_mah / avg_ma
print(f"sleep time per cycle: {sleep_s:.1f} s")
print(f"charge per cycle: {charge_mas:.3f} mA·s")
print(f"average current: {avg_ma:.4f} mA")
print(f"battery life: {hours:.1f} h = {hours / 24:.1f} days")sleep time per cycle: 9.3 s
charge per cycle: 11.186 mA·s
average current: 1.1186 mA
battery life: 447.0 h = 18.6 daysMemory and representation
A reading stored as a 32-bit float takes 4 bytes; as a 16-bit integer, 2 bytes; as an 8-bit integer, 1 byte. A 16-bit integer counting hundredths of a degree can hold −327.68 to +327.67 °C. An 8-bit integer has only 256 values, so covering −20 to +50 °C (70 degrees) gives steps of about 0.27 °C. Fewer bytes per reading means more readings fit in the buffer, which matters if the radio link fails for a while and data must wait.
How to approach it
- 01
Check the baseline
The baseline has a 60-second cycle: 60 samples (one per second) at 12 mA for 20 ms each, one transmission at 25 mA for 100 ms, and sleep at 0.05 mA for the rest. Calculate the charge per cycle, the average current and the battery life in hours. Edit the worked-example script to check your arithmetic. Does it meet 90 days?
- 02
Find what dominates
Split the baseline's charge per cycle into its three parts: sampling, radio and sleep. Which is largest? Which change would save the most: sampling less often, transmitting less often, or something else? Note that sleep current applies for almost the whole cycle, so even a tiny current can matter.
- 03
Check memory
How many bytes does one baseline cycle of readings (60 samples × 3 quantities) need as 16-bit integers? As 32-bit floats? How many cycles of data could wait in the 1,024-byte buffer if the radio link failed? Decide whether 8-bit storage could meet the 0.1 °C requirement.
- 04
Redesign
Choose a sampling interval, a transmission interval and a representation for each quantity. Calculate the new average current and battery life, and the buffer time if the radio fails. Aim for a margin above 90 days, because the battery may deliver less than its usable figure in cold weather.
- 05
Justify for the scientists
Explain what your design gives up compared with the baseline, such as time resolution or how fast data arrives, and argue why that is acceptable for recording conditions in a nesting box over a season. Say what would change if they needed to detect events that last only a few seconds.
Your work
Everything above is free to read and use. To save drafts, submit versions and get feedback, sign in.
You can also work on paper: the prompts below are what a submission asks for.
- Baseline average current (mA)
- Baseline battery life (h)
- Bytes for one baseline cycle of readings as 16-bit integers (bytes)
- Your design
- Your design's battery life (days)
- Justification and trade-offs
How it's judged
There is more than one good answer. This rubric describes what strong work looks like.
Energy calculation
- Beginning
- Battery life is guessed or the method mixes up current and charge.
- Developing
- The method is right but contains arithmetic or unit errors.
- Proficient
- Correct baseline and redesign calculations with units at every step.
- Exemplary
- As Proficient, plus a breakdown showing which part of the cycle dominates, used to guide the redesign.
Memory and representation
- Beginning
- Memory use is not considered.
- Developing
- Bytes are counted but the resolution requirement is not checked.
- Proficient
- A representation is chosen that meets 0.1 °C resolution and fits the buffer, with the buffer time calculated.
- Exemplary
- As Proficient, plus a scaled-integer scheme is specified (units per count, range) and overflow is ruled out.
Meeting the requirements
- Beginning
- The design does not meet 90 days or the 5-minute reading requirement.
- Developing
- Meets the requirements but with no margin or with an unchecked assumption.
- Proficient
- Meets all requirements with a stated margin.
- Exemplary
- As Proficient, plus the margin is justified by naming what could reduce real battery capacity.
Justification
- Beginning
- No justification beyond the numbers.
- Developing
- Lists what changed but not what was given up.
- Proficient
- Explains what was given up and why it suits the scientists' question.
- Exemplary
- As Proficient, plus explains how the design would have to change for a different scientific question.
Reflect
- Before calculating, which part of the cycle did you expect to use the most energy? Were you right?
- Why might two engineers given the same requirements choose different sampling rates, and both be right?
- What would you measure first on a real prototype to check your calculation?
Go further
The scientists ask whether the device could send only readings that changed by more than a set amount since the last transmission. Estimate how this would change radio energy, and describe what information would be lost and how you would make sure a missing reading is not mistaken for 'no change'.
Resources
- Power systems and energy budgets
- C types and overflow
- Units, scaling and fixed-point arithmetic
- Sampling rate and aliasing
- Inside a microcontroller
- AtlasElectrical power and energy budgets
- AtlasInside a microcontroller
- AtlasInterrupts and event-driven code
- AtlasUnits, scaling and fixed-point arithmetic
- AtlasReal-time computing on robots