The Habit Tracker
March 2020
A microcontroller-based device for building habits by tracking progress across multiple goals with day counters.
Overview
The Habit Tracker is a small embedded device I built to keep track of progress toward several habits. The idea came after reading Atomic Habits by James Clear,
“Recording your last action creates a trigger that can initiate your next one. Habit tracking naturally builds a series of visual cues like the streak of X's on your calendar or the list of meals in your food log. When you look at the calendar and see your streak, you'll be reminded to act again . . . The mere act of tracking a behavior can spark the urge to change it.”
— James Clear
Instead of using a phone or an app, I wanted a simple physical device that could sit on a desk and provide a quick way to record progress. Nothing fancy. Each habit has its own day counter, and the values are stored in nonvolatile memory so they are retained when the device is powered off.
The project involved circuit design, embedded firmware, PCB assembly, user interface design, CAD, and 3D printing.
Hardware and User Interface
The system is built around an ATmega328P microcontroller and a 16×2 character LCD connected through I²C. Four push buttons provide the complete user interface.
The left and right buttons move between the different habits, while the up and down buttons increase or decrease the day counter for the currently selected habit. The menu wraps around in both directions, so moving past the first or last entry automatically continues from the opposite end.
In my case, some of the habits I configured in firmware to track were:
- Wake up by 5:05
- Study Math
- Learn FreeCAD
- Read a book
- Study Programming
Each habit is displayed on the first row of the LCD, while its current day count is shown on the second row.
Firmware and Data Storage
The firmware organizes the habit names and their corresponding counters using arrays, allowing the same menu and counter logic to be reused for every habit instead of implementing separate code for each one.
Push-button inputs are debounced in software using millis(). This allows the controller to reject the short electrical transitions produced when a mechanical button is pressed without relying on long blocking delays in the main program loop.
Whenever a counter is changed, the updated array is stored in the ATmega328P's internal EEPROM. During startup, the firmware reads the saved values back from EEPROM before displaying the first habit. This allows the tracker to retain its progress even after power is removed.
The counters can also be decreased if a correction is needed, but the firmware prevents a value from going below zero.
When powered on, the LCD first displays a short startup screen showing the name "The Habit Tracker" before entering the main screen.
Enclosure and Assembly
A custom enclosure was designed in FreeCAD and 3D printed to hold the electronics, LCD, and control buttons in a compact desktop unit.
The front panel provides access to the display and four navigation buttons, allowing the tracker to be operated without opening the enclosure.
The electronics and mechanical design were developed together so the PCB, display, buttons, and enclosure could be assembled into a single self-contained device.
Results
The completed Habit Tracker provided a simple physical interface for monitoring several habits without relying on a phone or computer. The menu buttons made it possible to quickly move between habits and update their counters, while EEPROM storage preserved the data between uses.