Temperature Sensor + Arduino

14
About (/about/) Photos (/photos/) Archive (/archives/) Contact (/contact/) (http://www.danielandrade.net/) Temperature Sensor + Arduino (http://www.danielandrade.net/2008/07/05/temperature- sensor-arduino/) July 5, 2008 Hello people, it’s been a while since I have posted projects on this website. This semester was really busy, I didn’t have time to much else, but soon I will have my winter holiday (Here in south our summer holiday is from December to February). Today I am going to show you how to build a simple temperature sensor using one LM35 Precision Temperature Sensor and Arduino (http://www.arduino.cc), so you can hookup on your future projects. The circuit will send serial information about the temperature so you can use on your computer, change the code as you will. I’m planning to build a temperature sensor with max/min + clock + LCD, and when I get it done, I will post here. Parts: Arduino (You can use other microcontroller, but then you will need to change the code). LM35 Precision Centigrade Temperature Sensor, you can get from any electronic store. Here is the DATA SHEET (http://www.national.com/ds/LM/LM35.pdf). BreadBoard Assembling: This is a quick and simple step. Just connect the 5V output from arduino to the 1st pin of the sensor, ground the 3rd pin and the 2nd one, you connect to the 0 Analog Input. Down goes some pictures that may help you, click to enlarge:

description

Sensor termico

Transcript of Temperature Sensor + Arduino

  • About (/about/) Photos (/photos/) Archive (/archives/) Contact (/contact/)

    (http://www.danielandrade.net/)

    Temperature Sensor + Arduino(http://www.danielandrade.net/2008/07/05/temperature-sensor-arduino/)July 5, 2008

    Hello people, its been a while since I have posted projects on this website. This semester wasreally busy, I didnt have time to much else, but soon I will have my winter holiday (Here in southour summer holiday is from December to February).

    Today I am going to show you how to build a simple temperature sensor using one LM35Precision Temperature Sensor and Arduino (http://www.arduino.cc), so you can hookup onyour future projects. The circuit will send serial information about the temperature so you canuse on your computer, change the code as you will. Im planning to build a temperature sensorwith max/min + clock + LCD, and when I get it done, I will post here.

    Parts:

    Arduino (You can use other microcontroller, but then you will need to change the code).LM35 Precision Centigrade Temperature Sensor, you can get from any electronic store. Hereis the DATA SHEET (http://www.national.com/ds/LM/LM35.pdf).BreadBoard

    Assembling:This is a quick and simple step. Just connect the 5V output from arduino to the 1st pin of thesensor, ground the 3rd pin and the 2nd one, you connect to the 0 Analog Input.

    Down goes some pictures that may help you, click to enlarge:

  • Here is the Arduino Code, just upload it and check the Serial Communication Option.

    You can also download the .pde HERE(http://www.danielandrade.net/files/temperature_sensor_lm35.pde).

    /*An open-source LM35DZ Temperature Sensor for Arduino. This project will be enhanced on a regular basis(cc) by Daniel Spillere Andrade , http://www.danielandrade.nethttp://creativecommons.org/license/cc-gpl*/

  • 12345678910111213141516171819202122232425262728293031323334353637383940

    int pin = 0; // analog pinint tempc = 0,tempf=0; // temperature variablesint samples[8]; // variables to make a better precisionint maxi = -100,mini = 100; // to start max/min temperatureint i; void setup(){ Serial.begin(9600); // start serial communication} void loop(){ for(i = 0;i< =7;i++){ // gets 8 samples of temperature samples[i] = ( 5.0 * analogRead(pin) * 100.0) / 1024.0; tempc = tempc + samples[i]; delay(1000); } tempc = tempc/8.0; // better precisiontempf = (tempc * 9)/ 5 + 32; // converts to fahrenheit if(tempc > maxi) {maxi = tempc;} // set max temperatureif(tempc < mini) {mini = tempc;} // set min temperature Serial.print(tempc,DEC);Serial.print(" Celsius, "); Serial.print(tempf,DEC);Serial.print(" fahrenheit -> "); Serial.print(maxi,DEC);Serial.print(" Max, ");Serial.print(mini,DEC);Serial.println(" Min"); tempc = 0; delay(1000); // delay before loop}

  • view raw (https://gist.github.com/dansku/5682776/raw/arduino-temperature.ino)

    4041424344454647484950

    arduino-temperature.ino(https://gist.github.com/dansku/5682776#file-arduino-temperature-ino) hosted with by GitHub (https://github.com)

    Anything just ask!!!

    Category: Arduino (http://www.danielandrade.net/category/arduino/), Electronics(http://www.danielandrade.net/category/electronics/), Engineering(http://www.danielandrade.net/category/engineering/), Hardware(http://www.danielandrade.net/category/hardware/), Howto(http://www.danielandrade.net/category/howto/)

    105 Comments daniel andrade Login

    Sort by Best Share

    Join the discussion

    Favorite

  • Reply

    John 3 years agoHi Guys,

    Please what exactly does this line do?:

    samples[i] = ( 5.0 * analogRead(pin) * 100.0) / 1024.0;

    Thank you 15

    Reply

    pritam lunawat 6 months agoi want program of temperature sensor pt100 with arduino freeduino atmega 328..

    2

    Reply

    isme 2 months agoHey @john,That line takes a sample reading(given in ohms(we are reading from a thermistor)) and convertsit to a temperature, then adds it to an array called samples to be averaged in the next step.

    1

    Reply

    pritam lunawat 6 months agopt100

    Reply

    Malin 2 years agoHi!I'm making a project with an sht15-sensor. Do you know how to program it if i want an alarm forexample if temperature is over 20oC (68 F)? I have tried but can't get the function correct.Please help.

    Reply

    Denney Mark 2 years agosir what kind of arduino did you use?

    Reply

    APCC DIY 2 years agothanks works very fine, i want to use it on a diy project (Heat recovery system)

    PP5VX (Bone) 2 years agoOn SI the word "Centigrade" doesn't exists !

    The correct name in SI is CELSIUS...

    "Centigrade" is the 100th part of a degree, and means nothing on this temperature'smeasurements.

    When they use the correct terminology ?( I say it to TEXAS and NATIONAL, too... )

    Regards,

    Share

    Share

    Share

    Share

    Share

    Share

    Share

  • Reply PP5VX (Bone)

    Reply

    KF7PCL 2 years ago> PP5VX (Bone)PP5VX de KF7PCLI feel the same way. I really do not understand why people call it centigrade.Celsius is the correct term.

    As far as the original post goes, I wonder if it is possible to use floating point to get moreprecise measurements? With a 10 bit ADC, it should be accurate to atleast 0.5*C.

    73 KF7PCL / John

    Reply

    Gilbert 3 years agoHi there.

    I am thinking about using this setup, however I have a question that I am not able to easily findthe answer to:

    I am already using the Arduino (Uno) to pilot [4] servos, is it possible to upload your sketch onthe same device and have both servo controls (via USB) and temperature being fed back to thecomputer for treatment at the same time?

    Many thanks if you're able to answer.

    P.S. the servo control comes from this URL:http://principialabs.com/ardui...

    Gilbert

    Reply

    Daniel Andrade 3 years ago> GilbertHello Gilbert, what you could do is first make the program read the temperature, then tryto join them together, doing this way I think you will be able to make it with no problem.I was taking a look at the code, maybe you could also add a CASE that reads thetemperature and sends to the computer.

    :)

    Reply

    Paul K. 3 years agoJust a heads up - if you cut and paste code from the comments here to the Arduino V1.0 IDE,and it was posted with a non-US-English keyboard, and you are using a US-English keyboard,you will get strange errors when you try to compile. Errors like " stray '\' in program" or "expected`)' before 'u00d701'". These seem to be caused by differences in the code pages. Some of theseare caused by the " character specifically in Serial.print("something"); lines. Delete the " andretype it. I suspect some ( or ) were causing problems but couldn't verify. Can't speak for anyother keyboard combinations.

    Just something to watch for if you're getting strange compile errors.PCK

    Share

    Share

    Share

    Share

    Share

  • Reply

    Harparas G. 3 years agoHello,

    I reviewed your code that you have posted on your site (http://www.danielandrade.net/2.... I amgenerating a code that is similar to yours. My only question is, how would I go about storing dataevery 5 minutes, for 12 hours? I will appreciate it if you can get back to me at your earliestconvenience.

    Thank you,

    Harparas Kaur

    Reply

    Daniel Andrade 3 years ago> Harparas G.@Harparas Well, you can do in many different ways, one which I think is the easy one, isto connect the arduino to the computer and with an processing program.http://electronics.stackexchan...

    You want to store 144, you can save it on a array. But then it will be stored in the RAM,and deleted every time you reset the C

    You can also use an EEPROM, that will save the information on ROM, that will not bedeleted when restarting. Here you get more infos: http://arduino.cc/playground/C...

    Hope I have helped!

    Daniel

    Reply

    Harparas K. 3 years ago> Daniel AndradeThank you! i will try it.

    Reply

    Anant 3 years agoHi. Please forgive my ignorance.

    OK. In the ADC section of page 263 of the instruction manual of the ATmega 328P it speaks ofa Temperature sensor. Do they mean internal temperature sensor? Or is it a special channelreserved to connect a Temperature sensor?

    I am building a Temperature data logger using an LM35DZ sensor. Is there a need to connectthe temperature sensor to a dual op-amp LM358, to amplify the signal and detect very smalltemperature variations? Or is it that the Freeduino v 1.22 with the ATmega 328P will be able todetect the very small variations in Temperature? If so, how? Is it because of a fast sampling rateof the microcontroller ADC that the small variations will be able to be picked up? I see you haveconnected the sensor directly to the Freeduino.

    What range of input DC voltage can I connect to the Freeduino v1.22? Because I cant afford tofry my Freeduino.

    Thanks

    sush 3 years ago

    Share

    Share

    Share

    Share

  • Reply

    sush 3 years agoheya..can anyone plz tell me dat can i use GH 311 ultrasonic tranciever module for temperaturemeasurement?? earlier i used TS 601 and it worked quite well. can anyone tell me the coding..!!!

    Reply

    jens 3 years agohello,

    i was wondering if i could use this type of sensor to measure a water temperature, because i amusing an arduino to control the water flood of a jaccuzi.

    thxxx and greetings from Jens

    Reply

    Muzammil 3 years agoHi i m having a ardunio Uno board n i uploaded the code but i m getting strange output

    287 Celsius, 548 fahrenheit -> 288 Max, 100 Min287 Celsius, 548 fahrenheit -> 288 Max, 100 Min

    i have tried other options + i have changed lm35 and tested it again but its the same.plz help

    Reply

    Marry 2 years ago> MuzammilI got the same problem as yours, have you figure out the solution? could you pleaseshare it with me? Thanks.

    Reply

    gamezat 3 years agohello , i have built it and work greate but any body develop software to read from ardino direactthank you

    Reply

    Daniel Andrade 4 years ago@Jason yes it will!!@Ben thanks, I'll fix that! ^

    Blaze 4 years ago> Daniel AndradeI am a beginner at using the Arduino Uno, and I hope you can help me with somethingthat I am having trouble with. I used some of your code for a LM335 temperature sensorthat I am using. I have made a buffer circuit to convert the 10mV/K into a degrees celsiuscircuit. The circuit outputs for 0 degrees and 100 degrees is 2.73V and 3.73Vrespectively; but I am having problems getting the arduino to display the temperature.Could you look at my code at tell me if I did something wrong? Where should my voltagefrom my circuit go into the Arduino (A0 pin?) Can you help me?

    int pin = 0; //analog pinint tempc = 0;

    Share

    Share

    Share

    Share

    Share

    Share

  • Reply

    void setup(){Serial.begin(9600); //start serial communication}

    void loop(){tempc = (5 * analogRead(pin)*100)/1024;delay(1000);

    Serial.print(tempc, DEC);Serial.print(" Celsius");delay(1000);}

    Reply

    ben 4 years agoHi, thanks for doing this - very neat!

    just minor note: the for loop in the code at the moment has a space that needs to be removed 'i http://blog.danielandrade.net Valeu

    Reply

    Marcos 5 years agoDanie, muito bom seu post!Parabns principalmente pela explicao da frmula. Confesso que eu entendia mais ou menosessa parte. Agora ficou claro pra mim.Abrao.

    Share

    Share

    Share

    Share

    Share

    Share

    Share

    Share

  • Load more comments

    Reply

    DanielAndrade 5 years ago@Diego, sorry, didn't get what you are saying. Are you brazilian, if so. Fala em portugusmesmo. :P

    Reply

    Diego 5 years agoI have a question I'm using a teensy which uses a USB instead of a serial how could I modify theprogram?Thanks in advance

    Subscribe Add Disqus to your sited

    Share

    Share