Switching circuit using relays and UPS with Arduino in case of a power failure!

Hello all , I have an old APC UPS which i want to use as home inverter and i don't want to always keep it turned ON also. So when a power failure occurs the Arduino turns ON the UPS (need to push the power button for 1 second to turn ON and 3 second to turn OFF) and switches the appliances to UPS after a 2 second delay. When mains power restores it restores the appliances from UPS back to the mains supply and then turns off the UPS . For detecting the AC voltage presence I am thinking of using a 5v charger to input pins of my Arduino UNO board. I like diy electronics projects and have made many (excluding Arduinos) for myself but I am New to this community and want to get proper guidance for code and schematic parts. Thanks

Lots of great volunteers here that can help.

You need to be specific in asking questions, broad questions are not reasonable for this type of forum.

Example:
How do I make this work ? :woozy_face:

How can I use a MOSFET to energize a relay ? :slightly_smiling_face:


To start with, read the forum guidelines on the Sticky topic

An uninterruptible power supply or uninterruptible power source (UPS) is an electrical apparatus that provides emergency power to a load when the input power source or mains power.
(from wikipedia).

So I would assume a UPS should be always on in "standby" and jump in if mains gets disconnected.

So why do you want to switch the UPS "off"? what should the Arduino Uno do?
What APC UPS model do you have?

Hi, Thanks for the reply. I have an APC Back-UPS pro 1500 model that I have modded to run on Lithium ion battery. Since, my area don't have frequent power outages I am thinking of turning it ON only when outage happens. There can be a delay of 10 seconds in switching to UPS in case of a power outage.

I have Arduino UNO board. I want to detect the presence of 220V mains supply. For that I am thinking of using a mobile charger to supply at the input pin of Arduino. When there's mains present I want appliances to be run through the mains relay. When there's mains outage then the Arduino should turn ON the UPS through the power switch (needs to be pressed for 1 second) then Mains relay gets turned OFF and the UPS relay is turned ON. When the power gets restored the UPS relay is turned OFF and the Mains relay is turned ON. After that UPS is also turned off (power switch needed to be pressed for 3 seconds) by Arduino.

You want to switch something on/off depending on something else. Get an arduino, an LED and a button. Code for LED on/off. New Sketch, code for button input with no delay, some debounce and serial print. Combine both sketches so now input is button, output led. Use the millis timer knowledge from button code to time how long the led goes on for to simulate your requirements with ups. Replace button with current clamp sensor (5v wall wart is inefficient sensor). Alternatively use an led or similar on your load to provide a sensor for on/off. Replace your led with relay or similar taking account of current and voltage requirements to drive it.

Why? You will waste more power through your 5v adapter than through a good UPS which is essentially doing exactly what you are duplicating internally.

As i I told I have modded the UPS to be run on Lithium Battery and these batteries are charged through an external Li-ion charger. I have tried disconnecting the internal (lead-acid) charger which throws an fault message to the UPS and it turns OFF. So I want the UPS to run only on battery power when outage happens.

That is, in general, what a UPS is; a battery backup system. But you shouldn’t turn a UPS off and then replicate its function externally as that is weird and silly.

If, what you are saying is that you don’t actually have a UPS bit simply a pile of batteries then what you are actually asking is “how do I make a UPS”!!

I have asked only to turn the UPS ON in case of power outage, for now I have to do this manually. Can't Arduino do that?

I don’t think you have a UPS! If you did you would not need to switch it on or off! You have a battery.

If you actually have a UPS your questions make no sense but can still be achieved with the instructions in my previous post.

I think you need to stop and think about your project and what you actually want to achieve because it sounds like nonsense the way you describe it

I still don't get the point to switch on/off a UPS, but anyhow.
a) you have to detect if the AC state changes
b) based on which transition you can pulse an output longer or shorter

// pulse an output if switch changes to low
// https://forum.arduino.cc/t/switching-circuit-using-relays-and-ups-with-arduino/1019626/

constexpr uint8_t inputPin {7};
constexpr uint8_t warningPin {9};
constexpr uint8_t pulsePin {11};

