# 2 thermistors

i am trying to figure out how to read from 2 thermistors at the same time on 2 inputs. i am having a hard time figuring out what part of the code in the thermistor example lets me assign the analog inputs. and then send the 2 to the serial output

Does the code in "the thermistor example" really matter? It's the code on your Arduino that matters. Show that code, and we can help you out.

Even better, though, is for you to do some reading: http://arduino.cc/en/Reference/HomePage Look through your code, and make sure you understand what it is doing. Then, modifying it to do something different will be easy.

here is the code i did use to test it

#define THERMISTOR_PIN 0

// Thermistor lookup table for RepRap Temperature Sensor Boards (http://make.rrrf.org/ts)
// ./createTemperatureLookup.py --r0=100000 --t0=25 --r1=0 --r2=4700 --beta=4066 --max-adc=1023
// r0: 100000
// t0: 25
// r1: 0
// r2: 4700
// beta: 4066
#define NUMTEMPS 20
short temptable[NUMTEMPS][2] = {
{1, 841},
{54, 255},
{107, 209},
{160, 184},
{213, 166},
{266, 153},
{319, 142},
{372, 132},
{425, 124},
{478, 116},
{531, 108},
{584, 101},
{637, 93},
{690, 86},
{743, 78},
{796, 70},
{849, 61},
{902, 50},
{955, 34},
{1008, 3}
};

void setup()
{
Serial.begin(9600);
Serial.println(“Starting temperature exerciser.”);
}

void loop()
{
int fahrenheit = (((celsius * 9) / 5) + 32);

Serial.print("Current temp: ");
Serial.print(celsius);
Serial.print("C / ");
Serial.print(fahrenheit);
Serial.println(“F”);

Serial.print("Raw value: “);
Serial.println(rawvalue);
Serial.println(” ");

delay(1000);
}

{
int current_celsius = 0;

byte i;
for (i=1; i<NUMTEMPS; i++)
{
if (temptable*[0] > rawtemp)*

• {*
int realtemp = temptable[i-1][1] + (rawtemp - temptable[i-1][0]) * (temptable_[1] - temptable[i-1][1]) / (temptable*[0] - temptable[i-1][0]);
if (realtemp > 255)
realtemp = 255;_
current_celsius = realtemp;
_ break;
}
}
// Overflow: We just clamp to 0 degrees celsius*
* if (i == NUMTEMPS)_
current_celsius = 0;
return current_celsius;
_}*
i got it from the reprap wiki http://reprap.org/wiki/Temperature_Sensor_2_0
it dose work, i am just trying to figure out how to get it to work with 2 inputs and have it post the outputs so that i can see they are working. at the same time. this is more for testing purposes than any thing else.
that and my coding skill are still sorely lacking at this point in time_

This:

``````#define THERMISTOR_PIN 0
``````

defines which pin the thermistor is attached to. To have a second thermistor, you need a second statement like this, for the other pin/thermistor.

Append a 1 or 2 to the name (THERMISTOR_PIN1, THERMISTOR_PIN2).

This:

``````  int rawvalue = analogRead(THERMISTOR_PIN);
``````

reads the value of one thermistor. This value is ignored. This line can be deleted.

This:

``````  int celsius = read_temp();
``````

reads a specific pin, and does some calculations. The calculations have nothing to do with which thermistor was read, so this function should be changed to take a pin as an argument:

``````  int celsius = read_temp(THERMISTOR_PIN1);
``````

Then, change the function:

``````int read_temp([glow]int pinNum[/glow])
{
``````

The Serial.print statements show the data that was read. All the statements in the loop() function should be moved to a new function:

``````void show_temp(int pinNumber)
{
// Put existing loop code here
}
``````

Then, loop should have these two lines added:

``````void loop()
{
show_temp(THERMISTOR_PIN1);
show_temp(THERMISTOR_PIN2);
}
``````