Use ATtiny2313A as uC and DS18B20 as thermal sensor for a greenhouse

Started by Yeetan, April 09, 2018, 04:01:33 AM

Yeetan

I'm working on a thermal regulator for a greenhouse. My device will use ATtiny2313A as uC and DS18B20 as thermal sensor. I also use 1602 LCD display to monitor current temperature and set low and high limits for the heater system.

I want to be able to drive heater load for about 2kW (I'm from Russia so in my 230VAC line it will be about 10 amps). I use relay 507-1AH-F-C to commutate heater load. Actually I will break the Live line (which also have the fuse 10A @ 250VAC) while Neutral line will stay connected. As I understood from datasheet this relay can handle 12A @ 250VAC so things look pretty good to me. Coil voltage is 5VDC and I use KSP44 transistor in switch mode to handle such a heavy load (about 106 uA) by uC.

When I was in developing phase, I used breadboard to debug firmware for ATtiny2313A. During test phase, I was able to see some strange glitches such as random restarts of uC or even EEPROM corruption. I've measured some voltages and discovered that display backlight and relay coil causes serious voltage drop on breadboard rails (about 0.2 volts).

Because of this I decided to make two power sources, which are built on LM7805CT linear regulators. One LM7805 is mounted on the heatsink and supplies power exclusively for relay coil and LCD backlight. The second LM7805 supplies power only to the DS18B20 and ATtiny2313A. Somewhere in the Internet I read that using two linear regulators in such manner is a bad idea.

So because this is my first full-cycle (schematics developing, PCB routing etc) project, I want to learn as much as possible and avoid potential pitfalls. Here I attached the schematics, routed PCB and 3D models of it. I would be very grateful if anyone from the community would tell me some useful advice or point to my errors. I'm only a beginner and want to dive into the world of electrical engineering.

There are main questions of the greatest importance to me:

    Is it bad practice to use two or more LM7805s in parallel? In my case they have common grounds. Generally I have solid ground planes on the both sides of PCB.

    I use transistor in switch mode. For my calculations I assumed that hFE = 20, Base-Emitter voltage drop is 0.8 volts and Vout for ATtiny2313A is 4.2 volts. I think that it will be OK that collector current is about 150 uA (although relay coil consumes 106 uA) so my math for base resistor is:

    (4.2 - 0.8 ) / 0.150 * 20 = 453 ohm

    I took 680 ohm for my R2 value. Is there any miscalculations in that scheme? Also I wonder if there will be any pitfalls because collector is powered from +5V line (the first LM7805) while base is driven by VCC line (the second LM7805)?

    How can I efficiently find and understand ground loops? I tried to separate logic and power parts of my scheme and use solid ground zones, but I am concerned if any loops still exist.

    Is my variant of snubber for relay good? Or are there improvements which could be introduced? I've read Application Note which stated that this variant should work well, but I want to know real user experiences.

Thank you!

TomWS

Quote from: Yeetan on April 09, 2018, 04:01:33 AM
There are main questions of the greatest importance to me:

    Is it bad practice to use two or more LM7805s in parallel? In my case they have common grounds. Generally I have solid ground planes on the both sides of PCB.
The two LM7805s are not in parallel, they are powering separate circuits from the same raw DC supply and this is ok.  However, I'm not sure that two are necessary.  It isn't clear what package you're using for the LM7805, but if it's a TO220 package, one will easily handle the load of your entire circuit.  However, you also don't mention how much voltage the transformer passes and this will affect your power calculation.

Quote
    I use transistor in switch mode. For my calculations I assumed that hFE = 20, Base-Emitter voltage drop is 0.8 volts and Vout for ATtiny2313A is 4.2 volts. I think that it will be OK that collector current is about 150 uA (although relay coil consumes 106 uA) so my math for base resistor is:

    (4.2 - 0.8 ) / 0.150 * 20 = 453 ohm

    I took 680 ohm for my R2 value. Is there any miscalculations in that scheme?
First, the nomenclature of "106 uA" means 106 micro Amps.  I think you mean milliAmps which is much more reasonable for that relay coil anyway.  Your math is also consistent with 'milliamps', so that is correct as well.  I think the hFE you're using is conservative, I'd use 50 or so, but, if you're going to use the conservative value to calculate a resistor of 453 ohm, you should stick to this and use no more than a 470 ohm resistor rather than arbitrarily increasing it to 680 because you 'know' that you have some margin.  It's better to use a more realistic hFE in the calculation and, if anything, use a slightly lower resistor, in my opinion.
Quote
Also I wonder if there will be any pitfalls because collector is powered from +5V line (the first LM7805) while base is driven by VCC line (the second LM7805)?
No, this is ok because the emitter is on a common ground with the processor.
Quote

    How can I efficiently find and understand ground loops? I tried to separate logic and power parts of my scheme and use solid ground zones, but I am concerned if any loops still exist.
Since you didn't show the ground pours in the PCB drawing, it's hard to tell, but, at first glance, your circuit is simple and contained enough that I doubt you'll have an issue.
Quote
    Is my variant of snubber for relay good? Or are there improvements which could be introduced? I've read Application Note which stated that this variant should work well, but I want to know real user experiences.

Thank you!
A simple diode (just the 1N4001) across the relay coil should be sufficient, the zener diode is unnecessary, IMO.

Tom

perky

The zener is usually to allow the energy in the coil to dissipate more quckly when it is turned off, it's used sometimes for high powered relays with high coil currents but as Tom says not really necessary for a small relay coil like this.

I would suggest putting an MOV across the AC pins on the relay. I'm not sure what construction the heater element is but it may have an inductive component, the MOV should help to protect the contacts from arcing over.

Mark.