https://github.com/david-lor/arduino-poweroutagedetector
Simple Arduino project to detect power outages
https://github.com/david-lor/arduino-poweroutagedetector
arduino power-outage
Last synced: 2 months ago
JSON representation
Simple Arduino project to detect power outages
- Host: GitHub
- URL: https://github.com/david-lor/arduino-poweroutagedetector
- Owner: David-Lor
- Created: 2019-05-05T15:44:06.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2019-05-08T12:08:22.000Z (about 6 years ago)
- Last Synced: 2025-02-04T09:16:51.932Z (4 months ago)
- Topics: arduino, power-outage
- Language: C++
- Size: 249 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Arduino-PowerOutageDetector
Simple Arduino project to detect power outages. Following the KISS principle, the Arduino is limited to:
- Detect changes on power supply status
- Notify status using Serial
- Turn ON/OFF two ON/OFF status LEDs
## Requirements
- Arduino, any basic model is enough, but Serial is required (internal Serial<->USB converter recommended). Built on Arduino Nano compatible board with ATMega168P MCU.
- PC817C Optocoupler.
- 5V AC-DC adapter.
- A device to read the Serial output of the Arduino and perform the required actions on power ON or OFF (e.g. send a message to a MQTT topic, turn ON/OFF a computer...).
- (optional) 1x or 2x LED, 1 switch## How does it work?
The Arduino should be connected through USB to a computer or low power device (e.g. a router, a RPi) that can read the Serial output from the Arduino.
This computer/device is supposed to be connected to a UPS or battery, so when there is a power outage, the Arduino and device can know that it happened and do whatever is supposed to do.Outside of the UPS, a 5V AC-DC adapter feeds the Optocoupler (so the Arduino -UPS powered- circuit is isolated from the output circuit).
When there is a power outage (a.k.a. the 5V AC-DC adapter is OFF) the optocoupler turns off, so the Control Pin of the Arduino detects this change on the power status.
## Pinout & Components
- Control Pin (2): optocoupler 5V output (HIGH when power is ON, LOW when power is OFF)
- ON LED (3): optional LED, turns ON when the power is ON, turns OFF when the power is OFF
- OFF LED (4): optional LED, turns ON when the power is OFF, turns OFF when the power is ON
- Maintenance Mode Switch: optional switch that can be activated to disable the power outage detection when the 5V adapter will be disconnected temporary due to some maintenance.
- Resistor values can be changed, but keep in mind maximum current ratings. Optocoupler is limited to 50mA on both input and output.## Versions
- PowerOutageDetector_Simple: Simple/classic Arduino version with a constantly running loop
- PowerOutageDetector_Interrupt_Sleep: version that uses LowPower library to turn OFF the Arduino after detecting a change on the power status and sending it through Serial, using External Pin Interrupts. The Arduino will wake up after detecting another change.## Monitor script
Shell script that listen to a single Serial port and send each new received line through MQTT. Designed to be used on OpenWRT without Bash available.
Due to a bug on `PowerOutageDetector_Interrupt_Sleep` version, sometimes a certain status can be sent over Serial multiple times. To keep the Arduino sketch as simple as possible, a verification for repeated lines is performed on this script, instead on the microcontroller.