Building Love-O-Meter by using a temperature sensor

This "Love-O-Meter" is based on the tutorial by Arduino and it comes with the starter kit. It uses a temperature sensor to measure the warmth of your skin and then starts to turn on (or off) the LEDs  indicated by the temperature.


The components
  • Arduino UNO
  • Breadboard
  • Jumper wires
  • LEDs
  • 220 ohm resistors
  • TMP36 temperature sensor


Building the Circuit

At first I ran the "Hello World" for Arduino to make sure the environment would work as expected. Now I could start to connect the jumper wires between Arduino UNO and the breadboard.

As usually I connected the breadboard to power (5V) and to the ground (GND). I inserted the TMP36 on the breadboard so the rounded part of the sensor would face away from Arduino.

I attached 3 LED lights and the resistors and connected them with Arduino. The lights should react to the heat of the finger and if the temperature would get hot enough all the lights would be on and would also tell you if you are a hot lover or not...

The circuit

The result and the code

Everything worked like a charm and my love-o-meter was ready for action. The components worked fine together and I was happy with the result. When I held my finger on the sensor the blue LED turned on and after a while the yellow started to shine too.


/*
  Arduino Starter Kit example
 Project 3  - Love-O-Meter
 
 This sketch is written to accompany Project 3 in the
 Arduino Starter Kit
 
 Parts required:
 1 TMP36 temperature sensor 
 3 red LEDs
 3 220 ohm resistors
 
 Created 13 September 2012
 by Scott Fitzgerald
 
 http://arduino.cc/starterKit
 
 This example code is part of the public domain 
 */

// 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){
    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);
}




Sources http://arduino.cc/en/ , Arduino Projects Book
Based on the prototype course by Tero Karvinen (http://terokarvinen.com/and the book - Karvinen 2011: Make Arduino Bots and Gadgets 

Comments

  1. Just playing around with this.
    Is there a way to take a sample of the current ambient temperature and set that as the baseLine - instead of manually setting?

    ReplyDelete
    Replies
    1. If you read the temperature for a few cycles during the setup loop you could assign this value to a variable and use that as your baseline temperature instead of the hardcoded 20.0 degrees.

      Delete
    2. Chris, what would this look like in code? Do I need to return this baselineTemp so it can be used as input in the loop, or ...?

      Delete
    3. for what it's worth, I defined a float baselineTemp (not a constant). Each cycle in the loop he checks if the measured temperature is lower than the baselineTemp.

      if (temperature < baselineTemp){baselineTemp = temperature;}

      Normally this should (after a few cycles) result in the baselineTemp being the same as the room temperature .

      Delete
  2. Replies
    1. u just look at the codes of the leds then add for example

      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);
      }
      delay(1);
      \


      the n just add

      Delete
  3. I'm new to arduino, what size battery do I need to power this circuit?

    ReplyDelete
    Replies
    1. Thanks for your comment! I would use a 9V Battery and a suitable snap connector.

      Delete
  4. Can I hook up some other microvolt supply to the Love-O-Meter circuit? I want an analog style LED meter that can demonstrate the tiny volt levels.

    ReplyDelete
  5. bonjour j ai copier à l identique et j ai: expected "or" ;before "const" status 1 expectes',' or ';' before'const' pouvez vous m aider... :)

    ReplyDelete
  6. I am working on the love-o-meter project and using the manual that comes with the kit for project 3. I used the code that comes preloaded in the software.. When I touch the sensor the 1 LED lights up and then after a while the second one lights up. The third LED in the project never lights up. Is it not supposed to? Tried changing code and playing around with baseline temp. Any thoughts are welcome

    ReplyDelete
  7. Hi,

    I have completed the first part but does anyone know how to do the interface with 2 people?
    I guess you might have to duplicate all inputs and then if both people's temperatures satisfy the certain temperature condition then red LEDs would light up if both peoples temperatures are within the same range.

    Here is my code i've guessed would look something like

    void setup() {
    // put your setup code here, to run once:
    Serial.begin(9600); // Opens the serial port

    for(int pinNumber = 2; pinNumber < 5; pinNumber++){
    pinMode(pinNumber,OUTPUT);
    digitalWrite(pinNumber,LOW);
    }

    }

    void loop() {
    // put your main code here, to run repeatedly:
    const int sensorPin1 = A0;
    const int sensorPin2 = A1;
    const float baselineTemp = 20.3;
    int sensorVal1 = analogRead(sensorPin1);
    Serial.print("Sensor Value: ");
    Serial.print(sensorVal1);

    int sensorVal2 = analogRead(sensorPin2);
    Serial.print("Sensor Value: ");
    Serial.print(sensorVal2);

    float voltage1 = (sensorVal1/1024.0) * 5.0; // Get the voltage value from ADC reading
    Serial.print(" Volts: ");
    Serial.print(voltage1);

    float voltage2 = (sensorVal2/1024.0) * 5.0; // Get the voltage value from ADC reading
    Serial.print(" Volts: ");
    Serial.print(voltage2);

    Serial.print(" degrees C: ");
    float temperature1 = (voltage1 - .5) * 100;
    Serial.println(temperature1);

    Serial.print(" degrees C: ");
    float temperature2 = (voltage2 - .5) * 100;
    Serial.println(temperature2);


    // If temperature is less than baseline then LEDs are all off
    if(temperature1 < baselineTemp || temperature2 < baselineTemp){
    digitalWrite(2, LOW);
    digitalWrite(3, LOW);
    digitalWrite(4, LOW);
    } else if(temperature1 >= baselineTemp+2 && temperature1 <= baselineTemp+4 && temperature2 >= baselineTemp+2 && temperature2 <= baselineTemp+4){
    digitalWrite(2, LOW);
    digitalWrite(3, LOW);
    digitalWrite(4, HIGH);
    } else if(temperature1 >= baselineTemp+4 && temperature1 <= baselineTemp+6 && temperature2 >= baselineTemp+4 && temperature2 <= baselineTemp+6){
    digitalWrite(2, LOW);
    digitalWrite(3, HIGH);
    digitalWrite(4, HIGH);
    } else if(temperature1 >= baselineTemp+6 && temperature1 >= baselineTemp+6){
    digitalWrite(2, HIGH);
    digitalWrite(3, HIGH);
    digitalWrite(4, HIGH);
    }
    delay(1);
    }



    ReplyDelete

Post a Comment

Popular Posts