Using an ssr and arduino to make a push on switch

Hello everyone,

I want to make a circuit so that if i press a button the arduino turns on the solid state relay and if i release it it will stil keep the solid state relay powerd.
So i press a button ssr turns on i release it ssr still keeps on and the ssr powers arduino.

But how do i do this???

I was thinking of button gets pressed then ssr gets on then ssr powers arduino then arduino keeps ssr on by pulling a pin high which is connected to the ssr.
And if i want to to turn everything off i turn the pin which is connected to the ssr low and everything is of.

But i am not sure if this will work.
So will this work?????
if not how can i make it work?

Thanks everyone

// connect switches to ground the input pins
const byte on_pin=4, off_pin=5, relay_pin=6;

void setup() 
  // put your setup code here, to run once:


void loop() 
  if (digitalRead(on_pin)==LOW && digitalRead(off_pin)==HIGH) // switch on!
  if (digitalRead(off_pin)==LOW)  // switch off!
  // if this behavior should be 'anytine', use pins 2 and 3 (interrupu 0 and 1)

Just keep the Arduino powered (USB charger) and let the SSR do all the mains switching.

You already got a sketch that uses a on and a off button, that’s fine. Only never ever use the interrupts for something as simple as a switch.

Here a sketch for a simple on off one button setup. It uses the Bounce2 library to do all the button debounce and state detect stuff.

#include <Bounce2.h>

Bounce button;

const byte ButtonPin = 5;
const byte RelayPin = 13;

void setup() {
  button.attach(ButtonPin, INPUT_PULLUP);
  pinMode(RelayPin, OUTPUT);


void loop() {
    digitalWrite(RelayPin, !digitalRead(LedPin));

Sorry that i didnt explain it correctly.

I mean this:
Button powers ssr and ssr powers arduino.
Arduino powers ssr so the arduino keeps on.

thanks you guys

The sort of thing a person with a 3D printer wants to control printer power with... sounds like.

I did this... with 110V "normal" relay...

Button powers ssr and ssr powers arduino.
Arduino powers ssr so the arduino keeps on.

But what powers the button and the Arduino?

So simplest/safest approach, just leave the Arduino on :slight_smile: And let the SSR handle the mains.