Arduino boards have changed the face of DIY technology. Simple projects like creating miniature Arduino traffic lights are perfect for teaching beginners about basic electronics and programming.
Arduinos are perfect for home projects, and can be used on the move by attaching a battery pack to them. The problem is, even the chunkiest battery will be run down quickly by even a small Arduino board.
If you truly want your Arduino to run for the long haul, you are going to need to make some tweaks and changes.
1. Arduino Low-Power Software Libraries
There are several software libraries available that can change your Arduino’s power consumption. By sending the Arduino into a deep sleep for a set amount of time, power can be saved between operations. This is particularly useful for microcontrollers taking sensor readings in remote areas such as weather stations, or sensing sub-circuits for larger devices.
The Low-Power library by Github user rocketscream is an example of an easy to use library which is perfect for saving some power. Consider the following code, based on some of the library’s example code:
#include "LowPower.h"
// setup() your sensors/LEDs here
void loop()
{
// This next line powers the arduino down for 8 seconds
//ADC means analogue to digital conversion, and BOD for brown out detection
//both are turned off during the sleep period to save power
LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
//After each sleep, you can instruct the Arduino to carry out its tasks here - for example, take a temperature reading and send it to a server.
}
This code is a good start. Not only does it drop the power consumption using already built in methods, it turns off the potentially costly analogue to digital conversion (which can use power even when idle) and the brown out detection which stops the Arduino running code when its input voltage gets too low.
This is a simple but effective measure to start cutting down how much power your Arduino pulls. We can go much deeper than this though!
2. Arduino Built-In Power Saving
The Arduino programming language has its own built-in sleep functionality designed to help with power saving. The sleep function, used in tandem with interrupt clauses, allow the Arduino to wake up again.
Arduino has specific pins designed for interrupting the sleep cycle, and you can access them using the setup function:
#define interruptPin 2
void setup()
{
//interrupt pin MUST be Arduino pin 2 or 3 on Uno
//set the pin to pull up mode
pinMode(interruptPin, INPUT_PULLUP);
}
Now that this is set up as an interrupt pin, you can safely go about sending your Arduino to sleep. A simplified way of doing this is to create two small functions:
void sendToSleep()
{
//enable sleeping - note this primes sleep, not starts it!
sleep_enable();
//attach the interrupt, specify the pin, the method to call on interrupt,
//and the interrupt conditions, in this case when the pin is pulled low.
attachInterrupt(interruptPin, wakeUpAgain, LOW);
//actually activate sleep mode
sleep_cpu();
//code continues on from here after interrupt
Serial.println("Just awoke.");
}
void wakeUpAgain()
{
//stop sleep mode
sleep_disable();
//clear the interrupt
detachInterrupt(interrputPin);
}
The code above is a simplified way to send your Arduino into sleep mode, and you can wake it up again by connecting pin 2 to the GND pin. While the Arduino Uno is in sleep mode it shaves around 11mA off the total power draw, and if you use a Pro Mini instead you can expect to drop from 25mA regular power usage to just 0.57mA.
Interrupts are a great way to bring your power consumption down, and The Kurks blog has some detailed posts about them, which help to demystify interrupts for beginners.
3. Slow Down the Arduino Clock Speed
The clock speed of your Arduino determines how many operations it can perform per second. Most Arduino boards run on a 8 or 16 MHz processor, though some of the offshoot boards such as the Teensy 3.6 boast processing speeds of up to 180MHz! This is why many DIY hackers like to use Teensy boards over Arduino in their DIY projects.
All of this processing power comes at a power cost, and for many use cases employing the full clock speed is overkill. This is where regulating the clock speed through software can make a difference.
It would be remiss of me not to warn you, changing the clock speed can cause bootloader issues and may leave you with an Arduino you cannot upload sketches to, if done incorrectly.
If you do want to try changing your clock speed, along with making tools in the Arduino IDE to allow you to change CPU frequency on the fly, Pieter P’s detailed guide can help you get started.
4. Replace Power-Hungry Arduino Components
The Arduino Uno is the most popular board for beginners, and most Arduino kits supply either an official or clone model. Its larger form factor and hot swappable microchips make it perfect for experimentation, and its broad capacity for input voltages along with onboard voltage conversion for 3.3v components make it fit for almost every purpose.
All of this functionality doesn’t come cheap in terms of power usage. With this in mind, there are a number of things you can do to physically alter an Arduino Uno to save power.
The voltage regulator on the Arduino Uno causes the largest single power drain on the board. This isn’t particularly surprising, as it has to drop up to 7v safely from the input power supply to the board itself. Some have tried to get around this by replacing the regulator with more efficient ones, but this doesn’t really solve the issue.
Patrick Fenner of DefProc engineering came up with a great solution in his blog post covering Uno power saving strategies. By replacing the voltage regulator entirely with a DC-DC buck converter, he managed to half the power consumption of the microcontroller.
5. Make Your Own Arduino
A sure-fire way to only use the power needed for your project is to design a microcontroller to your own specifications. In the past we’ve shown how you can build your own Arduino for a fraction of the cost of an official board.
As well as having much more control over the size and scope of your circuit, this can bring power consumption down to 15.15mA in standby, and as little as 0.36mA in sleep mode. These figures are taken from the incredibly detailed post by Nick Gammon on his forum.
This post covers many other aspects of Arduino power saving, and is a fantastic resource to refer to when trying to squeeze a little more time out of a mobile power supply.
Use Arduino for Big Ideas and a Small Power Footprint
When you are working on your first beginner Arduino projects, power consumption probably isn’t too much of a concern.
As your ideas get bigger and require more thought, it is well worth learning ways to streamline your set up. Between making sure you get the right Arduino board and setting it up to get the most out of it, you can go a long way to making truly unique and useful devices. Good luck and keep tinkering!
Read the full article: 5 Arduino Power Saving Tips That’ll Keep Yours Running for Days
from MakeUseOf https://ift.tt/2u5PUmj
via IFTTT
0 comments: