Introduction: Safety Armband (with ATtiny85 and WS2812)

I decided to participate in the wearables contest with this project as it shows again, if necessary, how much I like the ATtiny85 microcontroller.


This little computer reminds me of the time when I started programming on ZX81 in BASIC and assembler. How much I struggled with a program, how much work I could do to overcome the limitations of memory and computing power! So every time I work with ATtiny85 for me it's a nice return in time 😊

Now I would like to introduce you to a device that can be used as a safety bracelet to warn others around about your presence, signal in case of a danger or can be used even as a survival bracelet as I saw it called nowadays. The materials, the components used are few and cheap, the electronic part is very simple and the actual construction is within reach of anyone.

How the bracelet works ...!

If you are a cycling enthusiast, if you are jogging or accompanying a group of children on the side of a busy road, then you know how important it is to signal your presence to other traffic participants. If you get stuck on the road because of a malfunction of your car or you may want to signal a danger to other drivers the bracelet can even be used even as a beacon. Of course, its use is subject to legal rules, for example in Spain it is mandatory, in other countries is optional, in my country it is only tolerated. Maybe it would not be silly to be mandatory in other countries too. However, if you use the bracelet in this way you should be interested in the regulations in your area.

Basically the bracelet is made up of a series of LEDs controlled by a microcontroller that are lit with a certain color with a shifting effect (you can see the effect in the video at the end of the article) The power source is a 300mAh Lipo battery, the operating autonomy of the bracelet depends to a large extent on the dynamics of the LED's operation (the duration of LED lit-unlit time) and on the luminous intensity of the LEDs. The color used can be green (day), orange or yellow (dusk) or red (night) - more about this here. If you use the device as a survival bracelet the color used depends on the weather conditions. For example, if the atmosphere is clear then the red color is most visible at night. However if it is fog or rain then the yellow color is the most appropriate. In the source code (see the software step) I have proposed a way of working and colors that could be used but these can be changed easily if you have other requirements.

Step 1: Material and Components

⯈ Pretty long piece of an used leather belt - I used a 43 cm piece of a belt with a 3cm width and 3mm thickness;

Transparent heat shrinking tube - Pretty expensive if you want something of quality, you can find it called sometimes as "heat shrink wrap for batteries", I used a large one for the electronics and a narrow one for the ledstrip, choose a dimension which shrinks for a good fit (depends on materials used) not too loose but neither too tight. Also take care of what material is made of. Those made with polyolefin are better because they have lower heating temperature, lower chance of overheating the electronic parts;

⯈ A piece of Velcro tape - I used a pair of 2cm width;

WS2812 ledstrip - 18 leds - I used a piece of a 60 led/m ledstrip (left from my previous project - Game of Life Coffee Table 😊

ATtiny85-10PU controller - The heart of everything :) - The 20PU variant can also be used but for low voltage level supply (cca 2.7V) do not exceed the 8MHz clock;

300mm LiPo battery - Other battery with a greater capacity could be used, this was very cheap;

Switch Buttons - pretty standard ones;

n-Channel MOSFET transistor - Based on some datasheets I used AOI4184 from AOS;

⯈ Resistors - 2x10kΩ and a 680Ω resistor;

Prototyping board - for easy and fast soldering of the component;

female DC plug - I used a standard DC plug with cable, for waterproofing some caps can be used (I did not have ones unfortunately);

⯈ 5v Power supply and a Battery charger module TP4056 - I used this to recharge the LiPo Battery;

Step 2: Electronics

I have attached the electronic scheme above. As you can see, it is very simple.

The heart of the device is an ATtiny85 microcontroller to which I connected the RGB LEDstrip via a n-channel MOSFET transistor. I chose to use this transistor for the following three reasons:

  • The transistor provides the power supply of the LEDstrip because the output pin of the microcontroller cannot supply the necessary current, at maximum intensity, white color, the consumption can reach over 1A ! Much above 40mA which can be provided by the digital output;
  • When entering the deep sleep the transistor completely turns off the power supply of the LEDs (as a relay) otherwise the LEDs would consume current even when they are off, for example 18 LEDs consume about 17mA even if they "display" the black color :)
  • MOSFET transistors can be chosen to have very low internal resistance at the opening so that the voltage drop on it is as small as possible.

I chose a MOSFET AOI4184 but other types can be used if they are the so-called logical level MOSFET (some articles to read hereand here). I also relied on choosing this transistor using the information from the respective articles, and the resistors I chose trough several trials :)

The data input of the LED string is connected to the digital pin 2 of ATtiny85 (physical pin 7). To avoid parasitic/backfeed supply the pin must be set to input mode (high impedance) read here.

To the reset (pin 1) and the digital pin 3 (physical pin 2) the touch buttons are connected. With the SW1 button connected to the reset, the program is restarted and with SW2, the one connected to the PB3, the colors and the operation mode of the bracelet are selected (more in the next step - software). As you can see in the electronic diagram at the reset pin you can put a pull-up resistor if you use the bracelet in an electrical noisy environment. Normally this resistance is not necessary but to avoid accidental resets it is still preferable to use it.

The 300 mAh battery powers the entire assembly and in parallel with is connected a cable with which the battery can be charged. The charger is a TP4506 module. Be careful! Do not start the bracelet while charging. There is a consumption that TP4506 interprets as being necessary to charge the battery and the phenomenon of overcharging may appear, which can damage the battery (more here) or you can use the second version of TP4506 module which is said to accept the battery and the charging at the same time (more here).

