You are on page 1of 8

technology

workshop

living

food

play

outside

Arduino decision box V2.0 (Attiny85)


by Victor8o5 on March 13, 2015

Table of Contents
Arduino decision box V2.0 (Attiny85) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Intro: Arduino decision box V2.0 (Attiny85) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Step 1: Materials: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Step 2: The circuit: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Step 3: Assembling the cube. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Step 4: Connectors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Step 5: Uploading the code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

File Downloads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Step 6: Customization and probabilities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Step 7: ??? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Step 8: Thanks for watching! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Related Instructables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Advertisements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

http://www.instructables.com/id/Arduino-decision-box-V20-Attiny85/

Author:Victor8o5

Youtube channel.
I'm an electronic engineering student. I don't usually have much spare time but I like to complete random projects to keep myself entertained. I hope you like
them! P.D: Sorry about possible grammar errors, I'm not a native English speaker.

Intro: Arduino decision box V2.0 (Attiny85)


After seeing my first Attiny85 based "Decision box" had become quite popular I decided to make a second version with more improvements using common materials so
everyone can build it.
The main difference between the first and second version are the materials they're made of, while the first box was made out of wood, this version has two perforated
boards stacked together with hex spacers and screws, and connected by pin headers and connectors. This makes it more modular, robust and easy to assemble.
Another difference are the LED's, in this version I used three LEDs instead of a single common cathode red-green LED, not just because I had more space to put them,
but also because it has allowed me to be more creative when making the program.

Step 1: Materials:
Attiny85
8pin chip socket
Coin battery holder
CR2032 Coin battery
Perforated board
Pushbutton
Hex spacers (around 2cm, 3/4 inch)
8 screws for the spacers
Long pin headers
Connectors for the pin headers
Red, green and yellow LEDs
Copper wire
120Ohm resistor
10kOhm resistor
You'll also need a soldering iron.

Step 2: The circuit:


The circuit is quite simple, but assembling it together in two different planes can be a bit tricky.
This circuit runs on 1mA when in idle and around 5-6mA when using the LEDs, so assuming the coin battery has a capacity of 200mAh, it should run for a week before
draining the battery in case its left on.

http://www.instructables.com/id/Arduino-decision-box-V20-Attiny85/

Step 3: Assembling the cube.


Start by cutting two squares of 11x11 pads, we need an odd number of pads because components like the button occupy an odd number of them, and by making this we
make sure they are symmetrical respect to the center line.I also bent the pins of the chip socket so it could fit in a 4x3 group, instead of the usual 4x4, this way it's
properly aligned and vertical. You can also connect it in an horizontal way, but making the connections could be harder. If you find hard to do this you can always use a
13x13 boards, or 12x12, if your button occupies 4x4 pads.
Make a hole at the center of the 2x2 pad groups located at the edges, the hex spacers will be placed there, the holes need to be big enough for the screws to fit in. Use a
precision tool for better accuracy.
Once the holes are made put the components on the board. I've traced the circuit with colors according to the schematic so you don't get lost when soldering it.
Notice that there is solder under the blue resistor (10kOhms) connecting the LEDs and the chip to ground.
For the main switch I used a a pair of pin headers and a bridge connector from a computer, you can use a small though-hole switch or even a tilt switch.

http://www.instructables.com/id/Arduino-decision-box-V20-Attiny85/

Step 4: Connectors
To assemble the pin headers and connectors that will join the two boards, solder a 5 connector row between two hex spacers, using the pads at the edge, remember to
separate them into positive and negative. Once the connector is soldered, cut the long pin headers to an appropriate length so they can be fully inserted leaving just a
small gap between the plastic holding the pins together and the upper board, then solder them as shown in the picture. It's quite tricky, but I haven't found any other way
to overcome this.

Step 5: Uploading the code


As always remember that to upload the code to your Attiny85 you must go to >Tools>Programmer>Arduino as ISP and Tools>Boards>Attiny85 1MHz clock.
You can check other instructables on how to program an attiny85 if you haven't worked with them yet.