constexpr uint16_t intervalOn {1000};
constexpr uint16_t intervalOff {3000};

byte previousInputState = HIGH;

void pulseUpdate()
{
  uint8_t inputState = digitalRead(inputPin);
  if (inputState == LOW && previousInputState == HIGH)
  {
    Serial.println(F("AC off"));
    digitalWrite(warningPin, HIGH);
    digitalWrite(pulsePin, HIGH);
    delay(intervalOn); // dirty delay
    digitalWrite(pulsePin, LOW);
    previousInputState = inputState;
  }
  else if (inputState == HIGH && previousInputState == LOW)
  {
    Serial.println(F("AC on"));
    digitalWrite(warningPin, LOW);
    digitalWrite(pulsePin, HIGH);
    delay(intervalOff); // dirty delay
    digitalWrite(pulsePin, LOW);
    previousInputState = inputState;
  }
}



void setup() {
  Serial.begin(115200);
  Serial.println(F("Switch an output based on another pin"));
  pinMode(pulsePin, OUTPUT);
  pinMode(warningPin, OUTPUT);
  delay(50);
}

void loop() {
  pulseUpdate();

}

Hi friend, what made you think, I don't have a UPS? As I told, I have a fully working APC ups. But it just have a lithium battery attached to it. I am attaching a pic.

You don’t have a UPS or else you wouldn’t be asking how to turn it off and on since this is a function the UPS already has.

A UPS is a device that monitors the power and switches to battery mode when main power is lost. You are asking how to monitor the power and turn on a UPS when main power is lost. It is like asking to put a switch on a switch!! It is weird and when we get weird questions here it normally signifies an XY problem (look it up).

I want to to get the UPS turned off and ON through Arduino board. And I want to turn it OFF because i dont want it to be always turned ON 24X7 hours for one in a month outage to conserve its life.

So you want an arduino to be turned on 24/7 monitoring the power to avoid the UPS being on 24/7 monitoring the power.

What you are saying does not make sense. Your final project will be less efficient, less responsive, and more failure prone for NO benefit that I can see. You are asking to duplicate something that has been done way better than you will ever do it (unless your UPS is a piece of carp).

The entire purpose of a UPS is to ALWAYS be on to monitor the power and switch to backup of power fails. Building a second monitor to duplicate this function is bonkers.

2 Likes

I am not asking for efficiency or responsiveness since there will fans and led lights at the load. As for the failure, i think this a mere simple task for arduino and there will be less chances of the bugs in the code.
One more thing, there is also an transformer in that UPS which stabilizes the voltage and gets hot. Because of that the UPS will always be warm only to supply a constant voltage to the fans and the led lights ( which I don't want) and using extra power.

You want to use a transformer to power your arduino!!

There is no way round this being a bad idea. I could understand you if either your UPS did not work (ie was acting as a battery only without any “smart” functionality) or your UPS was so cheap and rubbish that it did its job incredibly poorly.

I would expect even a cheap UPS to work more efficiently than your plan but as stated above this is how you do it;
Build a relay circuit with your UPS on the NO terminal and power to COM. Attach a current sensor or your inefficient adapter to 5v to the arduino to detect power on/off in mains. When power off switch relay on. Power Arduino and relay module from UPS battery and 5v adapter.

Bonkers but hey ho. You are building a UPS to turn on a UPS! It’s like UPS inception next you need to build another UPS maybe controlled by a raspberry pi so that you can switch off your arduino!!!

1 Like

That’s what the second uPS is for! :joy:

You really didn't understood what I told and want to achieve and made it look like more complicated than it really is. I told there is a big transformer inside the UPS which does the job of stablizing the input AC mains voltage and outputs a steady 220V AC for sensitive appliance like PC. Since i am using insensitive loads (fans and lights), so I don't want that feature
Let's start from begin.

I want to wire up the power button of the ups to the arduino so that it can turn it ON and OFF in case of power failure.

Did you read my first and second post?

I had told that a special Li-ion charger is being used for charging the batteries with bms.