Interfacing relay with Arduino - Page 1
Forum section: electronics / general

author: Spragnut
author_rank: Contributor
timestamp: June 15, 2018, 10:22:32 pm
content: Hi,First time poster so go easy! I've visited the forum for years but am not normally one for asking questions for some reason, that's about to change! I'm a keen hobbyist, I've done a few board layouts, I'm fortunate enough to work for an OEM with daily access to design engineers for help/criticism. I was etching boards in ferric chloride at 15, but fell out of love with electronics for 13 years until I started working where I do now. Any way enough of the life story!I'm working on a project using an Arduino to monitor Temp/Humidity/RTC, which is displayed on a LCD. The data in also stored on an SD card. The end application is to monitor an incubator for chicken eggs. I enjoy pcb layout so am taking the underlying Mega2560 layout and tweaking it and designing my own based on what I need above. Ultimately I will 3D print an enclosure to house it all.I've so far got everything working above, I've now decided I'd like to add a few relay outputs for handling heating elements and other bits and pieces, and possibly a mains driven motor for automatic egg turning. Although I may convert this to a servo for more accurate control.I've currently got the system being powered either by USB or 12V DC, regulators then give me 5V (from 12V) & 3V3. I've picked out some latching relays to conserve power, (I may add battery power as an option later on).The point of the post is mains isolation from DC side, I've seen various suggestions ranging from opto, mechanical slots, relay is enough etc.Whats the best approach? Cost isn't really a concern as these are unlikely to go into mass production as incubators with inbuilt systems already exist (buying one isn't this much fun though).I'd like if possible to power the coils from the common 5V rail, this obviously gives a non isolated route back to the Mega2560, data from Arduino can still be done through an opto. Another thought is to power a separate AC-DC converter with the mains input that will then be switched to the outputs by the relays. This would completely isolate the two systems by utilising an opto.The only reason for preferring the first option is I may use this for switching 12V DC loads as well, thus the AC-DC converter idea wouldn't work without adding some provisions for input power selection. Again this could be done but I think it all gets a bit messy.If it worked the data sheet for the relay should be attached to this post, if not....Anyway, first post and what a whopper.Cheers, James.

author: Siwastaja
author_rank: Super Contributor
timestamp: June 16, 2018, 07:08:32 am
content: Relay is a specifically designed product exactly for this purpose.Just pick a relay with proper safety approvals for switching mains, and keep the required creepage distances between the coil and the mains side. For this, there are too many standards for mere mortals to understand or even obtain, so you usually pick some worst-case universally accepted creepage distance (such as 8mm) that conforms to all relevant standards. If you don't need to use a miniature relay, put a 10mm gap there and you can't go wrong... (Remember to add no-go areas for the ground plane pours.)Routed slot in the PCB can make smaller physical separation acceptable, since now you are not limited by the PCB surface creepage defined by contamination such that dust, dew, etc. Slots are used if you are size constrained, or as an additional safety measure.Note that the freewheeling diode you add in parallel with the coil to prevent voltage spike killing your switching transistor actually slows down the relay, causing more arcing in the contacts than the relay was designed for, meaning shorter lifetime and higher risk of welded contacts. Not usually a problem when switching AC, but alternative ways to get rid of the inductively stored energy faster, without holding the magnitism on so long, are worth studying. Typical solutions include a simple parallel resistor, or a zener, or a combination thereof.

author: Ian.M
author_rank: Super Contributor
timestamp: June 16, 2018, 12:36:04 pm
content: Using 5V relays doesn't do you any favours if there is a higher supply voltage available due to their much higher coil current vs 12V relays of similar size. All the extra current has to come from your 5V regulator, which is problematic for linear regulators without serious heatsinking, or, if you are using a switching regulator, it may force you to choose a higher current one than you would otherwise need. You are partially mitigating that by using a latching relay, so if you have enough bulk capacitance on the 5V rail you may be able to skimp on the regulator, but latching relays are expensive.To drive the single coil latching relay, you need a H-bridge so you can reverse coil polarity. Due to the low coil voltage it will need to be a MOSFET one as you cant tolerate the voltage drop of a bipolar one.If its a two coil relay, all you need is low side MOSFETs and freewheeling diodes across the coils.If you were driving a non-latching relay, a low side MOSFET would do the job, but its often worth adding a resistor approximately equal to the DC coil resistance in series with the freewheeling diode to get a fast turnoff. However that means the MOSFET will have to withstand a spike of double the supply voltage at initial turnoff.As a rule of thumb, simple MOSFETs need a max Vgs threshold voltage of less than half the logic '1' level if you want to be able to drive them direct from an I/O pin.

author: David Hess
author_rank: Super Contributor
timestamp: June 16, 2018, 10:05:34 pm
content: I am a big believer in galvanic isolation between control circuits and power circuits.The problem with mechanical relays is their power requirements.Zero crossing TRIAC based solid state relays cannot be beat for line power applications and you can build your own if necessary. Power MOSFET based solid state relays work for DC loads and are also easy enough to make using photo-voltaic optocouplers.