There's an even better fix, though, and it hinges on the fact that the temperature sensor I'm using, the TMP36, has the same output over a wide voltage range (2.7V to 5.5V). By default, the Uno uses the 5.0V regulated voltage as the ADC reference voltage (AREF). It is possible, though to wire an external voltage to the AREF pin and use that voltage as the ADC reference. As it so happens, the Uno has a second regulated voltage on-board: a 3.3V supply. I verified that whether the relay is open or closed, the supply provides 3.3V.
It was a simple matter to make the hardware change and wire the 3.3V pin to the AREF pin. I also added a capacitor across AREF and ground to help stabilize the voltage, something I should have done before. I left the temperature sensor on 5V; it puts out the same voltage whether powered by 3.3V, 4.93V, or 5.03V. The software changes were also straight-forward: tell the Uno to use the externally provided voltage on the AREF pin as the ADC reference and change one line of code used in converting the ADC value, having it use 3.3V instead of 5.0V in the calculation.
The proof is in the pudding, as they say:
Trevor, does anybody understand this? As a faithful mom I read it, but I don't really get it.
ReplyDelete