I am using an Arduino Due board to read three temperatures from three separate smt160-30 digital sensors but the program is behaving very randomly. the code I am using is one I got from arduino official site and changed the structure to get three temp readings and display them on a 16x2 lcd. The problem is when I use one sensor the output is reasonable but when I use all three the temperature showing are all off by 4 degrees. also I tried removing the line lcd.print(temperature1, 1)
and the output temperatures changed. Is this odd behavior because of SRAM issues ? if so how can I find out about it and fix it ?
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
unsigned long now;
unsigned long lastSample;
unsigned int sampleSize;
unsigned int highCount1;
unsigned int highCount2;
unsigned int highCount3;
unsigned long lastOutput;
float temperature1;
float temperature2;
float temperature3;
float hcf1, hcf2, hcf3;
float ssf;
int sensorPin1 = 23;
int sensorPin2 = 24;
int sensorPin3 = 26;
void setup(){
pinMode(sensorPin1, INPUT);
pinMode(sensorPin2, INPUT);
pinMode(sensorPin3, INPUT);
digitalWrite(sensorPin1, LOW);
digitalWrite(sensorPin2, LOW);
digitalWrite(sensorPin3, LOW);
lastSample = 0;
sampleSize = 0;
highCount1 = 0;
highCount2 = 0;
highCount3 = 0;
temperature1 = 0;
temperature2 = 0;
temperature3 = 0;
lastOutput = 0;
delay(2000);
lcd.setCursor(0, 0);
}
void loop() {
now = micros();
if (now - lastOutput > 3000000) {
lcd.clear();
hcf1 = highCount1;
hcf2 = highCount2;
hcf3 = highCount3;
ssf = sampleSize;
temperature1 = ((hcf1 / ssf) -0.32)/0.0047;
temperature2 = ((hcf2 / ssf) -0.32)/0.0047;
temperature3 = ((hcf3 / ssf) -0.32)/0.0047;
lastOutput = now;
sampleSize = 0;
highCount1 = 0;
highCount2 = 0;
highCount3 = 0;
lcd.print(temperature1, 1);
lcd.print(" ");
lcd.print(temperature2, 1);
lcd.print(" ");
lcd.print(temperature3, 1);
}
if (now - lastSample > 50) {
sampleSize++;
highCount1 = highCount1 + digitalRead(sensorPin1);
highCount2 = highCount2 + digitalRead(sensorPin2);
highCount3 = highCount3 + digitalRead(sensorPin3);
lastSample = now;
} else {
delayMicroseconds(10);
}
}
Thank you!