Introduction

Last article, I wrote about how to use our own homemade Arduino Pro Mini bare bones along with an OLED display and how to make both of them consume as little power as possible. In fact, we managed to achieve a small 1.1 uA current with both of them sleeping. Also in our circuit there were a PCF8563 real-time clock module and one AT24C64 EEPROM memory. Now, to proceed with our smartwatch project we need to add sensors, such as an accelerometer, compass and pressure sensor. This article is about how to add them, read the variables and keep saving power.

Which sensor to use

Now that we have a watch running, I mean, a microcontroller reading a real-time clock module and throwing the data to a display, we can add some features to it! How about a pressure sensor? With a pressure sensor such as the BMP180 (or the BMP080), it is possible to get also the temperature from the environment, and with both information, the chip can estimate the altitude in which the person is.

Another very useful sensor could be the digital compass. The HMC5883L is an I2C compatible, very tiny compass that can point which direction the smartwatch is facing. The idea to put a compass was initially to help my sister, as she is a biologist an often have to enter forests or areas with dense vegetation. With a watch that has a very long battery duration, now she won’t get lost.

Another great sensor you must add to your device is the MPU6050 accelerometer. There is the possibility to use the MPU9150, which already has a compass inside it. However, the MPU9150 doesn’t have a very good library available online and is way more expensive than his cousin, the 6050. With the accelerometer data, the Atmega328p can work as a step counter. In possession of the number and frequency of the steps, the watch can estimate also the distance travelled and the calories spent on a daily basis. The sensors main features:

  • BMP180
    • Senses:
      1. Pressure;
      2. Temperature;
      3. Altitude;
    • Features:
      1. Pressure range: 300 to 1100 hPa;
      2. RMS noise 0.06 hPa, typ. (ultra-low power mode);
      3. 02 hPa, typ. (ultra-high resolution mode);
      4. I2C interface;
      5. Temperature: ±1 °C, typ.;
      6. Current (at 1Hz): 3 μA (ultra-low power mode);
      7. Current 32 μA, typical (advanced mode);
      8. Stand-by current 0.1 μA, typical;
      9. Supply voltage VDD 62 … 3.6 V;
      10. Operation temperature -40 to +85 °C;
      11. Maximum supply voltage all pins -0.3 +4.25 V;
      12. Package dimensions 6 x 3.8 x 0.93 mm³.
  • HMC5883L:
    • Responsible for:
      1. X, Y, Z compass;
    • Features:
      1. Fast 160 Hz maximum output rate;
      2. Software and algorithm support available;
      3. I2C digital interface;
      4. Low voltage operation (2.16 to 3.6V);
      5. Low power consumption (100 μA);
      6. Idle mode current 2 μA;
      7. 3-Axis magneto resistive sensors;
      8. Absolute maximum supply voltage 4.8 Volts;
  • MPU6050:
    • Responsible for:
      1. X, Y, Z accelerometer;
      2. X, Y, Z gyroscope;
      3. Step counter;
      4. Calories counter;
      5. Distance;
    • Features:
      1. Integrated 16-bit ADCs enable simultaneous sampling of gyros;
      2. Temperature stability reduces the need for user calibration;
      3. Digitally-programmable low-pass filter;
      4. Maximum supply voltage, VDD -0.5V to +6V;
      5. Gyroscope operating current: 3.6mA;
      6. Gyroscope standby current: 5µA;
      7. Accelerometer normal operating current: 500µA;
      8. Accelerometer low power current: 10µA at 1.25Hz;
      9. Orientation detection and signaling;
      10. Tap detection;
      11. High-G interrupt;
      12. 400kHz fast mode I2C;
      13. Digital Motion Processing engine supports 3D Motion Processing and gesture recognition algorithms;

Choose the board or make your own

It is possible to find these sensors on its own board separately or together on the same board. To test them on our breadboard, it is easier to buy each sensor on its own custom PCB. The downside is that these pcbs come with already soldered components that you do not want. For example, all these boards sold on EBay come with voltage regulators to guarantee the maximum voltage to the chips will be at 3.3V. However, these regulators consume a lot of power and, if we are making an application that keeps its voltage fixed, for instance, like a smartwatch powered by a lithium battery, we do not need them. To test the minimum current your watch will use, you will probably want all useless components out of your board. Another example are the LEDs that are placed just to show that the board is on! Totally useless. Each LED will consume easily 1.5mA, while we are trying to make the watch run with only 100uA, or 15 times lower than that. Now imagine each sensor using one LED just to show you they are on.

The problem is that it is too much complicated to make your own SMD board without the LED and voltage regulator, so you can buy a board on EBay, take out those components and short circuit some places and everything is fine. When the time comes to make the SMD board for the smartwatch, then you can make your own with all the pieces together. To use these sensors, the boards I recommend are:

  • GY-521 (MPU6050):

gy-521 schematic

GY-521 low powerThis module supports higher voltages than 3.3V, because it has a voltage regulator (the 3.3V LDO component from the figure above). To use it with low power mode, the user has to desolder the regulator, short-circuiting the 5V and 3.3V connectors (where the regulator was). In addition, it is good to remove the LED. This is show on the figure at the left. Buy on EBay, here.

  • GY-271 and 273 (HMC5883L):

