Introduction: Arduino + Temperature + Humidity

A simple temperature sensor using one LM35 Precision Temperature Sensor , Humidity Sensor and Arduino, so you can hookup on your future projects. The circuit will send serial information about the temperature and humidity so you can use on your computer. I have taken data from my compost. The project is related to an existing product daily dump with which anyone can convert kitchen waste into compost at home. For more details about product go to http://www.dailydump.org/content/. Digicompost displays the changes (change in temp, humidity) happening inside dump

Step 1: Materials

- 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.
- BreadBoard.
- Humidity Sensor.
- Wires.

Step 2: Setting Up Arduino + Temperature

Arduino is an open-source electronics prototyping platform based on flexible, easy-to-use hardware and software. It's intended for artists, designers, hobbyists, and anyone interested in creating interactive objects or environments. For more information log on to (http://www.arduino.cc)

Connecting a temperature sensor:
The LM35 has three legs and looks like a transistor. The two outside legs are
+5v and Ground, and the middle leg develops the sample voltage.

The Analog to Digital Converter (ADC) converts analog values into a digital approximation
based on the formula ADC Value = sample * 1024 / reference voltage (+5v). So with a +5 volt
reference, the digital approximation will = input voltage * 205. (Ex. 2.5v * 205 = 512.5)

The LM35 is a precision linear temperature sensor that supplies 10mv per degree Celsius.
This means at 15 degrees Celsius, it would produce a reading of .150v or 150 millivolts.
Putting this value into our ADC conversion ( .15v * 205 = 30.75) we can get a close
approximation of the Celsius temperature by dividing the digital input count by 2.

If the LM35 were supplied by a different reference voltage (9v or 12v) we would have
to use a different conversion method. For this circuit, dividing by 2 works well.

Step 3: Connecting Humidity Sensor

There are two pins on to the humidity sensor one is for ground and other for out which goes on the pin 3 on to arduino. I have used a local made sensor for testing humidity/ moisture but one can go for SHT15 which have both temperature and humidity.

Step 4: Setting Up Code!!!

Plug in your arduino to the computer, open the application select proper port and model no. before you start any coding. After everything is done write down the code as shown below:

int pin = 5; // analog pin
int putPin = 3; // humidity
int tempc = 0,tempf=0; // temperature variables
int samples[8]; // variables to make a better precision
int maxi = -100,mini = 100; // to start max/min temperature
int i;

float humi = 0;
float prehum = 0;
float humconst = 0;
float truehum = 0;
float pretruehum = 0;
long pretruehumconst = 0;
long valb = 0;

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

void loop()
{

for(i = 0;i<=7;i++){

samples[i] = ( 5.0 * analogRead(pin) * 100.0) / 1024.0;
tempc = tempc + samples[i];
delay(1000);
}

tempc = tempc/8.0;
tempf = (tempc * 9)/ 5 + 32;

valb = analogRead(putPin); // humidity calculation
prehum = (valb/5);
humconst = (0.16/0.0062);
humi = prehum - humconst;
pretruehumconst = 0.00216*tempc;
pretruehum = 1.0546-pretruehumconst;
truehum = humi/pretruehum ;
delay(1000);

Serial.print(tempc,DEC);
Serial.print(" Celsius, ");
Serial.print ("Humidity: ");
Serial.print ((long)truehum);
Serial.println ("% ");

tempc = 0;

delay(1000); // delay before loop
}

After everything is done click on the upload button which will take a little while to upload and when the uploading is done make sure you click on the Serial Communication to get the readings from the sensor !!!

Comments

author
VikasB30 (author)2017-01-03

bro its working but the output is not correct when i place it in soil

author
Daniel IsaiasU (author)2016-08-12

veo el syh-1 conectado entre 3,3v y A3. Deberías dar mas información respecto al sensor de humedad y su código. Dislike+

author
MahamuthaM (author)2015-07-19

