user84763: 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.

user10285: Here is my proposal:
Sum the readings (samples) of each sensor(thermistor) and store the sum in an array. Then divide each sum by the number of samples that were taken. Instead of computing one tCelsius, compute one tCelsius for each average values and store it in an array too. Then print each of them. Feel free to print it as you like.
BTW I did not compile and test the code. There might be errors in it. Use it as a hint/example.
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;   
const double RESISTOR_ROOM_TEMP = 10060.0;

// PIN_COUNT is the length of the thermistorPin list.
const double PIN_COUNT = 9;
int thermistorPin[] = {A0,A1,A2,A3,A4,A5,A6,A7,A8};  

void setup() 
{ 
  Serial.begin(9600);
}

double readThermistor() 
{
  double rThermistor = 0.0; 
  double tKelvin     = 0.0; 

  // The count of the zeros below should be equal 
  // to the PIN_COUNT
  double tCelsius[] 
           = {0.0, 0.0, 0.0, 0.0, 0.0, 
              0.0, 0.0, 0.0, 0.0};
  double adcSampleSumPerPin[]
           = {0.0, 0.0, 0.0, 0.0, 0.0, 
              0.0, 0.0, 0.0, 0.0};

  for (int i = 0; i < SAMPLE_NUMBER; i++)
  { 
    for (int j = 0; j < PIN_COUNT; i++) 
    {
      adcSampleSumPerPin[j] += 
                   (double) analogRead(thermistorPin[j]);
      delay(10);
    }
  }

  for (int i = 0; i < PIN_COUNT; i++) 
  {
    adcSampleSumPerPin[i] /= SAMPLE_NUMBER;
    rThermistor = BALANCE_RESISTOR *
                  ((MAX_ADC / adcSampleSumPerPin[i]) - 1);
    tKelvin = (BETA * ROOM_TEMP) / 
              (BETA + (ROOM_TEMP * log(rThermistor / 
              RESISTOR_ROOM_TEMP)));
    tCelsius[i] = tKelvin - 273.15;  
  }

  return tCelsius; 
}
   
void loop()
{
  delay(3000);
  currentTemps = readThermistor();

  for (i = 0; i < PIN_COUNT; i++)
  {
    double currentTemperature = currentTemp[i];
    if (currentTemperature > 0.0 && currentTemperature < 60.0)
    {
      Serial.print("Sensor A");
      Serial.print(i);
      Serial.println(":"); 

      Serial.print("It is ");
      Serial.print(currentTemperature);
      Serial.println("C. Ahhh, very nice temperature."); 
    }
    else if (currentTemperature >= 60.0)
    {
      Serial.print("Sensor A");
      Serial.print(i);
      Serial.println(":"); 

      Serial.print("It is ");
      Serial.print(currentTemperature);
      Serial.println("C. I feel like a hot tamale!");
    } 
  }
}


84763: <p>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 &quot;double readThermistor1, double readThermistor2...&quot; etc. After I make those declarations, how would I go about displaying each separate thermistor?  I'll post what I have so far:</p>
<pre class="lang-cpp prettyprint-override"><code>
//  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 &lt; 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 &quot;stiffer&quot;
     measurement. */
  for (int i = 0; i &lt; 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 &gt; 0.0 &amp;&amp; currentTemperature &lt; 60.0)
  {
    Serial.print(&quot;It is &quot;);
    Serial.print(currentTemperature);
    Serial.println(&quot;C. Ahhh, very nice temperature.&quot;);
  
  } 
  else if (currentTemperature &gt;= 60.0)
  {
    Serial.print(&quot;It is &quot;);
    Serial.print(currentTemperature);
    Serial.println(&quot;C. I feel like a hot tamale!&quot;);
  } 
}

</code></pre>
<p>Any help is appreciated, thank you.</p>
 10285: <p>Here is my proposal:</p>
<p>Sum the readings (samples) of each sensor(thermistor) and store the sum in an array. Then divide each sum by the number of samples that were taken. Instead of computing one tCelsius, compute one tCelsius for each average values and store it in an array too. Then print each of them. Feel free to print it as you like.</p>
<p>BTW I did not compile and test the code. There might be errors in it. Use it as a hint/example.</p>
<pre><code>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;   
const double RESISTOR_ROOM_TEMP = 10060.0;

// PIN_COUNT is the length of the thermistorPin list.
const double PIN_COUNT = 9;
int thermistorPin[] = {A0,A1,A2,A3,A4,A5,A6,A7,A8};  

void setup() 
{ 
  Serial.begin(9600);
}

double readThermistor() 
{
  double rThermistor = 0.0; 
  double tKelvin     = 0.0; 

  // The count of the zeros below should be equal 
  // to the PIN_COUNT
  double tCelsius[] 
           = {0.0, 0.0, 0.0, 0.0, 0.0, 
              0.0, 0.0, 0.0, 0.0};
  double adcSampleSumPerPin[]
           = {0.0, 0.0, 0.0, 0.0, 0.0, 
              0.0, 0.0, 0.0, 0.0};

  for (int i = 0; i &lt; SAMPLE_NUMBER; i++)
  { 
    for (int j = 0; j &lt; PIN_COUNT; i++) 
    {
      adcSampleSumPerPin[j] += 
                   (double) analogRead(thermistorPin[j]);
      delay(10);
    }
  }

  for (int i = 0; i &lt; PIN_COUNT; i++) 
  {
    adcSampleSumPerPin[i] /= SAMPLE_NUMBER;
    rThermistor = BALANCE_RESISTOR *
                  ((MAX_ADC / adcSampleSumPerPin[i]) - 1);
    tKelvin = (BETA * ROOM_TEMP) / 
              (BETA + (ROOM_TEMP * log(rThermistor / 
              RESISTOR_ROOM_TEMP)));
    tCelsius[i] = tKelvin - 273.15;  
  }

  return tCelsius; 
}
   
void loop()
{
  delay(3000);
  currentTemps = readThermistor();

  for (i = 0; i &lt; PIN_COUNT; i++)
  {
    double currentTemperature = currentTemp[i];
    if (currentTemperature &gt; 0.0 &amp;&amp; currentTemperature &lt; 60.0)
    {
      Serial.print(&quot;Sensor A&quot;);
      Serial.print(i);
      Serial.println(&quot;:&quot;); 

      Serial.print(&quot;It is &quot;);
      Serial.print(currentTemperature);
      Serial.println(&quot;C. Ahhh, very nice temperature.&quot;); 
    }
    else if (currentTemperature &gt;= 60.0)
    {
      Serial.print(&quot;Sensor A&quot;);
      Serial.print(i);
      Serial.println(&quot;:&quot;); 

      Serial.print(&quot;It is &quot;);
      Serial.print(currentTemperature);
      Serial.println(&quot;C. I feel like a hot tamale!&quot;);
    } 
  }
}
</code></pre>
