1

I am using Attiny85 to control 4 LEDs parallelly with a programmable switch. But even though when the LEDs are in OFF state, current consumption is around 7-8mA. I am using a 200mAh battery in my project and it is draining up the whole battery in 24hrs (when the LEDs are in OFF state)

Below is the schematic image of my attiny85 circuit: Attiny85 circuit

Code:

//Absolute maximum current of each pin of Attiny85 is 40mA
//So each LED has been given to seperate pins

const int buttonPin = 2;    // the pin that the pushbutton is attached to
const int ledPin1 = 0;      // the pin that the White LED1 is attached to 
const int ledPin2 = 1;      // the pin that the Blue LED1 is attached to
const int ledPin3 = 3;      // the pin that the White LED2 is attached to 
const int ledPin4 = 4;      // the pin that the Blue LED2 is attached to 

// Variables will change:
int counter = 1;             // counter for the number of button presses
int buttonState = 0;         // current state of the button
int lastButtonState = 0;     // previous state of the button

void setup() {
  pinMode(buttonPin, INPUT);
  pinMode(ledPin1, OUTPUT);
  pinMode(ledPin2, OUTPUT);
  pinMode(ledPin3, OUTPUT);
  pinMode(ledPin4, OUTPUT); 
  //Serial.begin(9600); 
}

void loop() {
  buttonState = digitalRead(buttonPin);    // read the pushbutton input pin

  if (buttonState != lastButtonState) {    // compare the buttonState to its previous state
    if (buttonState == HIGH) {             // if the state has changed, increment the counter
      counter++;                           // if the current state is HIGH then the button went from off to on:
    }
    delay(50);                    // Delay a little bit to avoid bouncing
  }

  lastButtonState = buttonState;  // save the current state as the last state for next time through the loop

  if (counter == 2) {              
    digitalWrite(ledPin1, HIGH);  //turns on White LED1
    digitalWrite(ledPin2, LOW);
    digitalWrite(ledPin3, LOW);
    digitalWrite(ledPin4, LOW); 
  }
  else if (counter == 3) {        //turns on White LED2
    digitalWrite(ledPin1, LOW);
    digitalWrite(ledPin2, LOW);
    digitalWrite(ledPin3, HIGH);
    digitalWrite(ledPin4, LOW); 
  }
  else if (counter == 4) {        //turns on both White LEDs
    digitalWrite(ledPin1, HIGH);
    digitalWrite(ledPin2, LOW);
    digitalWrite(ledPin3, HIGH);
    digitalWrite(ledPin4, LOW); 
  }
    else if (counter == 5) {        //turns on Blue LED1
    digitalWrite(ledPin1, LOW);
    digitalWrite(ledPin2, HIGH);
    digitalWrite(ledPin3, LOW);
    digitalWrite(ledPin4, LOW); 
  }
    else if (counter == 6) {       //turns on Blue LED2
    digitalWrite(ledPin1, LOW);
    digitalWrite(ledPin2, LOW);
    digitalWrite(ledPin3, LOW);
    digitalWrite(ledPin4, HIGH); 
  }
  else if (counter >= 7) {         //turns on both Blue LEDs
    digitalWrite(ledPin1, LOW);    
    digitalWrite(ledPin2, HIGH);
    digitalWrite(ledPin3, LOW);
    digitalWrite(ledPin4, HIGH); 
    counter = 0;
  }
  else if (counter == 1){         // turns off all the LEDs after one button push
    digitalWrite(ledPin1, LOW);
    digitalWrite(ledPin2, LOW);
    digitalWrite(ledPin3, LOW);
    digitalWrite(ledPin4, LOW); 
  }
}

For each time push button is pressed, respective LEDs get ON and there are 6 such cases. In 7th case, it goes back to case 1.

So, is there a way to reduce the current consumption?

Is there any commands where we can,

  1. Reduce the clock frequency
  2. Disable all the interrupts
  3. Disable all modules etcc.....when not in use

If the current consumption goes less than 1mA that would be great.

4
  • 1
    The key word you want to search for is “sleep”. – Edgar Bonet Dec 25 '20 at 13:14
  • electronics.stackexchange.com/questions/349496/… . You can have the MCU in power-down mode most of the time, and only wake it up (via an interrupt) when the button is pressed. It's probably easier to move the button pin to the INT0 pin for that. After that you should get sub 1mA currents (when all leds are also off). After that, you can disable the ADC to save a few tens of µA's. – Gerben Dec 25 '20 at 13:55
  • 1
    The VCC line of your ATTiny85 is connected to something called VBOOST; I just wanted to point out that the power you save by putting your ATTiny85 to sleep will probably be peanuts compared to what you'll save by shutting down the boost regulator when it's not used. If you're unable to do that, it may not matter so much whether you put the ATTiny85 to sleep. – timemage Dec 25 '20 at 16:27
  • Yes. I have placed a SPDT switch in between so that there wont be any drain @timemage – enoughisenough Dec 28 '20 at 4:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.