Go Down

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

rajFanOfSachin

May 10, 2011, 02:24 pm
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.nethttp://creativecommons.org/license/cc-gpl*/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 fahrenheitif(tempc > maxi) {maxi = tempc;} // set max temperatureif(tempc < mini) {mini = tempc;} // set min temperatureSerial.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

#1
May 10, 2011, 02:36 pm
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

#2
May 10, 2011, 07:03 pm

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

Please enter a valid email to subscribe