Hi, as my next project and first ever project using mains voltage, I'm planning to build a circuit which will allow me to switch a UK 240Vac mains supply on or off from my computer, via an Arduino connected to the computer via USB. I have a mains relay which will switch this mains voltage using a 12V coil. I plan to use an NPN transistor to allow the Arduino to switch on or off the 12V going to the coil, which will be provided by a 9V battery and two 1.5V batteries in series.
I've never undertook a project which uses transistors, relays or mains voltages before so naturally I'm going to require some guidance with this. I've done a bit of research and found that I'll need a signal diode in reverse bias placed in parallel with the coil, to prevent damage to the Arduino because the coil can give out high voltages when switching. I also found that I think I'll need a resistor between the Arduino digital pin and the transistor, I assume to limit the current drawn by the transistor. Based on these findings I've drawn up a schematic of what I think will be the circuit I'll be building.
'J1' will be the output of the switched mains supply which I'll be plugging a lamp into, which according to what I've read up on, is unlikely to draw any more than 1A from the supply.
I'd appreciate any advice or adjustments that I'll need to make to the circuit, and also I hope to find out whether or not I've made any rookie errors in the design! Thanks in advance.
I'd also recommend a resistor from base-to-emitter of Q1. When the Arduino is in reset (or before you grab control of the D4 pin), there may be enough leakage current to turn it on. If the base resistor is 1k (not a bad choice), the base-to-emitter resistor should be 10k (not critical).
Your diode D1 is a good idea but it is backwards.
Most unclear is how you have your mains hooked up through the relay and to the output. It's just...not clear....
--
The Ruggeduino: compatible with Arduino UNO, 24V operation, all I/O's fused and protected
Thanks, I've added the resistor you suggested to the schematic, and I've just had another think about the way I've wired up the mains supply and realised I got a little confused. I've now amended it, so that the relay only switches the live wire and the neutral just goes straight from the input to the output.
EDIT: Never mind, I see what I've done wrong now, I've actually got it in forward bias in the schematic, rather than 'backwards', how it should be. Thanks for pointing that out, I really shouldn't be designing circuits at 1:48PM!
People sometimes like having the input to the COM terminal, as I've shown.
I prefer having the Line come in on the NO and go out on the COM, as that way there's no voltage on the NC terminal to get bit on later. A personal preference.
Ah okay, I see. I suppose in my situation there isn't really any difference between having the supply on COM and output on NO or having the supply on NO and the output on COM. Thanks for the help, I'll be sure to pay extra attention to the polarity of the diode when I'm building this thing!
12V going to the coil, which will be provided by a 9V battery and two 1.5V batteries in series.
Although this is technically correct to get a desired voltage, rather then mixing battery types it would be better to get a 12V DC wall plug to power your relay (and arduino through the power jack, if you want)
From a drawing clarity point of view you should also have ALL the mains side circuitry outside the low voltage circuit so that it immediately obvious that the two circuits are separate. Minor point maybe but it avoids confusion.