gy-271-sch

GY-271 low powerAlong with the GY-521, this module supports higher voltages than 3.3V. To use it with low power mode, the user has to desolder the regulator, short-circuiting the 5V and 3.3V connectors (where the regulator was). This one however does not have LED. Watch out that after taking away the regulator you should not program the Arduino with these boards connected, because the UNO will use its 5V VCC to program the Pro Mini (Arduino as ISP). Buy on EBay, here. This version has an I2C NMOS, while the GY-273 does not. You can buy on EBay the GY-273 here.

  • GY-68 (BMP180):

GY-68-Diagrama-esquematicoThis board is the pressure sensor’s equivalent for the GY-273. Just remove the regulator and short circuit 5V and 3.3V. There you go! No LEDs. Buy it on EBay, here.

gy-68 low power

  • GY-87 (all in one):

GY-87-Diagrama-esquematico

gy-87 low powerThis is a good one. This board has all the sensors in it. It has the accelerometer MPU6050, the compass HMC5883L, and the pressure sensor BMP180. However, the board comes with a voltage regulator and LED. You have to take both of them off to work on low power. Moreover, to convert the I2C signal from 5V to 3.3V, it has the I2C NMOS. If you do not remove it, your circuit will not be the best possible. To remove it is easy. The tough part is to short circuit correctly the terminals, because you would have to connect SDA to H_SDA, SCL to H_SCL and 5V to 3.3V, all on that minuscule space between the pads. For me, I was happy just to remove the regulator and the LED and left everything else the way it was. It worked the same way. It was possible to lower the current on standby from 900 uA to only around 118 uA. Perhaps, if removed, this could lower to far below 100 uA. We will leave that for the final version! Buy it on EBay, here.

Connect the board

Simple enough just connect 3.3V VCC from breadboard to VCC, GND to GND (lol), SCL and SDA. The only different pin is the INTA from the accelerometer that should be connected to the PIN number 5 from the Atmega328p (digital input 3). This is because this output from the accelerometer will be used as an interrupt pin to the Arduino to wake it up from sleep on each step that the sensor reads. For example, the watch will be always sleeping. Just two events will be able to wake it up from sleep. A button being pressed, that means the person wants to know the time, or the accelerometer sending a signal telling the chip that the user made another step. On this case, the microcontroller add one step to its step counter, calculates the calories and then go to sleep again! Cool!

Program it and run

Now just throw all this code to your Arduino and everything should work perfectly. Because the code was too big, I put it on a GitHub account. Just click here and download the code. Download all the libraries and run it!

On that code you will see I worked a lot to make the accelerometer run as little as possible, consuming the minimum power possible. I made it wake up at only 1.25Hz to save power, besides disabling all the gyroscope’s axis and the temperature sensor forever (we will not use it), allowing interrupts at a certain movement threshold. I also made the magnetometer sleep at most times, to be woken up only when the user wants to know the direction he is facing. I also put the pressure sensor on an ultra-low power mode.

Results

mpu6050 hmc5883l bmp180 gy-87 pro mini low powerIf you followed all my previous tutorials, and was up to date, your system should display the same current as mine. Only 120 uA for all those sensors and the OLED display sleeping. It is possible to get even lower values, as I wrote: I did not remove the I2C NMOS as you can (probably) see on the image above. This way your smartwatch would have a 190mAh rechargeable battery that could last 66 days. Good. I expect a final SMD version even better, of course. The only thing consuming a lot of power (probably 99.9% of the power) is the GY-87 sensors board. The code is all right! We can just improve the hardware when we start designing the SMD board. Now we can begin to make the hardware on Eagle or improve our code.

step counter arduinoUpdate: I adapted the code a little on GitHub and now the interrupt increases the “stepcount” variable and it is possible to show this data on the Serial Monitor from the Arduino IDE. This was acheived using values of 3 for the Threshold of the movement and 5ms for the movement duration. Different values may generate different readings from the accelerometer. How can the developer declare these factors? One idea is to use the smartwatch while running on a threadmill, and making a “for” statement changing both these variables, one at a time, and plotting the readings on a graph.

threshold selection step counter accelerometerFirst walk a treadmill with the threshold value being altered. This is the value the accelerometer will use to consider that there is movement and then wake the Atmega via interrupt. For my experiments, declaring “thrs = 5” makes it easier to sense movement.

movement duration step counter accelerometerNow fixing the threshold to 5, change the movement duration variale. In my example I walked 10 steps on each one. With small durations, the accelerometer senses many steps more than it should, and bigger durations make it impossible to determine when there was movement. Time variable  “detcdur = 18” showed the best results.

Where to go from here

  • If I find useful links I’ll post them here.

2 thoughts on “Arduino Power-down Mode With Accelerometer, Compass and Pressure Sensor

  1. Olá, benhurgoncalves! Estou tentando fazendo um detector de passos, mas com outro acelerômetro e gostaria de tirar algumas dúvidas com você sobre a lógica do mesmo. É possível?

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s