Help with Love-O-Meter (Starterkit Project #02)

Hello, I am just starting out with arduino and have already run across a problem I just can't understand. I am trying to work my way through the project booklet provided with my official Arduino starterkit. I spent a lot of time attempting to get things to work, but my readings were erratic, too low and something obviously wasn't right. After some scouring the internet, I realised that I had been using the supplied BC547 transistors in place of a temperature sensor. However it seems that the temperature sensor that's supposed to be included in the kit (the TMP36) is nowhere to be seen. (Hence why I had been mistakingly using the wrong componant)

I concluded that sometimes parts are accidentally not included in kits like these, as mistakes happen, so went ahead and ordered myself a couple of TMP36s off eBay.

However, upon using the TMP36 in the circuit (which is structured exactly the same way as in the book, and with the original source code for this project), I am still getting the same problem! Only now, my results are far too high, instead of too low. And not quite as erratic but still clearly not stable.

I am wondering if my use of transistors in the circuit could have damaged something? Or if my new TMP36s are slightly different to the one I am supposed to have.

I have tried connected the TMPs middle pin to different analog inputs with no success.

As a beginner, I'm really at a complete loss as to what is going on. Please can you advise?

Results I'm getting in the serial monitor:

sensor Value: 942, Volts: 4.60, degrees C: 409.96
sensor Value: 930, Volts: 4.54, degrees C: 404.10
sensor Value: 945, Volts: 4.61, degrees C: 411.43
sensor Value: 940, Volts: 4.59, degrees C: 408.98
sensor Value: 930, Volts: 4.54, degrees C: 404.10
sensor Value: 946, Volts: 4.62, degrees C: 411.91
sensor Value: 939, Volts: 4.58, degrees C: 408.50
sensor Value: 932, Volts: 4.55, degrees C: 405.08
sensor Value: 947, Volts: 4.62, degrees C: 412.40
sensor Value: 936, Volts: 4.57, degrees C: 407.03
sensor Value: 933, Volts: 4.56, degrees C: 405.57
sensor Value: 948, Volts: 4.63, degrees C: 412.89
sensor Value: 934, Volts: 4.56, degrees C: 406.05
sensor Value: 935, Volts: 4.57, degrees C: 406.54
sensor Value: 948, Volts: 4.63, degrees C: 412.89
sensor Value: 933, Volts: 4.56, degrees C: 405.57

Love-o-Meter code:

// named constant for the pin the sensor is connected to
const int sensorPin = A0;
// room temperature in Celcius
const float baselineTemp = 20.0;

void setup() {
  // open a serial connection to display values
  Serial.begin(9600);
  // set the LED pins as outputs
  // the for() loop saves some extra coding
  for (int pinNumber = 2; pinNumber < 5; pinNumber++) {
    pinMode(pinNumber, OUTPUT);
    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: ");
  Serial.print(sensorVal);

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

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

  // 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;
  Serial.println(temperature);

  // if the current temperature is lower than the baseline
  // turn off all LEDs
  if (temperature < baselineTemp + 2) {
    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);
  }
  delay(1);
}

I have things set up like this (as per the booklet):

Please help me. Been struggling with this for days. :confused:

EDIT: Putting heat / cold around the sensor, does not appear to alter the readings.

I have things set up like this (as per the booklet):

Yes but what have you done, you think it is the same but we can't tell. Please post a photo showing all your wiring.

Grumpy_Mike:
Yes but what have you done, you think it is the same but we can't tell. Please post a photo showing all your wiring.

Well the good news is that it looks to be OK, but as it doesn't work then some of the wires round the temperature sensor must not be making contact. Try making it three holes down and rocking the wires and the sensor to try and make a good contact.
This is the down side of using Solderless breadboard, it is often poor at making contact.

Grumpy_Mike:
Well the good news is that it looks to be OK, but as it doesn't work then some of the wires round the temperature sensor must not be making contact. Try making it three holes down and rocking the wires and the sensor to try and make a good contact.
This is the down side of using Solderless breadboard, it is often poor at making contact.

Moved it down. Been through every single connection whilst watching the serial monitor. But still not working unfortunately. :frowning:

Hi,
Lift the sensor out, then connect A0 to gnd then to 5V.
Tell us what your values are..

Thanks.. Tom... :slight_smile:

TomGeorge:
Hi,
Lift the sensor out, then connect A0 to gnd then to 5V.
Tell us what your values are..

Thanks.. Tom... :slight_smile:

A0 connected to GND:
Stable values of:

sensor Value: 0, Volts: 0.00, degrees C: -50.00

A0 connected to V5:
Stable values of:

sensor Value: 1023, Volts: 5.00, degrees C: 449.51

Simply removing the sensor but keeping everything else exactly the same:

sensor Value: 376, Volts: 1.84, degrees C: 133.59
sensor Value: 381, Volts: 1.86, degrees C: 136.04
sensor Value: 371, Volts: 1.81, degrees C: 131.15
sensor Value: 377, Volts: 1.84, degrees C: 134.08
sensor Value: 380, Volts: 1.86, degrees C: 135.55
sensor Value: 371, Volts: 1.81, degrees C: 131.15
sensor Value: 378, Volts: 1.85, degrees C: 134.57
sensor Value: 377, Volts: 1.84, degrees C: 134.08
sensor Value: 370, Volts: 1.81, degrees C: 130.66
sensor Value: 379, Volts: 1.85, degrees C: 135.06
sensor Value: 376, Volts: 1.84, degrees C: 133.59
sensor Value: 371, Volts: 1.81, degrees C: 131.15
sensor Value: 380, Volts: 1.86, degrees C: 135.55
sensor Value: 376, Volts: 1.84, degrees C: 133.59
sensor Value: 374, Volts: 1.83, degrees C: 132.62
sensor Value: 383, Volts: 1.87, degrees C: 137.01

EDIT: I have just tried the circuit with another new TMP36 and I am now getting much more realistic results. I guess the TMP36 I was using was faulty perhaps? Results are still a tiny bit jumpy but if put that down to what Mike said about breadboards, then it seems like the problem is gone!

sensor Value: 142, Volts: 0.69, degrees C: 19.34
sensor Value: 143, Volts: 0.70, degrees C: 19.82
sensor Value: 143, Volts: 0.70, degrees C: 19.82
sensor Value: 143, Volts: 0.70, degrees C: 19.82
sensor Value: 143, Volts: 0.70, degrees C: 19.82
sensor Value: 143, Volts: 0.70, degrees C: 19.82
sensor Value: 143, Volts: 0.70, degrees C: 19.82
sensor Value: 143, Volts: 0.70, degrees C: 19.82
sensor Value: 143, Volts: 0.70, degrees C: 19.82
sensor Value: 143, Volts: 0.70, degrees C: 19.82
sensor Value: 142, Volts: 0.69, degrees C: 19.34
sensor Value: 143, Volts: 0.70, degrees C: 19.82
sensor Value: 143, Volts: 0.70, degrees C: 19.82

sensor Value: 143, Volts: 0.70, degrees C: 19.82
sensor Value: 142, Volts: 0.69, degrees C: 19.34
sensor Value: 143, Volts: 0.70, degrees C: 19.82

You can expect any analogue to digital converter to return a value plus or minus one least significant bit. So a variation like this is perfectly normal and is to be expected. This applies to all analogue to digital converters not just the one in the Arduino.

Grumpy_Mike:
You can expect any analogue to digital converter to return a value plus or minus one least significant bit. So a variation like this is perfectly normal and is to be expected. This applies to all analogue to digital converters not just the one in the Arduino.

Very good to know for the future!

Thank you for your help both of you. :slight_smile: