Daily Streak Tracker for Arduino Project Habits
In this article
Yes, you can build a daily streak tracker for your Arduino project habits, and it works best as a simple counter that logs each day you complete a habit. The core idea is to store the last completion date and a streak count in the Arduino's EEPROM, so the streak survives power loss. This page shows you how to design, code, and use one, plus what to watch out for.
What a Streak Tracker Needs to Do
A streak tracker has three jobs: record that you did the habit today, count consecutive days, and reset the count if you miss a day. The Arduino can handle all three with a real-time clock (RTC) module, a button, and a small display. The RTC keeps track of the date even when the Arduino is off, so you can compare dates accurately.
You do not need internet or a computer. The tracker runs on its own, and you press a button each day when you finish your habit. The display shows your current streak and maybe a simple message like "Done!" or "Keep going."
Hardware You Will Need
For a basic tracker, gather these parts:
- Arduino board (Uno, Nano, or similar)
- Real-time clock module (DS3231 or DS1307)
- One push button
- One 10kΩ resistor (for the button, optional if using internal pull-up)
- OLED or LCD display (optional but helpful)
- Breadboard and jumper wires
- Coin cell battery for the RTC (so it keeps time when unplugged)
You can skip the display and use the serial monitor on your computer to see the streak, but a small OLED makes it a standalone device.
How the Code Works
The logic is straightforward. On startup, read the stored last date and streak count from EEPROM. Then check the current date from the RTC. If the current date equals the last date, do nothing (already counted today). If the current date is exactly one day after the last date, increment the streak and update the last date. If the current date is more than one day after, reset the streak to 1 and update the last date.
Here is a pseudocode outline:
- Initialize RTC and set the time if needed.
- Read
lastDateandstreakfrom EEPROM. - Get today's date from RTC.
- When the button is pressed:
- If today is the same as
lastDate, do nothing. - If today is one day after
lastDate, increase streak by 1. - If today is more than one day after, set streak to 1.
- Save
lastDateandstreakto EEPROM. - Show streak on display.
- If today is the same as
Use the DateTime class from the RTClib library to compare dates. Store the date as a single number, like YYYYMMDD, to make comparison easy.
Setting Up the RTC and EEPROM
First, you need to set the RTC to the current time once. You can do this with a simple sketch that reads the computer's time via serial or manually sets it. After that, the RTC keeps running on its battery.
For EEPROM, the Arduino Uno has 1024 bytes. You only need two integers (4 bytes) for the date and streak. Write them at addresses 0 and 4. Use EEPROM.put() and EEPROM.get() to store and read them. Be careful not to write EEPROM too often; it has a limited write cycle (about 100,000), so only write when the button is pressed.
Rule of Thumb: One Button Press per Day
The simplest rule is: press the button once after you complete your habit. If you press it twice, the tracker ignores the second press because the date hasn't changed. If you forget a day, the tracker resets the streak to 1 the next time you press.
This works for any habit you do daily, like reading, meditating, or exercising. You can also use it for a project habit, like working on your Arduino for at least 15 minutes.
Common Misconception: Streak Resets at Midnight
Many people think a streak resets if you don't press the button before midnight. Actually, the tracker only checks when you press the button. If you press at 11:59 PM and then again at 12:01 AM, that counts as two separate days. If you press at 11:59 PM and then not until 11:00 PM the next day, it's still one day apart, so the streak continues. The tracker doesn't care about the time, only the date.
This means you can press the button late at night and still keep your streak, as long as you press once per calendar day. Some people prefer to press in the morning for the previous day, but that's your choice.
Testing and Calibrating Your Tracker
Before relying on it, test the tracker for a few days. Set the RTC to a known date, press the button, and check the streak. Then change the RTC date forward by one day (you can temporarily disconnect the battery and set it manually) and press again. The streak should increase. Then jump two days forward and press; the streak should reset to 1.
You can also add a small LED that blinks when the button is pressed, so you get visual feedback. And if you use a display, show the streak and the last date.
Making It a Habit
A tracker only works if you use it. Place it somewhere visible, like your desk or nightstand. Press the button at the same time each day, right after you finish the habit. If you miss a day, don't get discouraged; just start a new streak. The goal is to build a habit, not to have a perfect record.
You can also add a small note in your code to customize the habit name. For example, change the display text to "Reading" or "Yoga". This makes the tracker feel personal.
Expanding Your Tracker
Once the basic tracker works, you can add features:
- A buzzer to beep when you press the button.
- A second button to undo a mistaken press (though you'd need to store the previous streak).
- A small speaker to play a tone when you reach a milestone like 7 or 30 days.
- An SD card to log every press with a timestamp, so you can review your history.
These additions are optional and depend on your comfort with wiring and code.
Safety and Maintenance
This project uses low voltage (5V), so it's safe. But always unplug the Arduino when changing wiring. The RTC battery lasts about 2-3 years; replace it when the time starts drifting. EEPROM writes are fine for daily use; 100,000 writes is about 273 years.
If you use a button with a pull-up resistor, connect one side to ground and the other to a digital pin. Use the internal pull-up to avoid an external resistor, but then the button connects to ground and the pin reads HIGH when not pressed.
With this tracker, you'll have a physical reminder of your habit streak. It's a small project that can make a real difference in your daily routine.