File Downloads

random_final.ino (3 KB)
[NOTE: When saving, if you see .tmp as the file ext, rename it to 'random_final.ino']

Step 6: Customization and probabilities


The yellow LED, which wasn't enabled in the previous version, can now be used, and interpreted as a "maybe". This can be undone changing the program and removing
the LED, you could even add a button pattern recognition function or an extra button to disable and enable it.
You can also change the probabilities, for example, you can set red and green (no and yes) to 40%, and keep the yellow (maybe) at 20%. To do this, simply expand the
range of the elements in the random function and include them in the statements as shown as shown in the picture.
The random function will output anything from 0 to the second variable minus 1, meaning that if we introduce 3, the results can be 0, 1, or 2 (red, yellow, green). By
introducing 5 as the second variable we can get 0, 1, 2, 3 or 4. We can use an "if" function so 0 or 1 are recognized as red (40% chance), 2 yellow (20% chance) and 3 or
4 green (40% chance).
To compare two variables at a time you can use " || " (Alt+124), this is OR, and means that if one OR the other occurs, the statements will be executed.

http://www.instructables.com/id/Arduino-decision-box-V20-Attiny85/

Step 7: ???
Since easter is just around the corner I've added an easter egg to the program. And of course I won't reveal what it is or does, if you want to find out you'll have to build
the circuit, you could also analyze the program, but that would be cheating. I'll just say this easter egg is quite more elaborated than the random part itself, and you'll
probably end using it more too.

http://www.instructables.com/id/Arduino-decision-box-V20-Attiny85/

Step 8: Thanks for watching!

Related Instructables

Chipper Board ATtiny


Programming
Shield by
Hammock Boy

Program an
ATtiny with
Arduino by
randofo

Self-contained
16-Digit display
- Arduino &
Attiny85 by
Panici

Arduino ISP to
ATTiny85 by
baelza.bubba

Arduino
decision box.
(Attiny85) by
Victor8o5

Simplest and
Cheapest
Arduino by
smching

Advertisements

Comments
22 comments Add Comment

nqtronix says:

Mar 14, 2015. 10:51 AM REPLY

This is actually a really nice remake of the old version. The barebone construction was a good idea.
I'm not sure if the arduino libary supports that, but the attiny85 supports different sleep modes to reduce the current consumption to just about 2 uA. This
results in a standby battery time of mor than 11 years from a CR2032 eliminating the need of an on/off switch. The device can then simply be woken up by
any pin change interupt such as pressing the button.
If you want to I can write the program in native C, it shouldn't take too long. :)

Victor8o5 says:

Mar 14, 2015. 12:12 PM REPLY


Yes, I've heard about the power saving modes of the Attiny, however I haven't been able to implement it because I haven't done enough research. I'll try
to update the program as soon as I can If I can come up with it.
Thanks for your suggestion, I don't want to bother you, although if you are going to write and improve the program anyway I would be very grateful if you
posted it here.

nqtronix says:

Mar 15, 2015. 6:28 AM REPLY

I'm working on it right now ;)

Victor8o5 says:

Mar 15, 2015. 12:35 PM REPLY

I've just re-uploaded the program because I found some minor bugs, it's fixed now.

nqtronix says:

Mar 15, 2015. 2:33 PM REPLY


I've written the code from scretch anyway to optimize the power consumption as far as possible. The code also includes a "push button pull
down resistor present" detection, if there's none he internal pullup will be used. The "randomness" is now truely randon utilizing the noise
generated by the red LED. Right now my code doesn't include the easteregg, and I don't plan to implement that.
I'm still struggeling a bit with staeting the sleep mode from an interrupt, it somhow puts the attiny in an infinite loop locking it. I'll focus on that

http://www.instructables.com/id/Arduino-decision-box-V20-Attiny85/

tomorrow.
Would you mind if I'd create a seperate instructable for my setup? I'd link back to this page for all the hardware aspects, if that'd be ok.

