I have built a basic relay to control a 110v socket from a microcontroller and/or other physical switches. It more or less breaks down to the diagram attached. A few quick questions -
Does it matter what side (+/-) the switches are on? I do not imagine it matters for the AC side at all, but maybe the DC side?
Is it perfectly safe to have only one prong of the AC side on relay, and the other always-on?
The big one, and what prompted me to post a question - should I have a diode at position A? I know that I should if I was driving a DC motor, but what about here, where I am using a simply and cheap relay? Does it matter which direction the diode is facing (guessing yes, duh). I currently have one attached and the circuit does work. It worked before too, but I would like to use good practices and better understand what I am doing here.
Using a physical switch as the switch on the DC side (like a household light switch or a button) vs using a microcontroller+transistor, should I be taking any additional precautions to protect the microcontroller, such as an optoisolator? I have a few and would not mind connecting them, but again, I would like to use good practices and understand.
I have built a basic relay to control a 110v socket from a microcontroller and/or other physical switches. It more or less breaks down to the diagram attached. A few quick questions -
Does it matter what side (+/-) the switches are on? I do not imagine it matters for the AC side at all, but maybe the DC side?
yes, it matters. You want to switch the hot line for sure (as compared to the neutral)
Is it perfectly safe to have only one prong of the AC side on relay, and the other always-on?
if it is the hot line you are switching, yes.
The big one, and what prompted me to post a question - should I have a diode at position A? I know that I should if I was driving a DC motor, but what about here, where I am using a simply and cheap relay? Does it matter which direction the diode is facing (guessing yes, duh). I currently have one attached and the circuit does work. It worked before too, but I would like to use good practices and better understand what I am doing here.
you are using a relay with an optoisolator, right? So, they will be electrically isolated circuits
Using a physical switch as the switch on the DC side (like a household light switch or a button) vs using a microcontroller+transistor, should I be taking any additional precautions to protect the microcontroller, such as an optoisolator? I have a few and would not mind connecting them, but again, I would like to use good practices and understand.
be careful with A/C switching and make sure your relay is rated to the full capacity of the circuit it is attached and then some.
read more about interfaceing with line voltages and also more about connecting relays.
the relay power MUST be from a separate power supply. the arduino cannot deliver power to the relay reliably.
second, on 110VAC here in the States, you have a black and a white. the black is supposed to be the hot wire. the white is supposed to be the neutral that should be at the same potential as ground. you can test AC voltage from ground to white and ground to black. one should show 105 to 130 or such. the other should be at zero.
the reason you switch the hot is because if you do not, your device is has a hot and any ground will complete the circuit. often that is someone touching it. then that happens, they are shocked to find there is power.
I highly recommend that you use an opto isolator to keep the relay away from the arduino.
and put all that 120 side stuff in a separate plastic enclosure. you can buy cheap boxes at home depot in the electrical department.
Thanks guys! Oh, right, duh. I did read more about AC before building this, and I did switch the hot line and not the neutral. Good work, me-from-the-past.
So which line is switched does not matter at all for the 5v side, correct?
My real question here, is about that 1N4004 diode at posistion A - does that thing matter? Do I need it, and is it good practice? The direction matters, right?
I am not currently using an optoisolator. I could see value there if I am using a microcontroller, but should I bother if the 5v switch is a household light switch or hardware button?
Diode: neeeded, yes... or optional if you don't mind buying replacement parts in the future. Diodes tend to be cheaper than transistors so adding one to protect your transistor is cheap insurance against the voltage spike you see when the coil is de-energized, for example.
An opto-isolator is not needed since the relay provides more thn adequate isolation from ac lines.
Diode: neeeded, yes... or optional if you don't mind buying replacement parts in the future. Diodes tend to be cheaper than transistors so adding one to protect your transistor is cheap insurance against the voltage spike you see when the coil is de-energized, for example.
An opto-isolator is not needed since the relay provides more thn adequate isolation from ac lines.
Aha! That is the part I am missing, that the diode is protecting the transistor. Yeah, I could go either way on whether the transistor is worth protecting. Thanks a ton.
So, last little followup - if i were to use an optoisolator, where would it go? Would one use the opto WITH the diode, or is it a one-or-the-other situation?
I personally would not use an opto isolator in thar circuit, so I can't really recommended where it would go or how it would be wired. Redundant parts are illogical to me.