Pages: [1]   Go Down
Author Topic: LM35 With ARDUINO DUE  (Read 288 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 14
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi, I am trying to use LM35 with Arduino DUE.
The problem that I am facing here is that when the time delay for reading the temp is 1000ms the result will be lead to 0 after two cycle of reading. However, when the time delay is less or equals to 500ms there is no problem and the sketch works well.
I am also facing this problem when I use the tem reading with more than 500ms in any other sketches. But in UNO its fine.
The following is the sketch that I use to indicate the the temp in three modes of high, medium, cold with LEDs and switching on/off a relay for a specific range.
Does it back to the DUE as its 32bit ? should i use other way(binary) to indicate the time delay?
THANKS.

Code:
int sensorPin = 2;
int val = 0;
int temp;
int highPin = 8;
int lowPin = 6;
int mPin= 7;
int Mode = 0;
int Relay = 3;

void setup()
{
   pinMode(highPin, OUTPUT);
   pinMode(lowPin, OUTPUT);
   pinMode(mPin, OUTPUT);
   pinMode(Relay, OUTPUT);
  
   // if i dont make this pins LOW, at the beginning of the program  all these pins will be HIGH for a short time until the loop start.
    digitalWrite(highPin, LOW);
    digitalWrite(lowPin, LOW);
    digitalWrite(mPin, LOW);
    digitalWrite(Relay, LOW);
    Serial.begin(9600);

}
void loop()
{
  val = analogRead(sensorPin);
  
  float voltage = (val * 3.289)/1024;

  float celsius = (voltage - 0.0001) * 100 ;
  
  int temp1 = celsius;
  
  delay(500);   //if I change this to 1000ms or more than 500ms the reading  will changes to 0 . EVEN if I don’t use the fowling average procedure
voltage = (val * 3.289)/1024;
  celsius = (voltage - 0.0001) * 100 ;
  int temp2 = celsius;
  temp = ((temp1+temp2)/2);
 
 
  if (29 < temp < 33){
   Mode = 1;
    
  }
  if(temp < 28) {
    Mode = 2;
  }
 if (temp > 33.5)
  {
    Mode = 3;
  }
  if (temp > 30){
   digitalWrite(Relay, HIGH);
  }
  else if (temp <28.5){
    
   digitalWrite(Relay, LOW);
  }
  
  if (Mode == 1){
    digitalWrite(highPin, LOW);
    digitalWrite(lowPin, LOW);
    digitalWrite(mPin, HIGH);
  }
  if (Mode == 2){
    digitalWrite(highPin, LOW);
    digitalWrite(lowPin, HIGH);
    digitalWrite(mPin, LOW);
  }
  if (Mode == 3){
    digitalWrite(highPin, HIGH);
    digitalWrite(lowPin, LOW);
    digitalWrite(mPin, LOW);
  }
  Serial.print(voltage,4);
  Serial.print(" volts    ");
  Serial.print(temp,2);  
  Serial.println(" Celsius ");
}
« Last Edit: October 18, 2013, 09:37:00 pm by ashkan1637 » Logged

Pages: [1]   Go Up
Jump to: