555 timer LED flasher
The most famous chip in electronics, blinking an LED about once a second.
Shop by category
Shop all componentsEEPROM keeps data with no power, but each cell takes only about a million writes. The AT24C128 is a 128 Kbit (16 KB) I2C EEPROM in a DIP-8 package, so it plugs into a breadboard. The counter keeps the live count in RAM and saves it every 10 counts into one of 64 rotating slots with a sequence number; at start-up the Nano reads all slots and continues from the newest, so no single cell wears out.
Tick anything you already have and the total updates.
Follow the colours: red is power, dark grey is ground, blue is a signal.
5 V adapter or USB; the count survives power cuts.
safe_counter.inoVerify & upload in Electrolark#include <Adafruit_SSD1306.h>
Adafruit_SSD1306 oled(128, 64, &Wire, -1);
void big(const char* top, float value, int dp, const char* unit) {
oled.clearDisplay(); oled.setTextColor(WHITE);
oled.setTextSize(1); oled.setCursor(0, 0); oled.print(top);
oled.setTextSize(3); oled.setCursor(0, 20); oled.print(value, dp);
oled.setTextSize(1); oled.print(" "); oled.print(unit);
oled.display();
}
#include <Wire.h>
const int EE = 0x50, SLOTS = 64, SLOT_SIZE = 8, SAVE_EVERY = 10;
uint32_t count = 0, seq = 0;
int slot = 0;
void eeWrite(uint16_t addr, const uint8_t* d, int n) {
Wire.beginTransmission(EE); Wire.write(addr >> 8); Wire.write(addr & 0xFF);
Wire.write(d, n); Wire.endTransmission(); delay(6); // 5 ms write time
}
void eeRead(uint16_t addr, uint8_t* d, int n) {
Wire.beginTransmission(EE); Wire.write(addr >> 8); Wire.write(addr & 0xFF); Wire.endTransmission();
Wire.requestFrom(EE, n); for (int i = 0; i < n; i++) d[i] = Wire.read();
}
void save() {
slot = (slot + 1) % SLOTS; seq++;
uint32_t rec[2] = {seq, count};
eeWrite(slot * SLOT_SIZE, (uint8_t*)rec, 8);
}
void setup() {
Wire.begin(); pinMode(2, INPUT_PULLUP);
oled.begin(SSD1306_SWITCHCAPVCC, 0x3C);
for (int i = 0; i < SLOTS; i++) { // find the newest record
uint32_t rec[2]; eeRead(i * SLOT_SIZE, (uint8_t*)rec, 8);
if (rec[0] != 0xFFFFFFFF && rec[0] >= seq) { seq = rec[0]; count = rec[1]; slot = i; }
}
}
void loop() {
static bool last = HIGH;
bool b = digitalRead(2);
if (last == HIGH && b == LOW) { count++; if (count % SAVE_EVERY == 0) save(); delay(30); }
last = b;
big("Cycles", count, 0, "");
}
WP is high or the address pins float; tie them to GND.
A fresh EEPROM may hold old data; clear it once by writing 0xFF to all slots.
Check SDA/SCL and the pull-ups.
64 slots, a save every 10 counts and a million writes per cell give hundreds of millions of counts.
It works too (100,000 writes per cell); an external chip is larger and can be swapped.
Yes, with a capacitor and a voltage-detect pin, but slots are simpler.
7 parts: AT24C128 128 Kbit I2C EEPROM (DIP-8), Generic Nano CH340 Development Board (Soldered), 0.96" OLED Display 128x64, Tactile Push Button Switch, Resistor Assortment Kit (30 Values), Solderless Breadboard and Dupont Jumper Wires (40 pcs). On this page you can tick the parts you already have and add only the rest to your cart.
No. This page has the complete, tested code (safe_counter.ino).
About ₹492 for the parts at the prices on this page. Quantity price breaks lower the cost when you build several.
I2C EEPROM read and write with page addressing; Wear levelling across slots; Recovering state after a power cut.
The most famous chip in electronics, blinking an LED about once a second.
Press once and the light stays on for about 11 seconds, then goes off by itself.
A running light like the one on Knight Rider, made from two classic chips.
Touch two wires with a fingertip and an LED lights: skin current switches a transistor pair.
Lessons are free to read. Maker (₹499/month) and Pro add quizzes, worked problems and certificates, paid with your Geekobot account. See plans
Learning project. Check every circuit and the datasheet of each part before you power it up.