Go Down

Topic: Project 3 - Love-o-Meter - temperature jumps up too high? (Read 6333 times) previous topic - next topic


Hi, brand new user of Arduino and have a query about Project 3. I've read some other threads on it and I don't think i'm having some issues that I can see covered before.

I believe the circuit is wired correctly and the code is correct (see below). When it first runs I get what appear to be accurate temperature readings eg:

sensor Value: 146, Volts: 0.71, degrees C: 21.29
sensor Value: 146, Volts: 0.71, degrees C: 21.29
sensor Value: 147, Volts: 0.72, degrees C: 21.78
sensor Value: 146, Volts: 0.71, degrees C: 21.29
sensor Value: 145, Volts: 0.71, degrees C: 20.80

All 3 LEDS are off at this stage.

However, as soon as i pinch the TMP36 the temperature seems to spike, eg:

sensor Value: 148, Volts: 0.72, degrees C: 22.27
sensor Value: 182, Volts: 0.89, degrees C: 38.87
sensor Value: 252, Volts: 1.23, degrees C: 73.05
sensor Value: 241, Volts: 1.18, degrees C: 67.68
sensor Value: 240, Volts: 1.17, degrees C: 67.19

The LEDs all come on.

I am definitely using TMP36 not transistor. I think it's wired correctly (have rewired several times). The code I am using is:

const int sensorPin = A0;
// room temperature in Celsius
const float baselineTemp = 20.0;

void setup(){
  // open a serial connection to display values
  // set the LED pins as outputs
  // the for() loop saves some extra coding
  for(int pinNumber = 2; pinNumber<5; pinNumber++){
    digitalWrite(pinNumber, LOW);

void loop(){
  // read the value on AnalogIn pin 0
  // and store it in a variable
  int sensorVal = analogRead(sensorPin);

  // send the 10-bit sensor value out the serial port
  Serial.print("sensor Value: ");

  // convert the ADC reading to voltage
  float voltage = (sensorVal/1024.0) * 5.0;

  // Send the voltage level out the Serial port
  Serial.print(", Volts: ");

  // convert the voltage to temperature in degrees C
  // the sensor changes 10 mV per degree
  // the datasheet says there's a 500 mV offset
  // ((volatge - 500mV) times 100)
  Serial.print(", degrees C: ");
  float temperature = (voltage - .5) * 100;

  // if the current temperature is lower than the baseline
  // turn off all LEDs
  if(temperature < baselineTemp){
    digitalWrite(2, LOW);
    digitalWrite(3, LOW);
    digitalWrite(4, LOW);
  } // if the temperature rises 2-4 degrees, turn an LED on
  else if(temperature >= baselineTemp+2 && temperature < baselineTemp+4){
    digitalWrite(2, HIGH);
    digitalWrite(3, LOW);
    digitalWrite(4, LOW);
  } // if the temperature rises 4-6 degrees, turn a second LED on 
  else if(temperature >= baselineTemp+4 && temperature < baselineTemp+6){
    digitalWrite(2, HIGH);
    digitalWrite(3, HIGH);
    digitalWrite(4, LOW);
  } // if the temperature rises more than 6 degrees, turn all LEDs on
  else if(temperature >= baselineTemp+6){
    digitalWrite(2, HIGH);
    digitalWrite(3, HIGH);
    digitalWrite(4, HIGH);

(I copied and pasted the code from online as the code i typed had similar issues.)

My guess is it's to do with the sensorVal being incorrect? leading to voltage showing as incorrect, thus calculating an incorrect temperature? But i think the code is as it states in the book. 

Any ideas?

Thanks and appreciate the help!


Hi, I've managed to get this working properly by using 560 ohm resistors instead of 220 ohm, as suggested in a different thread i found (https://forum.arduino.cc/index.php?topic=555017.0)

However, i'm still not clear why using 220 ohm resistors caused the jump in values as described in my OP. I have some more reading to do!



Hi, I've been reading up more trying to understand why my readings showed a temperature spike and when all the LEDs came on when using 220 Ω resistors.

(please bare with me - i am a newbie but trying to understand the fundamentals with the help of a physics book!)

My understanding is a 5 V source and a single 220 Ω resistor would have a current of 0.02 A:

I = V/R
   = 5 V / 220 Ω
  = 0.02 A

A red LED with a forward voltage of 1.7 V in a circuit with 0.02 A current would require a 220 Ω resistor:

5 V - 1.7 V = 3.3 V

R = V/I
   = 3.3 V / 0.02
   = 165 Ω

Therefore you use a 220 Ω resistor as it is a 'close match' to 165 Ω.

However, in Project 3 there are three resistors in parallel.

I have worked out the equivalent resistance to be 73.3 Ω


 (5 V - 1.7 V) / 73.3 Ω = 45 mA

Therefore, the current is too great for the LEDs (the Ardunio starter kit book states max is 23 mA for the LED).

Using three 560 Ω resistors I work out an equivalent resistance of 187 Ω


 (5 V - 1.7 V) / 187 Ω = 17.7 mA which is ok for the LEDs

I hope my understanding is correct (but I could be completely wrong!) Is anyone able to confirm? Thanks!

Go Up