Hello everyone,
I am trying to program an Arduino Uno to read the analog values of 2 different NTC thermistors connected with dividers and with the analog pins of the Arduino.
- the Arduino takes 10 measurements with some delay between each other
- store each measurement in a array
- compare the first value stored in the array with the sum of the 10 values
- if the sum is the same with the 1st value, print a message
- when 10 measurements are completed, “clean” the array and go back to the beginning
#include <math.h>
int backLight = 13; // pin 13 will control the backlight
void setup(void) {
Serial.begin(9600);
pinMode(backLight, OUTPUT);
digitalWrite(backLight, HIGH); // turn backlight on. Replace 'HIGH' with 'LOW' to turn it off.
}
double Thermister(int RawADC) {
double Temp;
Temp = log(((10240000 / RawADC) - 10000));
Temp = 1 / (0.001129148 + (0.000234125 * Temp) + (0.0000000876741 * Temp * Temp * Temp)); //calculations used for the thermistors
Temp = Temp - 273.15; // Convert Kelvin to Celcius
return Temp;
}
void printTemp(void) {
double temp = Thermister(analogRead(0)); // Read sensor
double temp2 = Thermister(analogRead(5));
Serial.print("\n");
Serial.print("Temperature is:");
Serial.print(temp);
Serial.print("\n");
Serial.print("Temperature2 is:");
Serial.print(temp2);
Serial.print(" C ");
double stemp = (temp + temp2) ;
Serial.print("\n");
Serial.print("SUM temperature is:");
Serial.print(stemp);
double stfump = (stemp / 2) ;
Serial.print("\n");
Serial.print("AVERAGE temperature of 2 sensors is:");
Serial.print(stfump);
Serial.print("\n");
Serial.print("\n");
delay(3000);
Serial.print(",,,,,,,,,,,,");
}
void loop(void) {
float reading[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
float summer = 0;
float stfump = 0;
for ( int i = 0; i = 9; i++) {
printTemp();
delay(1);
reading[i] = stfump;
summer = summer + reading[i];
}
if (summer == reading[1]) { //checking whether the sum of the array is the same with the 1st value
Serial.print("completed measurement");
}
}
Here is my code:
Any help is more than welcome,
Thank you in advance,
Napster