Go Down

Topic: LM 34/35 temperature sensor+relay (Read 636 times) previous topic - next topic

rajFanOfSachin

Hi i have tried the following :
Code: [Select]
/*
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 

PaulS

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: [Select]
digitalWrite(relayPin, HIGH);

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

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

robtillaart


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: [Select]

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
Rob Tillaart

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

Go Up