Skip to content

Commit e8d834e

Browse files
Merge pull request #1709 from arduino/karlsoderby/learn-power-consumption
[Learn] Power Consumption (WIP)
2 parents 1c80ca7 + b8ab453 commit e8d834e

File tree

6 files changed

+194
-0
lines changed

6 files changed

+194
-0
lines changed
Loading
Loading
Loading
Loading
Loading
Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
---
2+
title: "Power Consumption on Arduino Boards"
3+
description: "Learn about measuring power consumption on an Arduino board."
4+
tags: [Power Consumption]
5+
author: "Karl Söderby"
6+
---
7+
8+
All electronic devices, including Arduino boards, consume power. The power consumption is measured in ampere-hours (Ah), and with low-voltage devices, it is typically measured in mAh.
9+
10+
When creating projects that run on a battery or are power-constrained, taking power consumption into account can be critical. It will among other things help you decide which kind of battery you need to use.
11+
12+
In this article, we will demonstrate how you can perform power consumption tests, using a **power profiler**. A power profiler is used to measure consumption over a specific time, where we record several thousand samples. You will find instructions for both the hardware setup, the software setup, and the actual power consumption tests in this article.
13+
14+
**_Note that in this article, third-party products are being used._**
15+
16+
## Hardware & Software Needed
17+
18+
For the power consumption tests in this article, we used the following hardware & software. Note that there are many alternatives on the market.
19+
20+
- [nRF Connect for Desktop](https://www.nordicsemi.com/Products/Development-tools/nRF-Connect-for-Desktop/Download)
21+
- [Power Profiler Kit II](https://www.nordicsemi.com/Products/Development-hardware/Power-Profiler-Kit-2)
22+
- [Arduino board (link to store)](https://store.arduino.cc/)
23+
- Jumper wires
24+
25+
## Measuring Power Consumption
26+
27+
Power consumption measurements are done by connecting a power profiler between your Arduino board and computer. The power profiler is connected to the computer via USB, and then to the Arduino board via jumper wires. For power consumption measurements, we simply use two wires: **power** and **ground**. The power cable is connected to your Arduino board's power pins, and the ground cable goes to one of the GND pins on the board.
28+
29+
When connected, the power profiler can measure the power consumption of your board with high accuracy. Any power that your board consumes can now be detected, and with a software tool (such as the [nRF Connect for Desktop](https://www.nordicsemi.com/Products/Development-tools/nRF-Connect-for-Desktop/Download)), we can record power consumption over time.
30+
31+
So what is it that we are measuring? In very simple terms, all electronic devices draw current, whether it is small or big. A small LED can for example draw 10 mA (0.01 A), while a servo motor can draw up towards 1000 mA (1 A). If you have an LED on for an hour that draws 10 mA, we can express it as **mAh**, which means **milli-ampers consumed per hour**.
32+
33+
### Power Consumption Example
34+
35+
To provide a practical example, let's take the [Nano ESP32](https://store.arduino.cc/products/nano-esp32) and run a simple sketch on the board, which continuously runs the `analogRead()` function. Running the test for 60 seconds recording 100'000 samples, results in an average consumption of **31.05 mA**.
36+
37+
Now, if we wanted to power this application using a 300 mAh battery we need to calculate the time with the following formula:
38+
39+
![Formular](./assets/formula.png)
40+
41+
With that information, we can make an educated guess of what type of battery we should get. For example, a battery with more capacity, let's say 600 mAh, would in theory last for twice the period.
42+
43+
**_Note that there are other factors at play, such as the battery's discharge rate and the general quality of the battery. The above formulas and measurements are to be considered guidelines._**
44+
45+
## Software Setup
46+
47+
The software setup involves two steps: **uploading a sketch** and **installing nRF Connect for Desktop**.
48+
49+
### Upload Sketch
50+
51+
This step is rather straightforward. Upload the sketch that you want to measure the power consumption of. Below is a minimal sketch that reads an analog pin continuously.
52+
53+
```arduino
54+
void setup() {}
55+
56+
void loop() {
57+
int analog_value = analogRead(A0);
58+
delay(1);
59+
}
60+
```
61+
62+
### Install Desktop App
63+
64+
To measure the power consumption, we are going to use the [nRF Connect for Desktop](https://www.nordicsemi.com/Products/Development-tools/nRF-Connect-for-Desktop/Download) tool. This is a program that you install on your computer.
65+
66+
## Hardware Setup
67+
68+
The profiler we used is the [Power Profiler Kit II](https://www.nordicsemi.com/Products/Development-hardware/Power-Profiler-Kit-2).
69+
70+
1. First, disconnect the USB cable from your board. You will be powering the board directly from the power profiler, so there's no need for the USB cable at this point.
71+
2. Use the provided cable from the kit, and connect it to your board's GND and power pin, following the illustration below:
72+
73+
![Connect the power profiler to the board.](./assets/circuit.png)
74+
75+
**_Important note! In the software setup, you enable the "Power Output" of the power profiler. Make sure that the voltage (3.3 V or 5 V) matches the voltage on the power pin of the board. Applying 5 V to a 3.3 V pin will damage your board._**
76+
77+
## Power Consumption Test
78+
79+
With the hardware and software set up, let's take a look at how to record the power consumption of your device.
80+
81+
1. Open the **nRF Desktop App**
82+
2. instructions for setting up the PP
83+
3. Enable the power output, by clicking the "Enable Power Output" option.
84+
85+
![Enable power output.](./assets/powerOutput.png)
86+
87+
4. Select sample period (60 seconds) and number of samples (100k).
88+
5. Click on "Begin Sampling" to start the power consumption test.
89+
90+
![Start sampling.](./assets/startSampling.png)
91+
92+
6. During the test, you can see the power consumption in real-time. After 60 seconds (or when the specified sample period ends), you will have the data, which includes the **max** and **avg** consumption. You can also zoom in to view the data.
93+
94+
![Power consumption data.](./assets/consumption.png)
95+
96+
You have now recorded the power consumption of your device. You can note down the results, export it as a `.csv` or take a screenshot for future reference.
97+
98+
## Example Results
99+
100+
In this section, you will find a number of tests we ran on a set of Arduino boards during different conditions.
101+
102+
### Simple Analog Read
103+
104+
The simple analog read sketch continuously reads an analog pin.
105+
106+
```arduino
107+
void setup() {}
108+
109+
void loop() {
110+
int analog_value = analogRead(A0);
111+
delay(1);
112+
}
113+
```
114+
115+
In the table below, you can see the results of each board tested with the sketch:
116+
117+
| Board | Min | Max | Average |
118+
| ------------ | -------- | --------- | -------- |
119+
| UNO R4 WiFi | 82.86 mA | 124.04 mA | 92.63 mA |
120+
| GIGA R1 WiFi | 51.02 mA | 94.08 mA | 58.05 mA |
121+
| Nano ESP32 | 29.18 mA | 46.58 mA | 31.05 mA |
122+
123+
### Arduino Cloud Basic
124+
125+
The **Arduino Cloud Basic** sketch sends sensor data to the Arduino Cloud and turns on the built-in LED whenever activated from a dashboard.
126+
127+
```arduino
128+
/*
129+
Sketch generated by the Arduino IoT Cloud Thing "Cloud Blink"
130+
131+
Arduino IoT Cloud Variables description
132+
133+
The following variables are automatically generated and updated when changes are made to the Thing
134+
135+
bool led;
136+
137+
Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
138+
which are called when their values are changed from the Dashboard.
139+
These functions are generated with the Thing and added at the end of this sketch.
140+
*/
141+
142+
#include "thingProperties.h"
143+
144+
void setup() {
145+
// Initialize serial and wait for port to open:
146+
Serial.begin(9600);
147+
// This delay gives the chance to wait for a Serial Monitor without blocking if none is found
148+
delay(1500);
149+
150+
// Defined in thingProperties.h
151+
initProperties();
152+
153+
// Connect to Arduino IoT Cloud
154+
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
155+
156+
/*
157+
The following function allows you to obtain more information
158+
related to the state of network and IoT Cloud connection and errors
159+
the higher number the more granular information you’ll get.
160+
The default is 0 (only errors).
161+
Maximum is 4
162+
*/
163+
setDebugMessageLevel(2);
164+
ArduinoCloud.printDebugInfo();
165+
pinMode(LED_BUILTIN, OUTPUT);
166+
}
167+
168+
void loop() {
169+
ArduinoCloud.update();
170+
digitalWrite(LED_BUILTIN, led);
171+
}
172+
173+
/*
174+
Since Led is READ_WRITE variable, onLedChange() is
175+
executed every time a new value is received from IoT Cloud.
176+
*/
177+
void onLedChange() {
178+
Serial.print("Led status changed:");
179+
Serial.println(led);
180+
}
181+
182+
```
183+
184+
In the table below, you can see the results of each board tested with the sketch:
185+
186+
| Board | Min | Max | Average |
187+
| ------------ | --------- | --------- | --------- |
188+
| UNO R4 WiFi | 94.07 mA | 513.70 mA | 140.19 mA |
189+
| GIGA R1 WiFi | 121.00 mA | 477.44 mA | 139.83 mA |
190+
| Nano ESP32 | 36.70 mA | 274.19 mA | 58.81 mA |
191+
192+
## Summary
193+
194+
In this guide, we have learned how to use a power profiler to record power consumption data. This is an incredibly good utility, as it helps you identify the power needs of your application, which can aid your decision in selecting the right power source.

0 commit comments

Comments
 (0)