I have a TMP36 sensor going to pin A1, and an output at digital pin 2 that goes to a SainSmart 4 relay module
The temperature sensor acts normally as far as I can tell. The code runs as expected, and the relay board switches on and off as expected, with LED indicators and audible clicks. I do not have any AC voltage connected at the moment for the relays to switch, but that is the eventual idea.
However, when I write a LOW signal to the relay board IN2 (input for Relay2, which closes the switch), the sensor reading instantly jumps .06 volts, about 10 deg F! It does not do this if Pin 2 is physically connected to the relay board, or when that pin is HIGH.
Everything is sharing the ground and +5 v off the Arduino board. Clearly something on the relay board is affecting the voltage reading. How can I isolate the temperature sensor so this doesn't happen?
This trick applies to all sensors with analogue outputs: connect the sensor GND directly to the Arduino GND, using a separate line for every sensor (star topology). Otherwise current flowing on that line, from other devices like relays, will offset the sensor output voltage, just as you observed.
For precise measurement of analogue voltages you also can add another sensing line, directly from the sensor GND to an analogue input pin, and subtract the reading of that pin from the reading of the sensor input pin (or use differential analogue input if supported by your Arduino).
I tried this solution, but it did not work, since the measured ground value was not changing from 0. I tried moving pins around to no effect as well.
I finally figured out what is going on--the 5V pin drops a few volts when it trips the relay. I don't know if this is because my tablet laptop USB power supply is inadequate, but what I can do is to read the actual high voltage at an analog input pin and use it for the temperature formula. The module is going to be powered by a iphone 1Amp DC converter, so hopefully this will work.