TMP36 temp sensor with an LED

So, I’m just learning about electronics and the Arduino Uno and I’ve run into something that has me puzzled. I’ve set up a simple circuit which reads input from a TMP36 sensor. My sketch converts this input voltage to a temperature value. I have this working fine and the temperature readings are stable and accurate enough for my educational purposes. Next I added an LED to the circuit and programmed it to turn on when the temperature reading falls below a given threshold value. This works fine too, sort of… I’ve noticed that when when LED is turned on, the reading from the TMP rises about 3 or 4 degrees F. When the LED is turned back off, the temperature drops back down to where it was and remains stable again. Can anyone explain to me what is happening to the TMP36 when the LED is turned on and off? If so, what can I do to prevent this at the hardware level?


Please supply the code and a clear circuit of how you have wired the project.


read this article:
You should add some delay betwen ADC readings to give time for the arduino switch ADC ports.

I'm also having some bad reading when hooking TMP36 with other sensors, if i use it alone, readings are more stable. Im my case adding delays didn't improve.

Did more tests and found that if i power TMP36 with 3,3V, readings are more stable than power it with 5V.

Thanks for the replies. I'm in the process of learning how to use the website to simulate my circuits, so once I have that figured out I think it will be easier for me to attach an image of what I am doing with the hardware.

I have done a couple of additional experiments to figure this out. My lack of electronics knowledge is really a hindrance, but I think I'm starting to understand a bit.

First, I disconnected the external LED I was using and just used the built-in LED attached to pin 13 on the arduino board. The problem went away. The TMP36 readings became stable whether or not I was activating the LED. Great. So, having that external LED running in parallel with the TMP36 circuit is messing up the reading from the sensor. Next, I wired the LED up on a separate breadboard with its own power supply to isolate it. I put a transistor in that circuit and wired it to an output pin on the Arduino so that I could switch the LED on and off. This solved the problem too.

I've learned something here. I'm just not sure what exactly. I think I need to learn how to use my multimeter with these circuits. :slight_smile:

It has been suggested previously that you do two consecutive readings of the analogue so that the electronics is "primed" for the actual (second) read.


It has been suggested previously that you do two consecutive readings of the analogue so that the electronics is “primed” for the actual (second) read.


That makes sense. I’ll try that.

If you read the A/D value with default Aref, things are as stable as the power supply (= bad).
Better to read the sensor against internal 1.1volt Aref.
Downside of that is temp range with a TMP36 is then limited to -40 to ~55C.
A TMP35 (LM35) has a range from ~2 to ~105C with 1.1volt Aref.
Try this code I wrote. Works with LCD shield and serial monitor.
Read the TMP35/36 part (line 5).

// TMP35 or TMP36 temp sensor connected to Analogue input A1, 3.3volt and ground
// or LM35 temp sensor connected to A1, 5volt and ground
// temp range ~2C to ~105C
// display on serial monitor and/or LCD
// for a TMP36 (-40C to ~55C), change line 45 to:   tempC = total * Aref * 0.1 / numReadings - 50.0;
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7); // your LCD pins could be different
byte ledPin = 10; // backlight pin
const byte numReadings = 32; // number of readings for smoothing (max 64)
int readings[numReadings]; // readings from the analog input
byte index = 0; // index of the current reading
unsigned int total = 0; // running total
int inputPin = A1; // the pin that the TMP35 is connected to
float Aref = 1.0759; // change this value to the actual Aref voltage of ---YOUR--- Arduino (1.0 - 1.2), or adjust to get accurate readings
float tempC; // Celcius
float tempF; // Fahrenheit

void setup() {
  //analogWrite(ledPin, 200); // optional dimming
  analogReference(INTERNAL); // use the internal ~1.1volt reference | change (INTERNAL) to (INTERNAL1V1) for a Mega
  Serial.begin(115200); // ---set serial monitor to this value---
  lcd.begin(16, 2); // shield with 2x16 characters
  lcd.print("Thermometer"); // info text
  lcd.setCursor(0, 1); // second row
  lcd.print("0-100 Celcius");
  for (index = 0; index < numReadings; index++) { // fill the array for faster startup
    readings[index] = analogRead(inputPin);
    total = total + readings[index];
  index = 0; // reset
  delay(2000); // info display time

void loop() {
  total = total - readings[index]; // subtract the last reading
  readings[index] = analogRead(inputPin); // one unused reading to clear ghost charge
  readings[index] = analogRead(inputPin); // read from the sensor
  total = total + readings[index]; // add the reading to the total
  index = index + 1; // advance to the next position in the array
  if (index >= numReadings) // if we're at the end of the array
    index = 0; // wrap around to the beginning

  // convert value to temp
  tempC = total * Aref * 0.1 / numReadings; // value to celcius conversion
  tempF = tempC * 1.8 + 32; // Celcius to Fahrenheit conversion

  // print to LCD
  if (total == 1023 * numReadings) { // if overflow
    lcd.print("---TOO HOT---");
  else {
    lcd.print(tempC, 2); // two decimal places
    lcd.setCursor(6, 0); // position 6, first row
    lcd.setCursor(0, 1); // second row
    lcd.print(tempF, 1); // one decimal place
    lcd.setCursor(6, 1); // position 6, second row

  // print to serial monitor
  Serial.print("Raw average = ");
  Serial.print(total / numReadings);
  if (total == 1023 * numReadings) {
    Serial.println("  ----too hot----");
  else {
    Serial.print("   The temperature is  ");
    Serial.print(tempC, 2);
    Serial.print(" Celcius  ");
    Serial.print(tempF, 1);
    Serial.println(" Fahrenheit");

  delay(1000); // use a non-blocking delay when combined with other code