3
\$\begingroup\$

I am working on an AVR project that involves measuring tempereture with an analog sensor (TMP36) and switching a heater on and off through relay to keep the temperature at desired level.

However, I've noticed that every time I switch the relay on, it causes the output voltage of the sensor to instantly drop, quite consistently by 0.01V to 0.02V (it's up to 2°C difference, so not negligible). To check whether that's AVR related problem or not I have constructed a simple test circuit, shown below. I simply enable the transistor by pushing down the button and observe voltage readings at sensor pins with a multimeter. It still shows the same behavior as with the AVR - switching on relay causes the same voltage drop.

enter image description here

Max current of my power supply is 5A, so it shouldn't be a power related problem.

Another important fact is that it doesn't matter if there's anything connected to relay's switching pins - this behavior seems only to depend on the relay coil being switched on and off.

\$\endgroup\$
  • \$\begingroup\$ Does the sensor output stay lower after energizing the relay coil? Does the 3.3V power change at all? \$\endgroup\$ – Clipboard_Waving_Enginerd Jan 25 '19 at 18:03
  • \$\begingroup\$ No, the sensor output goes back to normal level instantly when I switch the relay off. The 3.3V seems to stay quite stable and not affected by relay state. \$\endgroup\$ – Arxair Jan 25 '19 at 18:10
  • \$\begingroup\$ How confident are you that the 3v3 line isn't affected? Have you measured with a scope. Your power capacitor seems small for the size of the load you drive. \$\endgroup\$ – Pier-Yves Lessard Jan 25 '19 at 18:12
  • \$\begingroup\$ Something doesn't add up...a change of 0.2V at the sensor output would correspond to 20°C, not 2°C. Can you clarify this? How are things connected together physically? Do you have a solid ground plane? \$\endgroup\$ – Elliot Alderson Jan 25 '19 at 18:16
  • \$\begingroup\$ 3.3V seems to be rock solid, I have checked at several points. And yes Elliot, my mistake, the voltage changes by 0.01 - 0.02V. There is only one, common ground plane, connected to power supply's ground wire. Excuse me if I'm saying something stupid, I am pretty much a beginner. \$\endgroup\$ – Arxair Jan 25 '19 at 18:29
-1
\$\begingroup\$

There is only one, common ground plane, connected to power supply's ground wire.

This is where your problem is, very likely: a common ground between high-power signal path (inductive relay and 3-A heater), and a sensitive sensor which output is referenced to common ground. The effect frequently happens when power and signal ground are shared and routed improperly. This is called "ground bounce". It is not that the signal changes by 10-20 mV, it is the shift in ground potential between the sensor and MCU due to return current flowing form power part of the design.

To avoid parasitic interference of high-current into sensor readings, the grounding should be done as something along the following lines:

enter image description here

The following ground routing is bad: the MCU will read the actual Vout (which is the true value relative to sensor IC ground) plus the parasitic voltage drop along the power plane.

enter image description here

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Thank you for your answer. However I am not sure if I understand it correctly - are you suggesting that ground outputs of different components should physically "meet" each other in the same point of the ground plane? \$\endgroup\$ – Arxair Jan 25 '19 at 19:16
  • \$\begingroup\$ The ground circuit should be arranged so that the current from the power electronics to the power supply cannot possibly flow through the ground conductor from the sensor to the MCU. The schematic shown is one commonly accepted way to do it. \$\endgroup\$ – TimWescott Jan 25 '19 at 20:09
  • \$\begingroup\$ I think I'm starting to understand this. I will try out some different setups and wirings on a breadboard when I'll be able to, but in conclusion - it is possible for me to keep only one power supply for the entire circuit and get correct temperature readings if I manage to make it the smart way? I would rather not have to rethink the entire project and use separate power supplies for power electronics and sensors/MCU. \$\endgroup\$ – Arxair Jan 25 '19 at 20:41
  • \$\begingroup\$ @Arxair, single power supply is OK, you just need to route the sensor ground properly/separately, without having the relay in the path. \$\endgroup\$ – Ale..chenski Jan 25 '19 at 20:46
  • \$\begingroup\$ I'm sorry, but after spending 1.5 hours leaning over breadboard and switching wires, I still haven't succeeded in solving the issue. I have even connected the relay directly to 12V without transistor, and then attached its other end directly to PS's ground. I think there's still something I just can't grasp about this concept - if all the ground wires have to be eventually connected to the same power supply's ground wire, why would the way they are routed make any difference? \$\endgroup\$ – Arxair Jan 25 '19 at 23:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.