I am trying same thing using LM-35 and SYH-1 and the code is also same. But i am getting negative values of Humidity. Is it possible to obtain negative values of Humidity? But my actual humidity value in Chennai is 35%. Hereby i have attached the snapshot of it.

2.JPG
author
laith mohamed (author)2015-03-05

Good project and good work

author
sandiri (author)2014-10-11

will u please let me know the exact ic of humidity sensor that you have used. great instructable by the way.

author
taqiya (author)2014-05-08

why you dont use SHT11 for easy it

author
banswastik (author)2013-01-21

can i noe the exact model of the humidity sensor that is used?

author
rawrarf (author)2012-04-29

I am also interested to see the design of the humidity sensor. Please and thank you!

author
Mr.What (author)2012-02-27

Would like to see the design of your humidity sensor.

author
Imdsm (author)2011-06-03

Interesting code but reminds me of our crappy English education...code is just given to people without any explanation. I am a very competent coder so it's not a problem understanding your code - but arbitrary numbers such as 0.16, 0.0062, 0.00216, 1.0546 ..my fellow coders and I call these magic numbers, because no explanation is given to them. I am sure they have a specific purpose, but an explanation would make this page 4021501258 times better

author
TerryKing (author)2011-06-01

Hi, Here is some additional information on doing this with Arduino:
http://arduino-info.wikispaces.com/TemperatureHumidity

This uses a $2.50 sensor that is both temperature and humidity.

author
i0scan (author)2009-07-31

Can I ask where you got the humidity sensor and how much it cost? Great instructable by the way.

author
devillived (author)i0scan2009-10-26

Its a local made humidty sensor i am not in the town for few days but can send you the pdf i have made. which has most of the information so let me know if you need it send me a hi mail to dharmangprajapati@gmail.com will send you the pdf

author
ReagenWard (author)2009-10-26

Would you mind adding details about the humidity sensor?

author
devillived (author)ReagenWard2009-10-26

Its a local made humidty sensor i am not in the town for few days but can send you the pdf i have made from it which has most of the information so let me know if you need it send me a hi mail to dharmangprajapati@gmail.com will send you the pdf

author
pavan5859 (author)2009-06-08

can it used on the hot water pipes to know the temperature

author
devillived (author)pavan58592009-06-08

yes you can unless you use other temperature sensors available in the market ...

author
Ubachukwu (author)2009-03-25

Can You use this device to measure Water Temperature? IF so, how would you go about doing so?

author
Ubachukwu (author)Ubachukwu2009-03-26

ok, I read up on insulating the microchip in another instructable thanks. This arduino code that you have posted, I am not sure what the member "silver halo" meant by the code not working and needing some swaping. Can you explain the code or at least tell me what errors are in the code so I may adjust the code myself

author
devillived (author)Ubachukwu2009-03-26

well if its possible for you to tell me where your facing the issue!!! then i can guide you with it !!!

author
devillived (author)Ubachukwu2009-03-25

ya you can just make sure your temperature sensor is properly insulated!!!!

author
rolandl (author)2008-11-12

If you use linux, I suggest you install SimpleMessageSystem (from arduino.cc) and get my shellscript package from http://user.cavenet.com/rolandl, called SMS1.tgz. It will read all 6 AD channels, scale to mV, and format for import to most spreadsheets. Easy to modify input and scaling for your choice of sensors. Now with GUI via xdialog command. Allows complex control via scripts. Check it out.

author
silverHalo (author)2008-11-09

Is the "samples" syntax correct, I was having issues when it complied. Is it supposed to be samples[8] and samples[i] instead? thanks!

author
silverHalo (author)silverHalo2008-11-09

Must be something with the instructables formatting of the posts... it changed my formatting too!! The syntax should be "samples" followed by an open bracket (with the "8" or "i" inside of the bracket) and the closed bracket..... These posts don't like [

author
devillived (author)silverHalo2008-11-09

Yes there is some problem with the formatting will upload the file!!