Sunday, November 9, 2014

Measure tempreture using TMP35 sensor

After receiving my LCD this came to my mind, as a weekend project :)

Ingredients

1. Arduino (I'm using uno here)
2. Breadboard with jumper cables (create the prototype)
3. LCD (I'm using 2*16)
4. TMP35 Sensor
5. USB cable

Other than that I have used a potentiometer(variable resistor) to control brightness of the LCD.

Let's configure our LCD first, I have used the following circuit found here[1].



Next step is to configure our temperature sensor. I'm using a TMP35 sensor for this, this provides a voltage output linearly proportional to the temperature. So we have to do some math within our program to output temperature in Celsius.

One more thing, unlike our LCD TMP35 provides analog signal as it's output. So we have to plug in to an analog pin located in Arduino.

Connect Analog out pin (middle one) to the A0 analog pin. Then + pin to the positive bus of our breadboard and - end to the ground bus. (make sure to plug these two pins in correct way, refer following image) 



Now we are good to proceed to our program since we are done with the circuit prototype. Connect Arduino into a computer and open ArduinoIDE to write the sketch.You can find complete sketch here.
#Adding LCD library
#include <LiquidCrystal.h>
#Init LCD library with digital pin 12, 11, 5, 4, 3 and #2   
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);                           
const int sensorPin = A0;
void setup() {
    lcd.begin(16, 2);
    Serial.begin(9600);
}
void loop() {
    #Read the sensor value
    int sensorVal = analogRead(sensorPin);
    #Convert reading to voltage
    float voltage = (sensorVal/1024.0) * 5.0;
    #convert millivolts into temperature
    float temperature = (voltage - .5) * 100;
    lcd.print("Room Temp: ");
    lcd.print(temperature);
    delay(1000);
    lcd.clear();
Now upload this sketch into your Arduino and here is our final outcome :)


[1] http://arduino.cc/en/Tutorial/LiquidCrystal

No comments:

Post a Comment