So I asked this question a couple days ago but did some more work with some of the coding, but I'm really stuck and need some help. I'm trying to display the temperature for each separate thermistor from input pins A0-A8 on the 2560 board. My current issue that it only reads the A8 input pin. Do I need to make more declarations such as "double readThermistor1, double readThermistor2..." etc. After I make those declarations, how would I go about displaying each separate thermistor? I'll post what I have so far:
// Constants
const int SAMPLE_NUMBER = 10;
const double BALANCE_RESISTOR = 10000.0;
const double MAX_ADC = 1023.0;
const double BETA = 3977.0;
const double ROOM_TEMP = 298.15; // room temperature in Kelvin
const double RESISTOR_ROOM_TEMP = 10060.0;
// Here is where we will save the current temperature
double currentTemperature = 0;
// Pin Declarations
//Inputs:
int thermistorPin[] = {A0,A1,A2,A3,A4,A5,A6,A7,A8}; // Where the ADC samples the resistor divider's output
//Outputs:
void setup()
{
// Set the port speed for serial window messages
Serial.begin(9600);
}
double readThermistor()
{
// variables that live in this function
double rThermistor = 0; // Holds thermistor resistance value
double tKelvin = 0; // Holds calculated temperature
double tCelsius = 0; // Hold temperature in celsius
double adcAverage = 0; // Holds the average voltage measurement
int adcSamples[SAMPLE_NUMBER]; // Array to hold each voltage measurement
/* Calculate thermistor's average resistance:
As mentioned in the top of the code, we will sample the ADC pin a few times
to get a bunch of samples. A slight delay is added to properly have the
analogRead function sample properly */
for (int i = 0; i < SAMPLE_NUMBER; i++)
{
adcSamples[i] = analogRead(thermistorPin[0]); // read from pin and store
delay(10); // wait 10 milliseconds
adcSamples[i] = analogRead(thermistorPin[1]);
delay(10); // wait 10 milliseconds
adcSamples[i] = analogRead(thermistorPin[2]); // read from pin and store
delay(10); // wait 10 milliseconds
adcSamples[i] = analogRead(thermistorPin[3]); // read from pin and store
delay(10); // wait 10 milliseconds
adcSamples[i] = analogRead(thermistorPin[4]); // read from pin and store
delay(10); // wait 10 milliseconds
adcSamples[i] = analogRead(thermistorPin[5]); // read from pin and store
delay(10); // wait 10 milliseconds
adcSamples[i] = analogRead(thermistorPin[6]); // read from pin and store
delay(10); // wait 10 milliseconds
adcSamples[i] = analogRead(thermistorPin[7]); // read from pin and store
delay(10); // wait 10 milliseconds
adcSamples[i] = analogRead(thermistorPin[8]); // read from pin and store
delay(10); // wait 10 milliseconds
}
/* Then, we will simply average all of those samples up for a "stiffer"
measurement. */
for (int i = 0; i < SAMPLE_NUMBER; i++)
{
adcAverage += adcSamples[i]; // add all samples up . . .
}
adcAverage /= SAMPLE_NUMBER; // . . . average it w/ divide
rThermistor = BALANCE_RESISTOR * ( (MAX_ADC / adcAverage) - 1);
tKelvin = (BETA * ROOM_TEMP) /
(BETA + (ROOM_TEMP * log(rThermistor / RESISTOR_ROOM_TEMP)));
tCelsius = tKelvin - 273.15; // convert kelvin to celsius
return tCelsius; // Return the temperature in Celsius
}
void loop()
{
currentTemperature = readThermistor();
delay(3000);
/* Here is how you can act upon a temperature that is too hot,
too cold or just right. */
if (currentTemperature > 0.0 && currentTemperature < 60.0)
{
Serial.print("It is ");
Serial.print(currentTemperature);
Serial.println("C. Ahhh, very nice temperature.");
}
else if (currentTemperature >= 60.0)
{
Serial.print("It is ");
Serial.print(currentTemperature);
Serial.println("C. I feel like a hot tamale!");
}
}
Any help is appreciated, thank you.
My current issue that it only reads the A8
... that is what you told the Arduino to do ... see thefor (int i = 0; i < SAMPLE_NUMBER
loop .... think about theadcSamples[i]
variablefor
loops to read the sensor values into the array ... multipleanalogRead()
lines are not necessaryclass
, then instantiating multiple classes for each thermistor.for(s ...)
for(i ...)
adcSamples[i][s] = analogRead(thermistorPin[i]);
...i
is sensor number ...s
is sample number