querry43 says:

Mar 15, 2015. 5:48 PM REPLY


Yea, it's quite difficult to get it right. I've got a toy on my desk that does just about what you need (wakeup interrupts on an attiny85).
Here's a snippet of the code. It looks like I'm using a library called Sleepy to do the work.
#include <Ports.h>
#include <avr/interrupt.h>
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif
void setup() {
pinMode(pinLed, OUTPUT);
installInterrupt();
}
void loop() {
// do some work here
// maybe turn on a led and delay() a bit
Sleepy::powerDown();
}
void installInterrupt() {
sbi(PCMSK, pinButton);
sbi(GIMSK, PCIE);
}
ISR(PCINT0_vect) {
// wakeup
}

nqtronix says:

Mar 16, 2015. 11:52 AM REPLY


Honestly that didn't help me very much, I'm not using the Arduino code, but native C. However I tried a few things, now all major code
is in the main loop and it homehow works. My guess is that it doesn't handle sleepmodes within an interrupt very well.
Thanks for all your efforts :)

querry43 says:

Mar 16, 2015. 7:08 PM REPLY


Ah, bare C might be a bit harder :). It is best practice not to do any work in the interrupt because they are so unpredictable. For
instance, it might fire more than once. If you do have to update a counter or something, make sure the variable is marked volatile. I
don't know for sure that this is necessary on arduino, but for other architectures, it will prevent the compiler from making
optimizations that break things.

Victor8o5 says:

Mar 15, 2015. 4:57 PM REPLY

Of course I don't mind, thanks for all the work you're doing.

Victor8o5 says:

Mar 15, 2015. 8:06 AM REPLY

Thanks! :)

BiGrAyMaN22 says:
I like to see projects like this. It seems very well-written as well as well-designed. I hope to see more projects like this.

http://www.instructables.com/id/Arduino-decision-box-V20-Attiny85/

Mar 15, 2015. 8:53 PM REPLY

ibenkos says:

Mar 15, 2015. 2:45 PM REPLY

nice :)

Gursimran Singh 425 says:

Mar 15, 2015. 2:00 AM REPLY

nice job is it necessary to use only 10k and 120 ohm resistors

nqtronix says:

Mar 15, 2015. 2:54 AM REPLY


The 10k resistor can be left completely away if you enable the internal pull-ups of the attiny (I don't know how or if thats possible with arduino) or or
replace with any value in the range of 3.3k to 100k.
The 120ohm resistor can be replaced with any value from 68 ohms up, however lower values increase the power consumption and higher values (> 1k)
significantly decrease the brightness.
Hope that was helpfull :)

Victor8o5 says:

Mar 15, 2015. 6:25 AM REPLY

That's right, the 10k resistor is used to debounce the button, the
120Ohm resistor is used to regulate the brightness and energy
consumption.

Ben1894 says:

Mar 14, 2015. 2:31 PM REPLY


I like the design of this. I made your first one but I made it with a rgb led and I modified the code so I have definitely yes and no and ask again

woodworker10101 says:

Mar 14, 2015. 12:46 PM REPLY

very cool indeed

UlrichW1 says:

Mar 14, 2015. 11:48 AM REPLY

Hi, the comment in the yellow statement in the screenshot is "green"...


I think it should be "yellow" (no function, only easier for code beginner)

Victor8o5 says:

Mar 14, 2015. 12:15 PM REPLY


Thanks, I must have copy-pasted it without changing the color name. I'm going to change it and upload the modified program.

tomatoskins says:

Mar 14, 2015. 10:01 AM REPLY

I really like how it looks as well! So great!

liquidhandwash says:

Mar 14, 2015. 3:39 AM REPLY

it kinda cool looking, nice job

Victor8o5 says:
Thanks!

http://www.instructables.com/id/Arduino-decision-box-V20-Attiny85/

Mar 14, 2015. 4:56 AM REPLY

You might also like