I have an Arduino UNO with a TMP36 temperature sensor. Each of the 3 legs is connected to 3 analog pins, with one set to HIGH (5v), one set to LOW (for ground) and the middle pin does the actual voltage readings to compute the temperature.
The readings are completely different depending on whether the Arduino is powered via a USB cable, vs a DC (5v 2a) wall wart. What am I doing wrong? How do I fix this?
Where do you connect the DC supply? If you plug it into the external power input of the Arduino then you will have much less voltage than 5V for the ATmega. The chip will probably run flawlessly with only 4V, but your reference voltage for the measurement will be off.
Solutions:
Use a power supply with at least 7V
or
Use the internal 1.1V voltage reference. This will of course limit you readings to about 60 degrees C
or
Measure the actual Vcc of the ATmega and use it as a reference for your analog readings. This is how I do it. Please modify variable types as needed, I am using integers:
int16_t getVcc() { // Returns actual value of Vcc (in milliVolts), modified code copied from the forum
const int32_t InternalReferenceVoltage = 1100; // assume perfect 1.1V reference voltage, the absolute error does not matter much
// REFS1 REFS0 --> 0 1, AVcc internal ref. -Selects AVcc external reference
// MUX3 MUX2 MUX1 MUX0 --> 1110 1.1V (VBG) -Selects channel 14, bandgap voltage, to measure
ADMUX = _BV (REFS0) | _BV (MUX3) | _BV (MUX2) | _BV (MUX1);
delay(2); // this seems necessary for a stable reading
ADCSRA |= _BV( ADSC ); // Start a conversion
while ((ADCSRA & _BV(ADSC))); // Wait for it to complete
return (int)(((InternalReferenceVoltage * 1024L) / ADC) + 5L); // Scale and round the value
}
int16_t getTemperatureTMP36(uint8_t analogPin) { // returns temperature in tenth of centigrade, for TMP36 sensor
int16_t referenceVoltageADC = getVcc(); // determine current reference voltage for ADC
int32_t value = readAnalogPin(analogPin);
value = (referenceVoltageADC * value) / 1024L - 500L;
return (int16_t)value;
}
Why do you switch the supply AND ground pin.
These sensors use very little current.
If you HAVE to turn the sensor off, you ONLY switch the supply pin.
The temp output is referred to ground. Running ground over an output pin will introduce errors.
The temp readings depend indeed somewhat on Arduino's supply voltage (USB or external).
You can make the reading stable/supply independent by using Arduinos internal reference voltage.
1.1volt Vref limits TMP36's temp reading to ~50-55°C, but it also gives you a 5x better resolution.
Some Arduinos have a 2.56volt Vref. Then you can read to 125°C.
You can make the TMP36 read to ~100°C with 1.1volt Vref, by using a 10k/10k voltage divider.
Post your code if you don't know how to change it.
Leo..
Good point, Wawa
The problem seemed so familiar that I did not carefully read the OP's pin description.
The power and ground pin of the TMP36 should of course be connected to Vcc (or a digital pin set to HIGH) and board GND
I use 7.5 or 9V with Arduinos. My own boards I'll skip regulators altogether and just power from 5V directly unless I also need 12V to power an LED strip.
~5volt on the DC jack is ~4.3volt after the reverse polarity protection diode.
It then goes through the regulator, that removes some more.
If you're lucky, you're left with ~3.5volt on your micro (and A/D converter).
2/3 of what the Arduino gets on USB supply.
The DC jack needs a 9volt regulated wall wart.
7.5volt is better if you can get it (bit less heat in the regulator when shields are used).
7-12volt is usually ok.
5volt is not.
You could feed your 5volt wall wart into the 5volt pin of the Arduino, but be careful. No protection there...
Leo..
Gotcha. Been at this for 2 years now, learn something new every day
I have an Adafruit 5V Trinket, powering a 1M strip of (30) Neopixel LED's, and it seems to work fine, powered by the same 5V 2A wall wart.
What are the ramifications here? Maybe the LED's aren't as bright as they could be and I don't realize it? The chip might be a little unstable?
Under what circumstances would you use a 5V wall wart? (e.g. Adafruit, where I get most of my stuff from, sells them for a reason I guess...)
Thanks as always everyone!
PS: Always looking for good beginner/intermediate electronics books to read if anyone has any recommendations. Robert, already read yours, looking forward to the next one
30 neopixels @ 60mA each (full white) = 1.8A, pushing the limits of the supply.
Could use 2, connect 2nd on to the other end of the strip. Connect both GNDs together.
I use 5V wallwart for any design that doesn't need a higher voltage.
Gotcha. OK. So going to back to my earlier question about the TMP36: if I have the correct voltage coming in (e.g. 9-12, so my 5V, or pin set to HIGH is definitely going to be 5V), then will the ground pin (setting analog pin to LOW) be "safe" such that I can rely on the temperature reading at that point?
Basically what I'm saying is, can I use analog (or digital) pins as my 5V and Gnd for the purposes of this temperature sensor?
Hi
Why do you need to use the I/O pins to power the TMP36.
Why can't you connect
-Ve TMP36 to UNO gnd
+Ve TMP36 to UNO 5V
and signal TMP36 to analog input?