LM317 variable power supply
Turn a 12 V adapter into an adjustable 1.25–10 V supply for your experiments.
Shop by category
Shop all componentsWriting to EEPROM on every change wears it out, but waiting means losing data when the plug is pulled. The trick is to watch the supply and save only when it starts to fall. A supercapacitor charged through an anti-reverse diode module powers the Nano for a short time after the 5 V input disappears. The diode stops the capacitor from feeding back into the dead supply, and a divider on A0 tells the Nano that the input has gone.
Supercapacitors can deliver a big current when shorted; do not touch both legs with metal.
Tick anything you already have and the total updates.
Follow the colours: red is power, dark grey is ground, blue is a signal.
A 5 V USB supply into the diode module. Do not power the Nano by its own USB port while testing, or the capacitor is bypassed.
power_cut_saver.inoVerify & upload in Electrolark#include <EEPROM.h>
unsigned long count = 0;
bool saved = false;
void setup() {
pinMode(2, INPUT_PULLUP);
pinMode(LED_BUILTIN, OUTPUT);
Serial.begin(9600);
EEPROM.get(0, count);
if (count == 0xFFFFFFFF) count = 0; // fresh EEPROM
Serial.print("Restored count: "); Serial.println(count);
}
void loop() {
int supply = analogRead(A0); // about 512 while the input is 5 V
if (supply < 350 && !saved) { // input dropping: save now on capacitor power
EEPROM.put(0, count);
saved = true;
digitalWrite(LED_BUILTIN, HIGH);
}
if (supply > 450) { saved = false; digitalWrite(LED_BUILTIN, LOW); }
static bool last = HIGH;
bool now = digitalRead(2);
if (last == HIGH && now == LOW) { count++; Serial.println(count); delay(30); }
last = now;
}
The capacitor is too small or connected before the diode; it must sit on the diode output.
Lower the 350 threshold or check the divider values.
It is connected backwards or rated below 5 V; unplug at once and check.
Depends on the capacitance: a 1 F capacitor holds a bare Nano for several seconds, far more than the few milliseconds a save needs.
EEPROM cells survive about 100,000 writes; saving only at power cuts makes them last for years.
Yes, but a supercapacitor never needs changing and charges in seconds.
7 parts: Super Capacitor 5.5V 1.5F, Anti-Reverse Diode Module 60V 10A (Dual SS56), Generic Nano CH340 Development Board (Soldered), Tactile Push Button Switch, 2 × 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 (power_cut_saver.ino).
About ₹429 for the parts at the prices on this page. Quantity price breaks lower the cost when you build several.
How a supercapacitor stores energy; Why a diode is needed to stop back-feeding; Saving to EEPROM only when needed.
Supercapacitors can deliver a big current when shorted; do not touch both legs with metal.
Turn a 12 V adapter into an adjustable 1.25–10 V supply for your experiments.
Build your own USB power bank and learn how lithium charging works.
Free power for outdoor sensors: sunlight in, 5 V USB out.
Beeps when the mains goes off at night, so the fridge and the alarm clock do not quietly die.
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.