You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
description: 'Learn about measuring power consumption on an Arduino board.'
2
+
title: "Power Consumption on Arduino Boards"
3
+
description: "Learn about measuring power consumption on an Arduino board."
4
4
tags: [Power Consumption]
5
-
author: 'Karl Söderby'
5
+
author: "Karl Söderby"
6
6
---
7
7
8
-
All electronic devices, including Arduino boards, consume power. The power consumption is measured in amperehours (Ah), and with lowvoltage devices, it is typically measured in mAh.
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
9
10
-
When creating projects that run on a battery or is 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.
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
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 period, where we record several thousands samples. You will find instructions for both the hardware setup, the software setup, and the actual power consumption tests in this article.
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
13
14
-
***Note that in this article, thirdparty products are being used.***
14
+
**_Note that in this article, third-party products are being used._**
15
15
16
16
## Hardware & Software Needed
17
17
18
-
For power consumption tests in this article, we used the following hardware & software. Note that there are many alternatives on the market.
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
19
20
20
-[nRF Connect for Desktop](https://www.nordicsemi.com/Products/Development-tools/nRF-Connect-for-Desktop/Download)
@@ -24,35 +24,39 @@ For power consumption tests in this article, we used the following hardware & so
24
24
25
25
## Measuring Power Consumption
26
26
27
-
Power consumption measurements are done by connecting a power profiler between your Arduino and computer. The power profiler is connected to the computer via USB, and then to the Arduino via jumper wires. For power consumption measurements, we simply use two wires: **power** and **ground**. The power cable is connected to your Arduino's power pins, and ground goes to one of the GND pins on the board.
27
+
Power consumption measurements are done by connecting a power profiler between your Arduino and computer. The power profiler is connected to the computer via USB, and then to the Arduino via jumper wires. For power consumption measurements, we simply use two wires: **power** and **ground**. The power cable is connected to your Arduino's power pins, and the ground cable goes to one of the GND pins on the board.
28
28
29
-
When it is connected, the power profiler can measure the power consumption of your board with a 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.
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
30
31
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
32
33
33
### Power Consumption Example
34
34
35
-
To provide a practical example, let's take the [Nano ESP32](). We ran a simple sketch on the board, which continuously runs the `analogRead()` function. The test ran for 60 seconds, and recorded 100'000 samples. The result was an average of **31.05 mA**.
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
36
37
-
Now, if we wanted to power this application using a battery, we know that the power consumption is 31.05 mA. If we intend to run the application with a fully re-charged 300 mAh battery, we would be able to run for approximately 9 hours, as we would be consuming **31.05 * 9 = 279.45**, according to the formula below:
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
38
39
-
-**milli-ampere hours (mAh) = power consumption * hours**
39
+

40
40
41
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
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
-
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._**
45
44
46
45
## Software Setup
47
46
48
-
The software setup involves two steps: **upload a sketch** and **insatlling nRF Connect for Desktop**.
47
+
The software setup involves two steps: **uploading a sketch** and **installing nRF Connect for Desktop**.
49
48
50
49
### Upload Sketch
51
50
52
-
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.
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.
53
52
54
53
```arduino
54
+
void setup() {}
55
55
56
+
void loop() {
57
+
int analog_value = analogRead(A0);
58
+
delay(1);
59
+
}
56
60
```
57
61
58
62
### Install Desktop App
@@ -63,12 +67,12 @@ To measure the power consumption, we are going to use the [nRF Connect for Deskt
63
67
64
68
The profiler we used is the [Power Profiler Kit II](https://www.nordicsemi.com/Products/Development-hardware/Power-Profiler-Kit-2).
65
69
66
-
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.
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.
67
71
2. Use the provided cable from the kit, and connect it to your board's GND and power pin, following the illustration below:
68
72
69
-
![Connect the power profiler to the board.]()
73
+

70
74
71
-
***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.***
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._**
72
76
73
77
## Power Consumption Test
74
78
@@ -77,17 +81,17 @@ With the hardware and software set up, let's take a look at how to record the po
77
81
1. Open the **nRF Desktop App**
78
82
2. instructions for setting up the PP
79
83
3. Enable the power output, by clicking the "Enable Power Output" option.
80
-
81
-
![Enable power output.]()
84
+
85
+

82
86
83
87
4. Select sample period (60 seconds) and number of samples (100k).
84
-
5. Click on the "Begin Sampling" to start the power consumption test.
85
-
86
-
![Start sampling.]()
88
+
5. Click on "Begin Sampling" to start the power consumption test.
89
+
90
+

87
91
88
-
6. During the test, you can see the power consumption in real-time. After 60 seconds (or when 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.
89
-
90
-
![Power consumption data.]()
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.
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.
93
97
@@ -100,9 +104,7 @@ In this section, you will find a number of tests we ran on a set of Arduino boar
100
104
The simple analog read sketch continuously reads an analog pin.
101
105
102
106
```arduino
103
-
void setup() {
104
-
105
-
}
107
+
void setup() {}
106
108
107
109
void loop() {
108
110
int analog_value = analogRead(A0);
@@ -118,13 +120,64 @@ In the table below, you can see the results of each board tested with the sketch
118
120
| GIGA R1 WiFi | 51.02 mA | 94.08 mA | 58.05 mA |
119
121
| Nano ESP32 | 29.18 mA | 46.58 mA | 31.05 mA |
120
122
121
-
122
-
123
123
### Arduino Cloud Basic
124
124
125
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
126
127
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
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
+
}
128
181
129
182
```
130
183
@@ -138,5 +191,4 @@ In the table below, you can see the results of each board tested with the sketch
138
191
139
192
## Summary
140
193
141
-
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.
142
-
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