The practical assembly was done on two pieces of prototyping plates, you can see in the photos how they came out and how I made the connections between the plates. As the electronic part will be waterproofed, I did not provide outputs for subsequent programming of ATtiny85 so I soldered it directly on the proto board.

Step 3: Software

Something about the operation of the program ...

In the main loop, the status of the SW2 button is checked:

⯈ If SW2 is not pushed then the status of the battery is displayed (the LED in the 10th position will have the color green > orange > yellow > red depending on the supply voltage), the operating mode is displayed by a blue LED between the second position and the 9th position and (in the first position) the color used in the display during bracelet operation is displayed;

⯈ If the SW2 button is not pressed for 5 seconds, ATtiny85 enters the deep sleep, from which it is awakened only by pressing the SW1 button (reset);

⯈ At simple click the program advances through the operating modes of the bracelet (8 modes), we can see this happening when the blue led is changing the position on the ledstrip

⯈ At double click, the color used in the effect of moving the LEDs is changing (the color is displayed in the first position of the ledstrip)

⯈ When the click is long, the display will actually start with the color and mode selected.

In the main display() function there are two for-next cycles that display the color chosen from the first position to the 18th position and then vice versa. Only one led is lit during cycles and between ignitions there is a pause in which ATtiny85 goes into sleep but the string of LEDs remains powered. This pause is controlled by the mSpeed variable (between 1 ms and 40 ms), the lower the value, the higher the display speed and the total actual display time is less. After the completion of the two cycles, the micro controller is put in sleep again, and the MOSFET will turn of the power of the ledstrip, this pause is controlled by the variable mPause and is 250 ms and 750 ms.

Considering the values of the mSpeed and mPause variables, the order of the operating modes is from the most economical (mSpeed - 1 ms, mPause - 750 ms) to the least economical (mSpeed - 40 ms, mPause - 250 ms).

What is the most economical? We want the average consumption to be as small as possible and the operating time of the bracelet to be long as possible.

Let's calculate in these two marginal cases the battery life:

1. mSpeed - 1 ms, mPause - 750 ms

As you can see from the scope's screenshot the time between two consecutive deep sleeps is 1634 ms.

In this period there is a 750 ms sleep (mPause) when the current consumption is 5.48 uA, 35 periods of 1 ms when the current consumption is 15 mA, in the rest of 849 ms period is 21 mA.

So the average current for the 1634ms period is (750*0.00548+35*15+849*21)/1634 = 11.235 mA

If we chose the discharge safety to be 75% (minimum power voltage 3v) the theoretical battery life is

(300*(1-75/100))/11.235 = 6.68 hours

2. mSpeed - 40ms, mPause - 250ms

Whole period - 2484 ms

250 ms sleep with 5.48 uA, 35 periods of 50ms with 15 mA and 734 ms with 21 mA

Average current - (250*0.00548+35*50*15+734*21)/2484 = 16.773 mA

The theoretical battery life will be (300*(1-75/100))/16.773 = 4.47 hours

Even if the theoretical calculations indicate a relatively short working time, in practice I got 100% higher operating times, around 12 hours for the operating mode 1, especially because the assembly works well even at voltages below 3v, to my surprise the LED strip went well at the supply voltage of 2.6v (!)

Of course, you can use other values of mSpeed and mPause, maybe even different display effects for better visibility or for better running time.

You can find the source code and download it from github.

About Arduino IDE configuration and the ATtiny85 programming you can read in my article here.

Step 4: Construction

The steps for making the safety bracelet are (see also the photos above):

⯈ Cut the necessary piece (approx. 34cm) from the leather belt;

⯈ Slightly cut the ends with a cutter;

⯈ Drill a hole in the belt for the ledstrip connections;

⯈ Pull the wires trough the hole and solder them to the ledstrip;

⯈ Put the large heat shrink tube over the electronics then heat it to shrink,

⯈ Put the narrow heat shrink tube over the ledstrip and heat it with a heat gun;

⯈ Glue the ledstrip to the belt (with a hot glue gun);

⯈ Glue the electronics also;

⯈ Make holes for the touch buttons and apply above them a piece of large heat shrink tube, heat it;

⯈ Fix the DC jack to the belt with a piece of heat shrink tube also;

⯈ Glue the Velcro tape to the end of the strap with a good adhesive (for better bond it can also be sewed to the belt);


Step 5: Operation and Some Conclusions

You can see in the video below how the bracelet works... (I hope it will clarify some things 😊)

And in the video below how the bracelet looks like during actual use...

Some thoughts...

⯈ As you can see in the second video, the armband is not too noticeable in the daylight, but in dusk and in the night is quite visible;

⯈ Even though addressable LED strings could be considered non energy-efficient devices, you can see that they can also be used in applications where energy saving is required;

⯈ You can use a larger battery, they are not much bigger in physical size but the actual operating time can be greatly increased (you can use the example in step - software - to calculate 😊)

⯈ Simple construction, simple electronics, it can offer much satisfaction even for those with low experience in the field of micro controllers, maybe you will build this device too.

I hope you liked my article and I hope you will support my participation in the wearables contest.

Wearables Contest

Runner Up in the
Wearables Contest