Save some amps!. Lower the Power requirement in Arduino_Hack

Saving the power when your projects are power with batteries, every milliamps counts when use batteries. So in this post we going to learn ways to put Arduino in a state where we can save some power.

Hence that being said how the heck were going to do that?? , well one smart way to start with use the bare bone atmega328pu chip alone with some crystal and capacitors and resistors.

Another way to do is use the sleep registers to put unnecessary ports and pins to sleep. The tips are listed below:

1-Use the Bare Bone atmega328pu chip:

Use the bare bone atmega328pu chip alone with some crystal and capacitors and resistors consumes less power than PCB one, how much current if you ask? Around 20 mA.

2-Start writing all the pins either high or low:

 By writing all pins high are low you do reduce the power consumption to 3 or 4 milliamps.

[NOTE I’M TALKING ABOUT USING A BARE BONE ATMEGA328PU AS EXAMPLE IT CONSUMES LIKE 17 mA and so.]

Put this in void setup () Code:

       

for (i=0; i<20; i++)

{

        pinMode(i,OUTPUT);

}

 

3-Use the sleep modes register:

The one we looking for is Power Down mode from the datasheet. This is the deepest sleep you can put Arduino into. We do that with by setting bits in SMCR register.

SMCR register

7              6              5             4             3            2            1            0

-

-

-

-

SM2

SM1

SM0

SE

 

          SM2

             SM1

             SM0

             0

               1

                0

 

“SE” bit need to set it just before execution and clear immediately, well this is the trick:

Put this in void loop()

        //ENABLE SLEEP

 SMCR |= (1<<2); // enable power down

 SMCR |= 1;  // enable sleep

__asm__  __volatile__("sleep");//in line assembler to go to sleep

 

This trick allows you to consume all the way down to uA(micro amps) of current.

 

4-Turn OFF the ADC:

By turning off the ADC when it’s not in use we can save power even better.

By controlling the ADCSRA register in datasheet we can do that.

ADCSRA

7              6              5              4              3              2              1            0

ADEN

ADSC

ADATE

ADIF

ADIE

ADPS2

ADPS1

ADPS0

We are interested in bit-7 “ADEN” which enable or disable adc, Set that to 0 we can turn off ADC.

 Put this in void loop ()

// turn off ADC

ADCSRA  &=  ~(1<<7);

[NOTE: IF YOU NEED THE ADC IN YOUR PROJECT DON’T USE THIS METHOD]

Doing this also reduces the usage of power a lot to uA.

 

By doing all at once we can run at 100uA which is A LOT! Of power saving we can even do more but I’m happy till now. There are other ways but it might make Arduino of yours damage.

[NOTE: YOU CAN USE ABOVE METHODS BUT YOU NEED AN INTERRUPT MAKE ARDUINO TO NORMAL STATE AGAIN YOU NEED A PUSH BUTTON TO DO THAT]

 

Hence the final code:     The code lets the user to blink an led at pin4 and puts to sleep and wake up by push button attached to pin 3(interrupt 0)


void setup() {

  Serial.begin(9600);

  pinMode(4, OUTPUT);

  for (int i = 0; i < 20; i++)

  {

    if (i != 2)  // helps in not messing up our led pin4 output.

      pinMode(i, OUTPUT);

  }

  attachInterrupt(0, digitalInterrupt, FALLING); //interrupt for waking arduino

}

 

void loop()

{

  digitalWrite(4, HIGH);

  delay(1000);

  digitalWrite(4, LOW);

 

  //ENABLE SLEEP

  SMCR |= (1 << 2); // enable power down

  SMCR |= 1;  // enable sleep

  __asm__  __volatile__("sleep");//in line assembler to go to sleep

 

  //Disable ADC

  ADCSRA  &=  ~(1 << 7);

}

void digitalInterrupt()

{

}


For further clarification you can watch this video by kevin and check datasheet for more tips and tricks.

Comments

Popular posts from this blog

"Kernel Panic” error After upgrading Parrot OS

HACK HC-05(BLUETOOTH MODULE) FRIMWARE INTO HID FRIMWARE

HACK AND CLONE CAR KEY FOB, MY EPIC FAILURE...!!