Switch to an arduino to control a SSR

Hi all,

Learning with Arduino please bear with me.

I have a switch and a relay on pin 4 and pin 2 respectively. I add them to breadboard like in the attachment.

So question is where does the other pin of the switch go to. I need the relay to work once i press the switch as in the code below,

int Relay = 2;
int btn = 4;
int ButtonState = 0;

void setup() {
  pinMode (Relay, OUTPUT); //declare funcationality
  pinMode (btn, INPUT); //declare funcationality
  digitalWrite(Relay, HIGH); //declare funcationality
}

void loop() 
{
  ButtonState = digitalRead(btn);
  if (ButtonState == HIGH)
      {
       digitalWrite(Relay, HIGH);
       delay(5);
       digitalWrite(Relay, LOW);
       delay(450);
       digitalWrite(Relay, HIGH);
       delay(13);
      }
}

To GND and then enable internal pull up. How to do so? Maybe start to read tutorials?

BTW, that LED will turn into smoke if you try to turn it on without resistor.

Also, the - side of the SSR is connected to noting because the second to last row isn't connected.

And I hope you don't plan on running MAINS to that breadboard. Mains to a breadboard is already a bad idea but because of the state of your schematic and question I would say you are NOT ready to handle mains. Mains can kill you.

ok i guess i figured it out. so the resistor for the switch just acting as a load so that a short circuit does not happen and that is how the arduino knows that there is switch involved and when the stat of the button changes another action is done that is the relay is switched on here.

Did not notice the reply as i already had this typed out. Well thank you on the LED resistor. I have added those.Nope not connecting any mains now.

anishkgt:
so the resistor

Which resistor? I don't see any resistor in the drawing... And you don't need one (external that is) to read a switch. For the led on the other hand, you DO need a resistor.

ok i guess i figured it out. so the resistor for the switch just acting as a load so that a short circuit does not happen and that is how the arduino knows that there is switch involved and when the stat of the button changes another action is done that is the relay is switched on here.

There's no problem "shorting" an Arduino input to +5V or ground with a switch. The problem is when the switch is open and input "floats' to an undefined level.

A pull-up or pull-down resistor provides a known state when the switch is off. If you were to "pull-up" (or "pull-down") without a resistor, then yes, you'll create a 5V- to-ground short when you activate the switch.

(The Arduino has a built-in pull-up resistor that you can [u]enable[/u] with software.)

The LED needs a series resistor because LEDs are non-linear (like all diodes). If you exceed the operating voltage, excess current flows.* The resistor limits the current and "forces" the LED to operate at the right voltage. The LED won't necessarily "smoke", but the LED, Arduino, or power supply could be damaged or the Arduino may glitch and crash your program, etc.

Solid state relays have LEDs inside. Some (most?) have a built-in resistor and some require an external resistor.

  • Resistors are linear. If you double the voltage you double the current (Ohm's Law). When you exceed the operating voltage of an LED (or the "breakdown voltage" of a regular diode) the resistance drops dramatically and current increases disproportionately,and bad things happen if the current isn't limited elsewhere.

Thanks for the info on the INPUT_PULLUP. So i wanted to have the pin to be high when closed and Low when open. So I've left the resistor as a PULLDOWN at the ground (if that and changed the schematic a bit more(and at the same time learning also). Hope it makes some sense now.

A little confusing is where it says a resistor at the +5 makes it pullup, but how exactly. Isn't it like a load. Now speaking of the +5 pin. I have nothing connected their. not sure what would go there are all the components are connected to the digital pin and those are like a positive volts. I could add an LED to show the board is powered other than that wouldn't the whole circuit work ?

What i want to do is basically fire the relay with the button where the Arduino sends some commands to the SSR and stops and waits again for the button to be pressed.

anishkgt:
So i wanted to have the pin to be high when closed and Low when open.

Why? The code doesn't care if it checks for a high or a low.

anishkgt:
So I've left the resistor as a PULLDOWN at the ground

You did not. A pull down is between a pin and GND. So just remove that resistor and connect it straight to GND.

And okay, you removed the SSR from the breadboard. But really I think you should not yet mess with mains until you have more understanding of electricity.

hmmmm so its ok to remove the resistor ? well i thought that would short the pins and blow something up and at the moment i don't intend to start a fire show. :slight_smile: moreover these arduino thingy are not easy to get it shipped. So would this change how the state of the button. It does stay closed as high and open as low, right ? that is what i want.

The SSR are placed just for my understanding. I very well understand the electrical part and hazards of it, Thanks.

So the +5, does that need to be connected anywhere ? i don't see a need other than anything that requires it for operation like maybe power indicating LED.

Now it's okay. The 5V isn't needed for the button. And you can't short a pin as long as it's set as input. You can connect it to GND or 5V, nothing will blow.

If you set up the pin with pinMode(pin, INPUT_PULLUP) the pin will internally be pulled high (as if there is a resistor between the pin and 5V. So it will not float and read high. Now when you push the button you connect the pin to GND. This will not short anything because you have the internal resistor and connecting 5V via a resistor to GND is just fine. Now the button will just read low. All this is also written in all the good tutorials (that just use the internal pull up).

May I ask where you live that an Arduino is hard to get?

Ok Cool. glad am doing well :slight_smile:

One quick question, So without the resistor would the switch when closed read as high or low ? I did read about those that is how i fuigured that a resistor should be used when i saw this tutorial

I live in the middle east and amazon for some reason has some restrictions to be shipped here. So i've ordered it via ebay for now.

No button pressed = HIGH
Button pressed = LOW

Aha. But I must say, i'll order all my electronica on eBay or AliExpress directly from China. Takes some time (but it really varies from 5 days till 50 days..) but a lot I can't by local or I'll pay more for 1 then I do for 20 online...

hmm button pressed = HIGH is more logic to me and keeps the confusion down. So if i need to set the CLOSED as HIGH what do i do ? do i set the Pin as NPUT_PULLUP ?

Thanks

never mind. will leave it like so can reduce the components. :slight_smile:

You will get used to it pretty fast :wink: A way to think of it is to look at the mechanical position of the button. If the button is not pushed it's up or high and when you push it down it's position is down or low :wink:

Yea i guess will stick to the defaults for now. Same time trying to understand the inrush current limiting also.

That is gonna take some time.

Inrush current of what? The switch at least has no noticeable inrush current.

Oh that is a different post its for a transformer used for Spot welding 18650 and this switch is part of it. The SSR here controls the Transformer.

The SSR you've shown does not have an internal current limiting resistor ... you cannot connect the SSR IRLED input directly to an Arduino output. You need an external current limiting resistor. Here's several connection methods:

Thanks dlloyd but that was just a sample as component for understanding. I am planing to use one of these pic as they are readily available locally.

I guess with what i have i would not need a resistor as these SSR can handle voltage from 3 - 32vdc.

Yeah, you can connect direct. If it's labelled FOTEK, note that there are clones out there with poor performance. Some need 12VDC or so on the input to adequately switch the load. Also, the minimum AC load requirement might be higher than advertised. Some may not work at all.

With direct connections, the above examples still apply (without the resistors).