What is it?

This small project is a battery powered click logger. You get visual indication and microSD card log for your clicks. It's powered using 2 x CR2032 coin lithium batteries in series. They should last a few hours. Of course, you can use other types of batteries as well but we just had these lying around and wanted to use them in something cool :) 


  • 1 x H05R00 Hexabitz Micro-SD Memory Card Module
  • 1 x H13R10 Hexabitz CR2032 Coin-cell Battery Holder Module (2 in series)
  • 1 x TL59FF160Q Momentary tactile push button

Estimated hardware build time: 5 minutes 

Estimated software development time: 5 minutes

Have suggestions about how to improve our demo projects? Feel free to comment below or send us a private message!

Code Description:

The code for this project is very simple. We define a button and an event-based log. The button has two event callbacks: one that triggers on clicks and another on a 3-second press. The click callback increments a variable in RAM and blinks indicator LED on each click. Every 10 counts, the LED gives a longer 1-second blink. 

Define the button and link it to its callbacks like this:

AddPortButton(MOMENTARY_NO, P1);                // Define a button connected to port P1
SetButtonEvents(P1, 1, 0, 3, 0, 0, 0, 0, 0);    // Activate a click event and a pressed_for_x event for 3 seconds

Check the BOS factsheet for documentation on external buttons/switches API. Create an event-based log and log two variables, the button state and the counter variable:

if ( CreateLog("Click Logger", EVENT, 10, FMT_TAB, FMT_SAMPLE, "Sample @ 10Hz") == H05R0_OK )
    LogVar("Click Logger", PORT_BUTTON, P1, "Logger");
    LogVar("Click Logger", MEMORY_DATA_UINT32, (uint32_t)&counter, "Counter");                
    // Do not reset button state after writing the log since we need it to blink LED as well!
    needToDelayButtonStateReset = true;

Logging starts at first button click and is stopped when the button is pressed for 3 seconds in the PressedForX callback. Button events are also disabled there so you don't see any more logs or LED flashes. Check H05R00 module factsheet for detailed documentation on logging API.

void buttonClickedCallback(uint8_t port)
    if (counter == 1)    StartLog("Click Logger");
    if ( counter%10 == 0 ) {
    } else {

    needToDelayButtonStateReset = false;        // Reset button state now

void buttonPressedForXCallback(uint8_t port, uint8_t eventType)
    // The first PressedForX event we defined in SetButtonEvents was called    
    if (eventType == 1)
        StopLog("Click Logger");
        SetButtonEvents(P1, 0, 0, 0, 0, 0, 0, 0, 0);        
        IND_blink(400); Delay_ms(400); IND_blink(400);

    needToDelayButtonStateReset = false;        // Reset button state now

Note how we used needToDelayButtonStateReset flag to log the button state and at the same time use it to blink the indicator LED. With this variable set to false, the button state will be reset automatically after being logged. Here's how a sample-based log looks like:

You can also log time stamps by replacing the index column format parameter with FMT_TIME as follows:

if ( CreateLog("Click Logger", EVENT, 10, FMT_TAB, FMT_TIME, "Sample @ 10Hz") == H05R0_OK )

And you get this log:

Example log files are attached to this project. Note that it's better to load the firmware using power from USB cable connection without batteries (to avoid power confusion and reset states). Once done you can insert the batteries and then remove the USB cable. 

Check this video for the Click Logger...

Read more »