Loading...
Pages: [1]   Go Down
Author Topic: Arduino and LM335 temperature sensor  (Read 252 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 14
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi everyone.

I tried to read value from an LM335 temperature sensor, i used this tutorial http://learn.adafruit.com/tmp36-temperature-sensor/using-a-temp-sensor.
In my room the temperature is 20.2C but the arduino serial monitor  display wrong data like these:
Quote
Sensor value Analog Pin 0: 755.00
Calculated Volt: 3.69
Calculated Milli Volt: 368.65
Calculated Cersius: 95.50
Calculated Fahrenheit:: 203.90
----------------------------------
Sensor value Analog Pin 0: 757.00
Calculated Volt: 3.70
Calculated Milli Volt: 369.63
Calculated Cersius: 96.48
Calculated Fahrenheit:: 205.66
----------------------------------
Sensor value Analog Pin 0: 756.00
Calculated Volt: 3.69
Calculated Milli Volt: 369.14
Calculated Cersius: 95.99
Calculated Fahrenheit:: 204.78
----------------------------------
Sensor value Analog Pin 0: 756.00
Calculated Volt: 3.69
Calculated Milli Volt: 369.14
Calculated Cersius: 95.99
Calculated Fahrenheit:: 204.78
----------------------------------
Sensor value Analog Pin 0: 756.00
Calculated Volt: 3.69
Calculated Milli Volt: 369.14
Calculated Cersius: 95.99
Calculated Fahrenheit:: 204.78
----------------------------------
Sensor value Analog Pin 0: 761.00
Calculated Volt: 3.72
Calculated Milli Volt: 371.58
Calculated Cersius: 98.43
Calculated Fahrenheit:: 209.18
----------------------------------
Sensor value Analog Pin 0: 757.00
Calculated Volt: 3.70
Calculated Milli Volt: 369.63
Calculated Cersius: 96.48
Calculated Fahrenheit:: 205.66
----------------------------------
Sensor value Analog Pin 0: 761.00
Calculated Volt: 3.72
Calculated Milli Volt: 371.58
Calculated Cersius: 98.43
Calculated Fahrenheit:: 209.18
----------------------------------
Sensor value Analog Pin 0: 756.00
Calculated Volt: 3.69
Calculated Milli Volt: 369.14
Calculated Cersius: 95.99
Calculated Fahrenheit:: 204.78
----------------------------------

I used  this code
Code:
// ------------------
    void loop() {
// ------------------

  // Take sample_count temperature readings.  Will calc the average.
 

    sensor = analogRead(sensorPin);
    Serial.print("Sensor value Analog Pin 0: ");
    Serial.println(sensor);
    volt = (5.0 * sensor) / 1024.0;
    Serial.print("Calculated Volt: ");
    Serial.println(volt);
    milivolt = volt * 100;
    Serial.print("Calculated Milli Volt: ");
    Serial.println(milivolt);
    c = milivolt - 273.15;
    Serial.print("Calculated Cersius: ");
    Serial.println(c);
    f = (c * 9/5) + 32;
    Serial.print("Calculated Fahrenheit:: ");
    Serial.println(f);
    Serial.println("----------------------------------");
    delay(1000);
  }
These code i found here on arduino forum :
 
Logged

Offline Offline
Sr. Member
****
Karma: 7
Posts: 386
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

well, millivolt should be volt/1000.0, not volt * 100.0.
Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 69
Posts: 3256
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
well, millivolt should be volt/1000.0, not volt * 100.0.

Hmmm, millivolt = volt * 1000, because 1 Volt is 1000mV.

The page you linked to uses a completely different sensor, I was a bit surprised that you measured anything at all with this wiring. Did you consult the datasheet of your sensor?
Logged

Offline Offline
Sr. Member
****
Karma: 7
Posts: 386
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Oops, he still needs 1000 vs 100, though.
Logged

Sydney
Offline Offline
God Member
*****
Karma: 14
Posts: 717
Big things come in large packages
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Agree on the use of 100 from above. Also make sure you have wired it up properly, although usually you get no reading rather than a wrong one.

Quote
volt = (5.0 * sensor) / 1024.0;

The assumption here is that you have 5 volts. If you are powering the Arduino from a USB port this is probably not the case - it is worth checking with a voltmeter. Remember that you are getting 0-1023 for the full range of the voltage. If you have 4.5 volts you will be 10% out. Sometimes my USB port is as low as 4.2 volts.

At the location in my signature below I have a library that tries to calibrate itself by working out what the voltage actually is, using the internal Arduino voltage reference. I know this library works so it is worth using it to check your hardware setup using it.

Edit: Look at the circuit here: https://github.com/hgdeoro/py-arduino-proxy/wiki/Example%3A-Testing-LM335
« Last Edit: March 01, 2013, 06:03:25 pm by marco_c » Logged


Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 269
Posts: 25392
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes the LM335 and the LM36 are two very different sensors requiring a different way of wiring them up and a different way of converting the reading into a temperature. Apart from that it is fine.
Logged

Pages: [1]   Go Up
Print
 
Jump to: