Introduction: 3 Minute Game Timer, a Deep Sleeping ATtiny85 Digispark
Above, my final created unit is shown operating in two different containers, as well as being powered by a USB power bank (instead of a coin battery).
I wanted to make a small interesting timer to use with games like Boggle. I had an Attiny85 Digispark board so I decided to put it to use.
Further, I decided to use the Digispark over a bare Attiny85 chip because:
- I had the board on hand and no bare chips
- It provided easy wiring & mounting
- The board was easier (albeit not as easy as other boards) to program repeatedly than a bare chip.
Nonetheless, I would advise (if you know how & have means to program it) to use just the bare chip with a socket as you won't have to take so many measures to reduce power consumption during sleeps.
Step 1: Parts
The parts you'll need are:
- Digispark ATtiny85 board http://digistump.com/products/1 or http://www.ebay.com/itm/262085283993
- 3 LEDs (a green, a yellow and a red) http://www.ebay.com/itm/321464065222
- a 100 ohm resister.
- a tilt switch http://www.ebay.com/itm/191212877291
- an active buzzer http://www.ebay.com/itm/281280117872
- CR2032 battery and holder www.ebay.com/sch/?_nkw=Coin+Cell+Holder
- a 47 uF capacitor (not needed if you use 2 AAA batteries or a LiPo)
- a transparent container
- various equipment and tools (the usual stuff ... PC, cables, wires, strippers ...)
Above is an idealized diagram of how these parts interconnect for this project.
Step 2: Reducing the Power Consumption on the Digispark Board
The intention was to have no on-off switch and have the battery last as long as possible.
Under normal operations Digispark board consumes about 18-36 ma. And while fully asleep 12-24ma. Note that current measurements will vary as the Vcc voltage level used varies (I used 3 to 5V respectively). Half of this is consumed by the 78M05 voltage regulator (while not in use).
Using a 3 volt battery (attached to the '5V' pin), this regulator is less than worthless. So we cut it out of the circuit. This is done by cutting all three leads coming out of it (look close at image above). One lead was not connected in the first place. That the device remains soldered down is of no concern.
At this point typical power use is about 10-20 ma going to the MCU and LED(s), and a low power sleep is approximately 2.2-6 ma. The LEDs use 2-2.5 ma each. The one connected to PB1 is not an issue as the software controls it.
Cut the trace between the power-on LED and its supply resister (see image above). Do not remove either of these components; this way you should be able to reactivate the power-on LED with a little conductive ink placed over the cut. http://www.ebay.com/itm/191724561789
Afterwards, with 3.1volts on '5V', I measured 8ma while MCU was awake and 0.37ma while asleep. Using 5v going to '5V' it was 15ma awake and 1.5ma asleep.
Step 3: Optional Additional Power Saving Measures
For those who plan to cut off the battery supply for long term storage, via switch or battery removal, this is more than enough power savings.
If this is not the case and you are proficient with fine soldering and caring for surface mount components, then you may want to take these additional measures.
To further reduce ambient current drain, I also cut the trace to the resister R3 used to pull up the PB3 signal (for USB download communications) Digispark schematic. This is rather problematic, as it has to be effectively undone in order to allow download via USB. Furthermore it seems that the loaded logic which runs on power-up gets stuck if the data line connected to R3 is not pulled up. Thus, I had to solder in (very carefully and precariously a diode (1N4148) from the '5v' line to the end of R3 I had cut the trace by. So it might be best to only take these actions once you're pretty sure you are done playing with the code.
Using PB3, for the tilt switch, continued to cause operational and perhaps power management issues, so I stop using it. Also note that many USB battery power banks connect the data lines together which causes cross talk between PB3 & PB4. This significantly confused my testing, when using these convenient power sources.
With these actions, I was able to get the power consumption during a deep sleep down to 0.02ma ( 20 micro-amps) with a 3 volt supply. This will allow for about one year life for the battery, without excessive use. I have heard that others got a bare Attiny85 down to 0.2 micro-amps (0.0002 ma) I tested my modified board with the code they used, from http://www.technoblogy.com/show?KX0 And I measured 0.02 ma. So I don't know where the current difference is going. Granted I could not wake it up as I did not modify my on-board chip so it would respond to a reset, but the power use should have been the same, given the coding used. I then thought that there might be leakage through the zener diodes attached to the USB data lines but I was unable to get that to prove out.
It would be great to extend the battery life, while connected to a Digispark board, another order of magnitude; so if anyone manages it please let me know.
Step 4: The Assembly
For prototyping this, I used a solderless breadboard assembly; shown above.
For a reduced part count I used one resister to limit the LED current flow. Since only one LED is lit at a time and all three illuminate close enough to the same brilliance with the same limiting resistance (of 100 Ohms) there is no big advantage of using separate resisters.
I wired the parts directly to the Digispark board so as to have an assembly which would fit inside of a small vessel. I used a semi-transparent 35mm film container. Sorry but I can't tell you where you can obtain one of these. You may consider using a pill bottle or a small glass decanter.
Be sure to mount the tilt switch so it is normally open while the container sets how you want it while it is timing and during storage.
To hold the project assembly still while the container was being rocked back and forth, I hot glued the spring metal from a binder clip to the inside of the container's top. I first drilled a hole in the lid and the base of the spring metal clip so the glue could have a place to hold better. I did put a piece of masking tape inside the clip so the glue would not ooze into the inside. Additionally I filed the USB edge of the board so it could be wedged in the clip more easily. And to prevent gouging of the contacts or shorting them together, I wrap a piece of paper over the edge of the board before pressing it in. You can make all this out by closely studying the last few images above.
When finally putting my assembly into the tightly fitting container I had to file off the corner of the buzzer. I also secured the battery holder to the PCB with a little hot glue.
To my pleasant surprise, I found that the lid from the film container also fit on the small pill bottle I had.
Step 5: The Code
I believe the code is pretty straight forward. Assuming prior use of the Arduino IDE . The code includes comments to aid understanding.
When programming the MCU (uploading the sketch) be sure to select the board as “Digispark (Default – 16.5mhz)”, else the timing will not be right; unless you also 'burn a fuse' setting reflecting the CPU clock change.
If you have not programmed a Digispark with the Arduino IDE check out this Digispark tutorial: http://digistump.com/wiki/digispark/tutorials/conn...
Attachments
Step 6: Operation
After an initial power up the timing between LED flashes is about 4 seconds instead of a minute. That is to facilitate testing and to validate assembly health.
When the unit has been flipped over and put back up right, there will be three quick flashes and chirps. This marks the beginning of the timer period. The following is what happens on each successive minute.
- quick Green flash and a chirp
- quick Green then Yellow flash + chirps
- flash of Green – Yellow then long Red LED flash with buzzer
- four quick Yellow flashes + chirps
- five Red flashes + chirps and ending with a buzzer
These can, of course, all be changed to one's liking in the software.
Watch the video above, it shows the device in the initial accelerated mode, but all of the flashes and beeps are as they will be when there is a full minute interval between them.
The device will go into the power-down sleep mode after it completes it timing function and anytime there has been no change of state of the tilt switch. Don't leave the device on its side, the switch may make sporadic contact.
Note, I have applications for both 3 & 5 minute time outs. By the way, the whole timing process can be stopped at any point by simply turning the timer back over.
Step 7: Epilogue
While this device works fine with three volts, I found that my unit, with an old battery, would begin to fail when the voltage being supplied fell below 2.9 volts.
I found that the main contributors to this situation were:
- The Digispark uses an ATtiny85-20SU, which is designed to operate at up to 20MHz but its lowest operating voltage is spec-ed at 2.7v (so it should have worked, Right !?)
- The buzzer was drawing an additional 14ma for up to 1 second. This put a total of 30 or more milliamps being pulled from the button battery.
- The battery has a limited current drain rate. The instantaneous use was more than 10% of its capacity rating of 200mah. Causing it to sag.
Viable solutions to the above:
- New fresh battery
- Reduce current use of Buzzer (by activation time; or could have put a 50ohm in series)
- Don't light an LED and buzzer at the same time
- Run CPU at low MHz, to allow slightly lower Vcc use.
- Add a compact 100-1000uf cap, to reduce Vcc sag. [found to be effective, but I don't know for how long]
- Instead use a ATtiny85V (1.8v-5.5v) chip for low power operation
With the last solution in mind, having started with a bare chip (given it was of the '85V' variety) in the first place looks like a better idea then I had considered it to be.
Items 2 and 3 above are now done in the project software.
Update: With low voltage, the PB5 line was giving insufficient drive to the third (red) LED. Which is to be expected per wiki/digispark/quickref.
So I moved my red LED to PB3. Now it looks fine. however ... Whereas the switch I had earlier on PB3 would prevent new code uploads if the switch was closed; The side effect of LED-100ohm resister on PB5 was the LED flashing at power up (due to the boot-loader trying to communicate) and loader failures due to too much load on the line. So to alleviate this when doing updates, I temporarily jumper-ed a 270ohm resister from where the 100ohm attaches to the LEDs and Vcc, to offset some of the pull down effect of the 100ohm.
11 Comments
3 years ago
Thanks for this insights especially on power saving. I tried and tested a little bit myself and I think the additional 320uA are not going into PB3, but through the Zener Diode. I cut the connection between R3 and the Zener and also ended up with 20uA (@3V), keeping PB3 pulled up. On my board this place is also easier to cut. With a jumper I can go back to programming mode.
What I really do not understand how you can drive the 5V to R3 with a diode while still having 20uA power down current. Do you have any details on this?
https://s3.amazonaws.com/digistump-resources/files/97a1bb28_DigisparkSchematic.pdf
For further power saving, I think you need to disable the Brown Out Detector (BOD). I will test this later and let you know.
Reply 2 years ago
I can confirm that it is possible to further reduce power consumption to 0.5uA if you disable the brown out detection feature. This uses about 20uA. Do this by setting the ATTiny85 High fuse to 0xDF which equates to BODLEVEL=111.
These are the settings I used:
# avrdude -p attiny85 -c usbasp -v -U lfuse:w:0xe1:m -U hfuse:w:0xdf:m -U efuse:w:0xfe:m
Reply 3 years ago
Great discovery. I would not have expected so much leak current thru a 3.6v Zener when only pulled 'up' to a ~3.1v supply.
I can't verify it now, but It appears that I cut at the connection between R3 and the '5v' line then put a 0.7v drop diode between them. This then eliminated the leakage, with 3v battery use, thru the 3.6v Zener (that you noted during sleeping) and still provides a logical high level at PB3 when needed. Note: my battery+ is connected to the '5V' pad (& the USB-5vRegulator supply is cut).
As wired my unit does not need any jumper to program it. I simply add in the coin battery when the Arduino IDE is ready to connect for downloading.
I'll update the document to clarify, sometime soon.
Reply 2 years ago
Hi,
Please, could you you explain in more details how you power up digispark with CR2032?
I've try to use +5V, VIN, USB+5V, without success. Power regulator is cut.
Regards
Reply 2 years ago
I see I left out the battery in the drawing in step 2. I updated that and the text to reflect that the battery connects between the '5V' and 'GND' pins. Check that your device uses the ATtiny85-20SU. The min voltage for this device is 2.7V. CR2032 can supply this voltage at the needed current only if they are relatively fresh (?~50%). Note that old batteries due lose capacity. They are also fairly wimpy batteries. They can show full voltage with no load, then drop fast under load. Test for that. A new battery connected to '5V' should do it for you. BTW, if you can get an ATtiny85-10SU their minimum operating voltage is 1.8V.
Reply 2 years ago
Thank you. After some attempts I succeed with 47 microF capacitor between GND and +5V pin
Reply 2 years ago
BTW: you could have opted powering with 2 AAAs or a LiPo battery. They would easily handled the small current spikes. But then again they would take up more room then the CR2032 + electrolytic cap.
Please do an "I made it" post with photo(s).
Reply 2 years ago
That's great to here! :~}
I'll add that in.
7 years ago
great work!!!
i'd like to do something similar with digispark ldr and rgb
Reply 7 years ago
Thank you for sharing.
Using a single RGB LED reduces part count and solder connections and could make for a little more compact final unit; while electrically and software wise there is virtually no difference. Cool. Looking forward to an 'I made it' posting from you.
Using an LDR (Light Dependent Resistor; I did not recognize this acronym, I think of as them photo-resisters), in an auto power on-off circuit may have some issues. In the circuit's off state, it would need to use <<20ua in order to significantly allow for longer battery life than already achieved. If it does do that, It would likely only do so when stored in extreme darkness. So you could not leave it out on display. I would expect that in the circuit's On state, it would end up with about 0.2v drop across a driving transistor. As I found these 1/10 volts are precious when using a 3v coin-cell and a standard Digispark.
7 years ago
This is fun. Great DIY timer.