Go Down

Topic: Using an ssr and arduino to make a push on switch (Read 545 times) previous topic - next topic

leds_are_cool

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

knut_ny

#1
Feb 22, 2016, 08:48 pm Last Edit: Feb 22, 2016, 08:50 pm by knut_ny
Code: [Select]
// connect switches to ground the input pins
const byte on_pin=4, off_pin=5, relay_pin=6;


void setup()
{
  pinMode(on_pin,INPUT_PULLUP);
  pinMode(off_pin,INPUT_PULLUP);
  pinMode(relay_pin,OUTPUT);
  
  // put your setup code here, to run once:

}

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

septillion

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.
Code: [Select]

#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() {
  button.update();
  if(button.fell()){
    digitalWrite(RelayPin, !digitalRead(LedPin));
  }
}
Use fricking code tags!!!!
I want x => I would like x, I need help => I would like help, Need fast => Go and pay someone to do the job...

NEW Library to make fading leds a piece of cake
https://github.com/septillion-git/FadeLed

leds_are_cool

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

pwillard

#4
Feb 23, 2016, 07:44 pm Last Edit: Feb 23, 2016, 07:46 pm by pwillard
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...

http://www.reuk.co.uk/Latching-Relay-Circuit.htm

septillion

#5
Feb 23, 2016, 10:04 pm Last Edit: Feb 23, 2016, 10:05 pm by septillion
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 :) And let the SSR handle the mains.
Use fricking code tags!!!!
I want x => I would like x, I need help => I would like help, Need fast => Go and pay someone to do the job...

NEW Library to make fading leds a piece of cake
https://github.com/septillion-git/FadeLed

Go Up