Skip to content

DIY UPS with and Arduino

Jim Klimov edited this page May 18, 2024 · 8 revisions

WARNING! WARNING! WARNING!

Be careful! Building this sort of project involves potentially lethal mains level voltage, potentially high current, and potentially overheated cabling or contacts becoming a fire hazard. You need to understand how to do this safely, size components and match metals appropriately, etc.

NOTE: As of 2024-05-16, this is a work in progress.

Links:

ROUGH OUTLINE

NUT communication using Arduino

The overall idea is to use an Arduino Pro Micro (built in USB connector) and the HIDPowerDevice Arduino Library project. As of NUT v2.8.2, an Arduino Pro Micro using this library in a sketch will be correctly detected by NUT using the Arduino sub-driver for usb-hid. See drivers/arduino-hid.c in the NUT source code for details.

The HIDPowerDevice library has a sample sketch as an example. The rough idea is that once you initialize the library, you send reports to NUT periodically calling a sendReport function with various flags set. Ex:

PowerDevice.sendReport(HID_PD_PRESENTSTATUS, &iPresentStatus, sizeof(iPresentStatus));

The iPresentStatus is a bitfield with a ton of info in it, like: PRESENTSTATUS_ACPRESENT, PRESENTSTATUS_DISCHARGING, PRESENTSTATUS_CHARGING, etc. See the project for full details.

A minimal implementation would look for the status of mains AC on a pin using an opto-isolated AC detection module, then set or clear HID_PD_PRESENTSTATUS and call sendReport()

A next step would be to use a voltage divider to sense the DC voltage and turn it into a percentage you can report with:

PowerDevice.sendReport(HID_PD_REMAININGCAPACITY, &iRemaining, sizeof(iRemaining));

UPS components

With the above Arduino handling status updates to NUT there are many choices for cobbling together a UPS.

Minimal online double conversion architecture

Sample 12V equipment. Can be used for loads less than 800-1000W. Beyond this, use 24/48V

  • 12V Pure sine inverter. It's going to run 24/7 so reliability may be a concern. Possibly derate it to extend lifetime?
  • 12V Lead acid battery bank. Size this for the load and the run time you want.
  • PowerMax RV 12V converter/charger.
  • Cables to connect the above. Size them for the load. 4/6/8AWG may be needed depending on equipment and load.
  • Arduino to monitor AC presence and DC voltage The equipment is connected so the inverter and the battery bank are wired as parallel loads to the converter/charger. When AC power is on, the converter is powering the inverter. When power is off, the converter shuts down and the battery provides power to the inverter instantly. The AC load downstream of the UPS is always powered by the inverter.

Minimal line interactive architecture

Sample 12V equipment. Can be used for loads less than 800-1000W. Beyond this, use 24/48V

  • 12V Pure sine inverter. Size for the load you have, ensure the inverter can handle the voltage range of the battery bank.
  • 12V battery bank. Size this for the load and the run time you want.
  • Any quality battery charger appropriate for the battery chemistry.
  • Automatic Transfer switch (ATS) capable of switching in less than XXXX milliseconds. This one from Amazon may work, but isn't tested yet. The equipment is wired like this:
  1. Mains AC connects to charger AC in.
  2. Another Mains AC connects to the the "Utility" or "primary" ATS input.
  3. Battery and inverter are wired as parallel loads to the charger output.
  4. Inverter output connects to the "generator" or "secondary" ATS input
  5. AC Load connected to ATS output. This is the architecture in many consumer UPS'. The ATS switches between to AC inputs. If the primary input is on, it uses that. If that is off, it switches to the secondary (the inverter). In this case, the inverter is always running, but under virtually no load until a power outage. With this architecture, you do not need a powerful battery charger because the charger does not need to supply enough power to power the AC load downstream of the inverter. You do need to be careful selecting an ATS that will switch fast enough for your load and an inverter that will handle the initial surge.

Notes about battery choices

12/24/48V systems

A rough guide is: For less than 1000W, 12V is ok. From 1000-2000W 24V is ok. Above 2000W, use 48V. Generally, you will find more equipment choices at 12V. But, be careful because some 12V equipment assumes 12V always means "lead acid batteries" and that may not be what you choose. Going to a higher voltage system allows smaller diameter cables connecting things. As of May 2024, there are more choices in 48V equipment than a few years ago, I think mostly because folks are scaling up home solar systems. 24V feels like it is getting more rare.

Battery chemistry

This is a deep topic, there's no single right answer. Keep in mind the use case for your UPS. For many people, the battery is fully charged almost 100% of the time and discharged rarely. In many cases, a lead acid battery can be very cost effective for this.

Future ideas

It would be nicer to integrate everything. Functionally I think of it as:

  • AC/DC PSU. I'd probably just buy this since I have no experience designing PSU
  • MCU that reports to NUT and controls battery charging
  • DC/DC battery charger. As long as the hardware can do constant-current and constant voltage. An MCU with the right code can drive that battery charge profiles.
  • AC detection, DC voltage sensing, DC current sensing.
  • Inverter driven by an EGS002 or similar module.
  • an ATS (if doing line interactive architecture). I'd buy this.

It feels like a single PCB could handle the MCU with the charging and inverter components. The MCU isn't really required to run the inverter so maybe the inverter section could be its own board. It could all still fit inside a single case with the ATS.

Clone this wiki locally