Build it step by step
0 of 9 doneSet the boost converter
Connect a charged cell to the MT3608 input and turn the screw until the output reads 5.0 V.
Wire the charger and cell
Adapter to TP4056 IN, the holder to B+ and B-, and put in a charged 18650.
Wire the Nano power
TP4056 OUT to the MT3608 input, MT3608 output to the Nano 5V and GND.
Wire the SIM800L
VCC and GND from TP4056 OUT with the 1000 uF capacitor across them.
Wire the data lines
SIM800L TXD to D7, D8 through the divider to RXD, and join all grounds.
Wire the sense divider
Two 10 k resistors across the adapter output with the middle point to A0.
Put your number in the sketch and upload
The monitor shows a signal reading from AT+CSQ and Power watch ready.
Unplug the adapter
After about five seconds your phone gets Power has failed.
Plug it back in
A few seconds later your phone gets Power is back.
How do you build a power outage SMS alert?
A small unit sits on a 5 V adapter and a backup cell. When the adapter loses power it sends you an SMS, and sends another when the power returns, so a shop, a pump house or a freezer room can tell you about a cut. The cell keeps the whole unit alive while the mains is off. You need Arduino Nano, SIM800L GSM module, TP4056 module with protection (USB-C), 18650 cell 2600 mAh (branded), Battery holder 18650 single, MT3608 Boost Module, Electrolytic capacitor 1000 µF, Resistor 10 kΩ × 4, 5 V 2 A USB adapter, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm). It takes 9 steps and about 150 minutes.
- Level
- Beginner
- Time
- About 150 min
- Parts
- 11
Wiring
| From | To | Why |
|---|---|---|
| 5 V USB adapter | TP4056 IN+ and IN- | Charges the cell from the mains adapter |
| Cell holder | TP4056 B+ and B- | The 18650 cell |
| TP4056 OUT+ and OUT- | MT3608 IN+ and IN- | Backup power from the cell |
| MT3608 OUT+ and OUT- | Nano 5V and GND | Set to 5.0 V with no load first |
| TP4056 OUT+ and OUT- | SIM800L VCC and GND | The module runs straight from the cell |
| 1000 uF capacitor | Across SIM800L VCC and GND | Holds the voltage during transmit bursts |
| 10 k and 10 k in series | Adapter + to GND, middle to Nano A0 | Divider that halves 5 V so A0 reads about 2.5 V |
| SIM800L TXD | Nano D7 | Replies from the module |
| Nano D8 | 10 k to SIM800L RXD, 10 k from RXD to GND | Commands, divided down to 2.5 V |
| All grounds | Joined together | Adapter, cell, Nano and module share one ground |
Code
The unit has two power paths. The 5 V adapter charges an 18650 cell through the TP4056 board, and the cell then runs the Nano through the MT3608 boost converter and runs the SIM800L directly. So when the mains fails, nothing in the unit turns off. The Nano finds out about the cut by watching the adapter voltage itself. Two 10 k resistors form a divider that halves the adapter's 5 V to about 2.5 V, which A0 reads as roughly 512. When the adapter goes off the reading drops to nearly zero. The sketch uses two limits, 300 to say it has failed and 400 to say it is back, so a reading in between does not flip the answer back and forth. This is called hysteresis. The change must last 5 seconds before an SMS is sent, so a flicker in the supply does not send a message. The SIM800L needs a 2G-capable SIM and a supply that can deliver 2 A for a moment while it transmits, which is why it is powered straight from the cell with a 1000 uF capacitor beside it and not from the Nano. The module's receive pin tolerates about 2.8 V, which is why Nano pin D8 goes through a second 10 k divider. Set the MT3608 to 5.0 V with a multimeter before you connect the Nano. Replace the phone number with your own, and check that the SIM has credit. Note that the TP4056 charges a cell only while the adapter is on, and that a real installation should use a cell holder that is not near any heat.
Runs on a virtual Arduino Nano in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).
#include <SoftwareSerial.h>
SoftwareSerial gsm(7, 8); // RX, TX
const char* PHONE = "+91XXXXXXXXXX"; // your number with country code
const int SENSE = A0; // adapter voltage through a 10 k / 10 k divider
const int LOST_BELOW = 300; // under about 1.5 V on the pin means the adapter is off
const int BACK_ABOVE = 400; // over about 2.0 V means it is back
const unsigned long CONFIRM = 5000; // the change must last 5 s before we send
bool mainsOk = true;
unsigned long changedAt = 0;
bool pending = false;
void at(const char* cmd, int wait = 600) {
gsm.println(cmd);
delay(wait);
while (gsm.available()) Serial.write(gsm.read());
}
void sendSms(const char* text) {
at("AT+CMGF=1"); // text mode
gsm.print("AT+CMGS=\"");
gsm.print(PHONE);
gsm.println("\"");
delay(500);
gsm.print(text);
gsm.write(26); // Ctrl+Z ends the message
delay(3000);
while (gsm.available()) Serial.write(gsm.read());
Serial.println();
Serial.print(F("SMS sent: "));
Serial.println(text);
}
void setup() {
Serial.begin(9600);
gsm.begin(9600);
delay(3000); // let the module find the network
at("AT");
at("AT+CSQ"); // signal strength, 10 or more is fine
Serial.println(F("Power watch ready"));
}
void loop() {
int v = analogRead(SENSE);
bool wantOk = mainsOk ? (v >= LOST_BELOW) : (v > BACK_ABOVE);
if (wantOk != mainsOk) {
if (!pending) {
pending = true;
changedAt = millis();
} else if (millis() - changedAt >= CONFIRM) {
mainsOk = wantOk;
pending = false;
sendSms(mainsOk ? "Power is back." : "Power has failed. Running on battery.");
}
} else {
pending = false; // a short flicker, forget it
}
static unsigned long last = 0;
if (millis() - last > 2000) {
last = millis();
Serial.print(F("Adapter reading "));
Serial.print(v);
Serial.println(mainsOk ? F(" (mains ok)") : F(" (mains OFF)"));
}
}What the serial monitor should show
Open the serial monitor at the baud rate in the code. This is what our simulator prints for a virtual Arduino Nano with its sensors at their default values. Your numbers will follow your real readings, but the format should match.
Power watch ready Adapter reading 205 (mains ok)
Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Adapter plugged in | Monitor shows a reading near 512 and mains ok |
| Unplug the adapter for 2 s only | No SMS, the reading recovers |
| Unplug the adapter for 10 s | Reading falls near 0 and the Power has failed SMS arrives |
| Plug the adapter back | The Power is back SMS arrives |
| Cut power and leave it for an hour | The unit stays alive on the cell |
If it does not work
No SMS arrives
Check the SIM has credit and signal, and that AT+CSQ in the monitor shows 10 or more.
The module keeps restarting
The supply sags when it transmits, so check the 1000 uF capacitor and use the cell, not the Nano 5V pin.
Reading stays at 0 with the adapter on
Check the 10 k divider is joined to the adapter output and to ground.
Garbled text from the module
Check the baud rate is 9600 and the module ground joins the Nano ground.
The Nano resets when the unplug happens
The MT3608 may be set below 5 V, so reset it to 5.0 V.
Upload fails
Choose the Old Bootloader option for the Nano.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the power outage SMS alert?
Arduino Nano, SIM800L GSM module, TP4056 module with protection (USB-C), 18650 cell 2600 mAh (branded), Battery holder 18650 single, MT3608 Boost Module, Electrolytic capacitor 1000 µF, Resistor 10 kΩ × 4, 5 V 2 A USB adapter, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm).
How long does the power outage SMS alert take to build?
About 150 minutes for a beginner maker, in 9 steps.
How do I know the power outage SMS alert works?
Adapter plugged in: Monitor shows a reading near 512 and mains ok. Unplug the adapter for 2 s only: No SMS, the reading recovers. Unplug the adapter for 10 s: Reading falls near 0 and the Power has failed SMS arrives.
No SMS arrives: what should I check?
Check the SIM has credit and signal, and that AT+CSQ in the monitor shows 10 or more.
The module keeps restarting: what should I check?
The supply sags when it transmits, so check the 1000 uF capacitor and use the cell, not the Nano 5V pin.
Reading stays at 0 with the adapter on: what should I check?
Check the 10 k divider is joined to the adapter output and to ground.
Garbled text from the module: what should I check?
Check the baud rate is 9600 and the module ground joins the Nano ground.
