Hi,
I am trying to build a simple Arduino controlled thermostat. To read the temperature I am using a Temperature Sensor (LM19) and a Relay (G5V-2) to control the heater.
Separately, both worked fine but I have noticed that when the relay switches on or off the temp. sensor reading jumps a bit (2-3 C). Apparently, it is a common problem (and from what I have understood the coil takes too much power) and people recommend using a transistor to switch the relay.
My question is, why do I need the relay when I already have the transistor that (from my very uneducated point of view) does pretty much the same (and some tutorials uses transistors for thermostats only).
What are the advantages/disadvantages of relays and transistors in this case? And what solution would you recommend?
The disadvantage of an analogue temp sensor read with Arduino's default Aref is that the returned A/D value depends on the supply voltage of the Arduino. There will always be an increase/decrease in temp when you switch a load (relay, LED) that is powered from the same supply.
If you had used an LM35, then you could have switched to the more stable internal 1.1volt Aref.
Digital temp sensors, like the DS18B20, are a much better solution.
Leo..
My bad, sorry, should have thought of that. The thing is that I am not totally decided on these things. It will either be a thermostat controlling a temperature in a terrarium (in this case powered by a notebook charger (12-20V, about 100W) or it will be a thermostat controlling boiling of few liters of water (then probably powered from the main grid). I understand that these are totally different circuits, but I am now mostly trying to find out why and when is a relay with transistor better than simply transistor and vice versa.
BTW, I understand that the relay currently used would not withstand any of these choices, but was the only one currently laying around.
To switch mains power, you need the isolation from a relay module or SSR (solid state relay).
A relay module draws ~80mA@5volt, which could be bad for your analogue temp sensor.
An SSR could be happy with 2-5mA.
I think a low voltage heating element is better switched with a logic level mosfet.
5-8Amp DC is hard on relay contacts.
Leo..
That is a hefty topic, Padawan. Hard to answer without writing a book. But, basically:
A relay provides electrical isolation from the thing being switched. But, driving it takes special considerations, like:
the need for a back EMF absorbing diode.
the possible need for current amplification.
the possible need for voltage translation.
or both current amplification AND voltage translation.
A relay can switch both DC and AC, but being mechanical, it suffers from certain drawbacks:
the contacts tend to have a lower Mean Time Before Failure [MTBF], than a solid state device. In other words they wear out faster. If the transition rate is low, then this may not be a problem, but if it's cycled often, it may prove less reliable.
they tend to be audibly noisy.
they are more likely to be a source of radio interference and to impart electrical noise into a circuit.
they typically require more drive current than a solid state device (especially in comparison to a MOSFET or a Solid State Relay [SSR]).
A "transistor" can only, by itself, switch DC [I put *transistor* in *quotes* because there's more than one type of transistor].
There is, also, the Triac or Quadrac -- which, I confess, I don't know a lot about. One, or both, of those can be used to switch AC.
Did I leave anything out [I mean, in terms of just the basics--excluding all those excruciating details]?
For your sensor, it seems the voltage output can go as high as 2.5V at -50°C.
To stabilise your output, indeed you best use the internal reference. You're limited to voltages of up to about 1.1V (there's a 10% tolerance in that voltage so you need to calibrate but otherwise it's stable). The moment the input goes over 1.1V but remain under Vcc you should still be safe, but you will get a 1023 reading regardless. Whether that's a problem for you I don't know - this would be for temperatures below about 60°C.
Otherwise add a voltage divider (e.g. 2x 10k resistors) to the output of the sensor to bring down the voltage.
gumavkleci:
from what I have understood the coil takes too much power
I would rather say: whatever you use to power that relay can't supply enough current, or is not well stabilised.
The most important point to make here is that if you are connecting your creation to the mains in any way make sure you have an appropriate isolation barrier between the hazardous voltage and anything conductive that you will / might / could / maybe touch.
Relays have some degree of isolation between coil and contacts and some have sufficient isolation to satisfy the requirements for double or reinforced insulation which is what is typically required between mains and SELV (the usual 5V and 12V type stuff etc etc where there is no barrier between you and the low voltage conductors). I don't think the g5V has anything special to offer as far as isolation barriers are concerned but this one Compact power relay guarantees 8mm creepage distance does and there are loads of other models from the usual manufacturers also offering 8mm and 10mm barriers. You should probably be aiming for a minimum of 6.4mm for both creepage and clearance distances if you are switching mains (230VAC) voltages.
Relays, like all mechanical switches, are not so good with reactive loads (C or L) but quite ok with a resistive load up to a fair number of switching actions and high currents.
A solid state switch (transistor) though, does not wear out like a mechanical switch and some solid state relays will also provide the safety barrier (isolation barrier).
As others have pointed out, driving a mechanical relay directly from a uC is just not a good idea. A small SOT23 MOSFET and a SOT23 diode (for back EMF) and that problem goes away. With something like a ULN2003 the transistors and diodes for 7 independent drives are all built into a single 14 pin chip.
A relay may be more forgiving of accidental short circuits in the load than a transistor but a transistor can switch at very high speeds and at very high frequencies without mechanical failure.
For your application though, with relatively infrequent switching and the possibility of higher voltages or mains voltages and the need for isolation barriers, relays are probably your best choice. This assumes you are not planning some funky proportional control type algorithm.
I hope at least some of that is useful for you.
Unfortunately, I have somehow fried my currently only available Arduino (due to completely unrelated circumstances.. ) bud when I will get a hold of another one I will try the internal reference with the voltage divider. Hopefully, that could solve it.¨
And if that would not work I will get try to control the relay with a transistor.
Hi,
You cannot drive the relay directly, 100mA, from the Arduino output, the controller output cannot supply the needed current.
The solution is to use a transistor or MOSFET to drive the relay.
You have not fitted a back EMF protection diode.