Pages: [1]   Go Down
Author Topic: LM 34/35 temperature sensor+relay  (Read 502 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 14
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi i have tried the following :
Code:
/*
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.net
http://creativecommons.org/license/cc-gpl
*/

int pin = 0; // analog pin
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;

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 precision
tempf = (tempc * 9)/ 5 + 32; // converts to fahrenheit

if(tempc > maxi) {maxi = tempc;} // set max temperature
if(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;

Done successfully ,,
The thing is i want to extend the same for the following requirements:
1.  there is a  heating element ,a resistor which is heated up by a dc source of 5v,, Lm 34/35 senses the temp and continuously reads .. and displays
2.we have a set temperature and if it exceeds the relay cuts the dc supply.

Any one plz help me on this 
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 551
Posts: 46243
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What kind of relay are you using? How is it connected to the Arduino? Does it control the heater?

Generally, turning a relay on is as simple as:
Code:
digitalWrite(relayPin, HIGH);

and turning it off is as simple as:
Code:
digitalWrite(relayPin, LOW);

Turning the relay on and off at the right temperature is done using an if statement.
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 170
Posts: 12483
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


you need to do the if statement carefully and use two different temperatures to switch. These can be based upon one setTemp by means of two offsets.

Code:
if (tempc > setTemp+1) digitalWrite(pin, LOW);
if (tempc < setTemp-1) digitalWrite(pin, HIGH);

this prevents that when the temperature is around setTemp that the relay is "buzzing" on and off constantly. You can define the behaviour by changing the offsets +1 and -1 e.g to +0 and -4
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Pages: [1]   Go Up
Jump to: