0

Arduino & Temperature Sensing
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Arduino & Temperature Sensing

by Chief Robot on Wed Jun 25, 2008 8:10 pm

Hi,
I'm fairly new to using an Arduino and need to be pointed in the right direction.
My project is to control a small fan or servo based on a temperature reading. Basically if the small room in my basement is too hot I need to cool it down.
I've seen SHT15 temperature sensor over at Sparkfun and thought about using that. Is this a good way to go or are there other temperature sensors that are better or cheaper? Also any hints or code examples would be appreciated.

Thanks!
Chief Robot
 
Posts: 37
Joined: Wed Jun 25, 2008 8:04 pm

by mngrif on Wed Jun 25, 2008 8:21 pm

Chances are driving the fan will be the hardest part since the temperature sensor has it's datasheet right on the site, no purchase required.

Just go through the datasheet and make sure you understand it before you get in too deep. The same with whatever device you'll use to turn the fan on or off.
mngrif
 
Posts: 47
Joined: Sat Jun 07, 2008 6:36 am

by franklin97355 on Wed Jun 25, 2008 10:40 pm

Arduinos talk well with DS18x20s and they are cheap.

franklin97355
 
Posts: 21488
Joined: Mon Apr 21, 2008 2:33 pm
Location: Lacomb, OR.

by Silver on Thu Jun 26, 2008 2:36 am

I've had good luck with the LM35, a precision linear temperature sensor.

LM35 Sources: BGmicro.com and Jameco.com Search term: LM35 Approx $1.75

See this previous post.
http://forums.ladyada.net/viewtopic.php?t=5763
Silver
 
Posts: 12
Joined: Mon Apr 21, 2008 1:39 am

by Atrum on Thu Jun 26, 2008 2:58 pm

You might run into a problem where fans don't really cool down a room, they only push air around helping your sweat evaporate.

The room might be hot enough causing the sensor to go off but the sensor will never detect a change in temperature. So the fan would not turn off.

This would work with a small A/C unit or evaporative cooler, but they already have built in thermostats.
Atrum
 
Posts: 13
Joined: Thu Jun 19, 2008 12:52 am

by Chief Robot on Thu Jun 26, 2008 7:36 pm

Thanks Silver.
I'll order some LM35's and give your code a try for starters.
Chief Robot
 
Posts: 37
Joined: Wed Jun 25, 2008 8:04 pm

by Chief Robot on Mon Jun 30, 2008 4:45 pm

Silver,
I get the following readings when using your code.

216 Celsius, 420 Fahrenheit
197 Celsius, 386 Fahrenheit
190 Celsius, 374 Fahrenheit
201 Celsius, 393 Fahrenheit


What am I doing wrong?
Also why would the temperature fluctuate so much in seconds?
Chief Robot
 
Posts: 37
Joined: Wed Jun 25, 2008 8:04 pm

by Silver on Tue Jul 01, 2008 2:54 am

What am I doing wrong?


Good question. Like any other troubleshooting task, rule one is: Check the hardware first. (Plus the fact that the program itself is really only three lines of code :) )

First thing is to check if you have the LM35 oriented correctly. The quick wiring diagram in the comments of the code shows the two outer pins connected to +5 and ground, but it doesn't tell you which pin is which. Plus, there are four different packaging types for the LM35. The version I used is in the TO-92 package and it looks like a transistor. The LM35 also comes in a cylindrical package, a flat surface mount, and a TO-220 that looks like a voltage regulator. There is also a note that the earlier version of the TO-220 had a different pin out. Checking the pin orientation from the spec sheet is essential.

http://www.ece.osu.edu/~passino/LM35.pdf

Because the LM35 is only rated to supply a reading up to 150 Celsius, I'm guessing there is a wiring problem. Check that the +5 and ground are going to the correct pins and that there is a signal resistor between the voltage output pin and ground (I used an 18K resistor). Also check that the sample voltage goes into the Analog Input pin 5 of the board (bottom connector, last pin).

Also make sure the +5 and ground are supplied from the Arduino board itself and not an external source. Having two differently referenced ground levels (called a floating ground) makes reading small voltage differences difficult and is a real pain to troubleshoot. (Ask me how I know :) )

If you still don't get a believable reading, try taking the LM35 out of the circuit and replace it with a resistor 10 times the value of the signal resistor. This should give you a voltage divider circuit that will supply .45 volts directly to Analog Input pin 5. Running the program should say that the temp is approximately 92 Celsius, 198 Fahrenheit.

Code: Select all | TOGGLE FULL SIZE
             180K ohm        18K ohm 
    +5 ------/\/\/\/-----+---/\/\/\/-----> Gnd
                         |
                         +----------- Analog Input pin 5


One or more of these fixes should get the circuit and program working together. If you still have problems, let me know what value you got when using the basic voltage divider circuit shown above.

Silver
Silver
 
Posts: 12
Joined: Mon Apr 21, 2008 1:39 am

by Chief Robot on Tue Jul 08, 2008 7:00 am

Thanks Silver. I haven't had much time to work on this lately.
Right now I get a reading of 511 or 510. I still need to work on the wiring .

Also, I have added 2 lines of code. I don't really want to print Fan On, but actually turn the fan on or off. I have some useful info from todbot herehttp://todbot.com/blog/2007/11/24/bionic-arduino-class-notes-3-4/, and am thinking about using a transistor to turn the fan on and off, but really would appreciate being pointed in the right direction .

if (inVal>=75) (Serial.print("Fan On "));// If temp over a certain amount, turn fan on
if (inVal<=73) (Serial.print("Fan Off "));// If temp under a certain amount, turn fan off

thanks again.
Chief Robot
 
Posts: 37
Joined: Wed Jun 25, 2008 8:04 pm

by Chief Robot on Sat Jul 12, 2008 2:04 pm

Ok I finally have the LM35 wired correctly and have started wiring up the fan, but need help with the code for controlling the fan. The fan is a 12 v .25amp fan. Anyone know where to find code for controlling a simple motor or small fan?
Chief Robot
 
Posts: 37
Joined: Wed Jun 25, 2008 8:04 pm

by lou on Sat Jul 12, 2008 2:36 pm

Chief Robot wrote:Ok I finally have the LM35 wired correctly and have started wiring up the fan, but need help with the code for controlling the fan. The fan is a 12 v .25amp fan. Anyone know where to find code for controlling a simple motor or small fan?


If your control is just on/off, it's just a digital output bit. Look at the numerous transistor and/or relay circuits out there for controlling DC loads. As the fan most likely presents an inductive load, pay attention to any protection diodes to protect a transistor from burning out or a relay from arcing.

If you're using PWM, it's pretty much the same thing, but a relay-based solution probably wouldn't work very well. A sufficiently sized transistor should have no problem switching a 250ma load.

As for code, this is really basic stuff. Any LED blinker demo should tell you everything you need to know for on/off. PWM is not much harder. The PWMs are popular on Arduinos. There should be no shortage of examples.
lou
 
Posts: 91
Joined: Fri Jul 11, 2008 9:39 am

Please be positive and constructive with your questions and comments.