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:
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,
- Reduce the clock frequency
- Disable all the interrupts
- Disable all modules etcc.....when not in use
If the current consumption goes less than 1mA that would be great.
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