SSR with battery backup

@AndyW @peekay123, Hi Andy and Peekay. I’ve got what I hope is a easy one for you.

I’m tripping a solid state relay with my photon via a N-Channel Mosfet. I’m using the mosfet so I can deliver a full 5v to the relay instead of the 3.3 from the Photon. I want to also include a battery backup in my circuit to be able to switch on the relay should the Photon fail for some reason. My question/concern is this. If for some reason someone were to switch on the battery back while the Photon was still on and providing 5v to the SSR I want to ensure the 4.5V power from the battery pack doesn’t flow into the photon circuit and vice versa, 5v power from the Photon circuit into the batteries. Attached is a simplified image of my circuit. Please consider the switch to the mosfet actually a Photon with a pin going high/low. I’m not entirely sure if the Diodes will cover me here. Note that I’m actually using a 3 AA battery pack for 4.5V, not the 2AA in the image.

Oh! Bonus question: although the battery backup would rarely be needed due to the awesomeness of the Photon it would be nice to use rechargeable batteries which would be continually recharged by the main 5v power supply. How could I pull that off? Thank you!!! Todd

I’m not sure what your end goal is, but it seems like you could significantly simplify your circuit by putting the switch in parallel with the SSR on the load side.

The mosfet shouldn’t be necessary so I’ve left it off my diagram (this should be a low current thing, a simple transisor would work if you really need 5v at the SSR to trigger it), a pull-down resistor would probably be a good addition to this circuit though between D0 and ground to keep the pin float from triggering the SSR unexpectedly.

@indemnity83, Thank you! Indeed, you’re right, I could certainly use a smaller NPN instead of the Mosfet. I do need to supply 5v to my SSR as that is its minimum rating. Most are 3v minimum now, but I have 5v handy in my circuit so thought I’d use that. My question is more around incorporating the battery backup to trigger the SSR. I don’t want a switch on the AC side of the SSR. This exercise is concerning the DC side. Thanks again for the thoughts. OH! Where did you find the Photon on Fritzing?

one way may be to use simple 7400 logic chip an OR gate and power the SSR off the backup battery all the time , but trigger it from the switch or photon .

Fritzing model for Photon and Spark: https://github.com/technobly/SparkCore-Photon-Fritzing

@tkurtz are you wanting to the the battery in case the Photon/Firmware kicks the bucket, or is it just to ride-through a power fault? Here’s a much more complicated circuit, but one which provides battery backing of the photon if main power (vin) is lost, and will keep the battery charged too. The catch here is that it won’t work with your 5V SSR (it might with some tweaking and a buck converter).

Red wires are the battery V+, green is 3.3V regulated and orange are the external source (can be 3.75 - 6V, or power over USB). Blue is the signal path, and black is common ground.

This is based on the Adafruit Pro Trinket LiPoly/LiIon Backpack design, which is done around a microchip Li-Polymer charge controller: https://learn.adafruit.com/adafruit-pro-trinket-lipoly-slash-liion-backpack/overview

Wow! Intersting and you’re making me think through this in a different way. Let’s eliminate the battery from the circuit for a scenario. How could I always be running 5V to the SSR unless the photon were to trigger the 5V to stop? In that case if the Photon were to fail for whatever reason the SSR would still be supplied the 5V needed to keep the relay flowing AC. Would I use a PNP transistor instead? Only when the attached Photon pin goes high would the SSR stop flowing AC. Thanks again! Todd

Don’t forget, you lose 0.7V with a transistor. An N-Channel MOSFET with a pullup to 5V (4K7) would switch it on without the Photon, as long as the Vgs is under 5V. With the Photon digital pin in output mode, you’d get 0V low, or 3V3 high. Switch it to input mode and you’d get 5V (just no current). So switching to input turns it on, output low turns it off.

1 Like

@CuriousTech, to be honest here I’m not totally following how you are manipulating the N-CHNL MOSFET here and would love a more in-depth explanation if you have the time to teach a hobbyist something new.

If I’ve got the set up straight I’m going to leave my circuit largely as is however with the following changes:

  1. run a 4,700 resistor from 5v rail to MOSFET gate which will pull it high turning on the relay even in the event the photon where to fail or lose power.

  2. change my code like so and have my relay on a digital pin…

         if (command=="Enable Now") {
            pinMode(relay,INPUT); // Our relay pin is input which turns the relay ON.
        relayenable = "Yes";
        enabled = 1;
        return 200;
    }
        else if (command=="Disable") {
            pinMode(relay,OUTPUT); // Our relay pin is now output.
            digitalWrite(relay,LOW); // Our relay pin is set to LOW which turns the relay OFF.
        relayenable = "No ";
        enabled = 0;
        return 200;
    }
        else {
        return -1;
    }

Your code looks good. When you switch between input and output, it probably retains the previous output state so it switches to low immediately. But it’s best to just set it every time anyway. Most micro-controllers are tri-state, where the input is high-Z or possibly 1Mohm to ground, but also have a 5V1 zener diode that can handle just small current. So going over 5V would pull it down to 5V no matter what state you’re in, but likely damage it with enough current.

@CuriousTech, thanks again for your advice here. So, I’m concerned that I’m going to fry my Photon with this set-up. Are you confident that using the photon digital pin in this way is within it’s tolerances? For an overview of my circuit I’ve got a 12v 1.67A power supply running through a 5v 1.5A voltage regulator. The 4.7k resistor to N-Channel MOSFET gate along with Photon digital pin to toggle the MOSFET. The SSR should have very little draw. Thoughts?

Sorry for the scare @tkurtz. It’s perfectly safe. The current for the SSR is going through the MOSFET, which is 20-50mA (see the datasheet), and the MOSFET gate takes none, except just a bit when it switches. So really all you need is to control the voltage to it without any current. Even a 10K resistor would work fine, but higher gets slower and more susceptible to interference. High or low logic will always pull some current through the resistor, so using Ohm’s law you can get the current that will go through it. At 5 - 3.3 that’s 0.36mA through a 4K7 if you had it high, or about 1mA at 5 - 0 for low, which is what you’ll do a lot. That’s pretty low for normally operating a transistor.

@CuriousTech, You’re the best! Thank you. Can’t wait to hook it up!!! :smile:

Question: are the digital inputs 5V tolerant?

@Mycroft, digital inputs are 5V tolerant but NOT analog inputs. From the Photon datasheet:

1 FT = 5.0V tolerant pins. All pins except A3 and DAC are 5V tolerant (when not in analog mode). If used as a 5V input the pull-up/pull-down resistor must be disabled.

@CuriousTech, Success!!! This worked perfectly. I couldn’t be happier. Can’t thank you enough CuriousTech.

I also transferred the entire project to a Perma-Proto board over the weekend as well. That took a decent amount of time but very satisfying getting it off a breadboard.

Best!
Todd

1 Like