Skip to main content

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 from this blog

Creating a Bootable USB for Kali Linux

If you are interested to see my documentation about making a bootable USB for Xubuntu please click here!

This USB was made by using the latest version of Xubuntu (the 14.04 release).

Downloading Kali Linux 
23.13. After navigating to https://www.kali.org/ I chose the version that would suit me the best and started downloading the ISO image for 64-Bit system.


USB imaging
22.40. I followed the guide offered by kali.org and used the commandsudo fdisk -lwithout plugging the USB yet. I needed to pay attention to the path of Device Boot (/dev/sdb1). After this I inserted USB and ran the same command again. Now I could see how the name of Device Boot had changed to sdc1. This would be my USB to use.

22.50 It only took a while to format the dd code correctly as the base was already given on Kali's web page. After running the correct command for the first time I got an error message "'/dev/sdc1': Permission denied". In these kind of situations I tend to ask sudo for help an…

Using a button to control the LED light

This time my project was to configure how to build a button that would turn on and off depending if the user is pushing it or not. While holding the button down the LED should stay on until removing the finger.



For this assignment I used the fallowing components:
Arduino UNO and USBJumper wiresLED lightBreadboardButton10k ohm resistor
At first I run the "Hello World" for Arduino and made sure that the LED I was using worked properly (read my previous post).

I attached the button in the middle of the breadboard so the legs were touching the both "sides" of it.


Now I started to connect the jumper wires between the Arduino UNO and the breadboard. In order to get it working like in the sample code (Ardoino > Examples > 02.Digital > Button)
I linked the wires with Arduino's 5V (red wire, positive) and ground (black wire, negative) to the equal holes on the very corner of the breadboard (+ and -). I put the white jumper wire to connect the positive circuit to t…