Here's the single line of code:

Serial.println(map(analogRead(0),250,700,14,441)/10.0);

Broken down into 3 lines:

float x = map(analogRead(0),250,700,14,441);  // analog pin reads 250-700, corresponds to 1.4C to 44.1C
x /= 10.0;          // divide by 10; map() uses integers
Serial.println(x);  // output to serial

I used the 'map' statement to read from a thermistor bridge. This is cheating because it assumes the voltage response is a straight line between 1C and 44C. If you want to be more exact, use ComponentLib.Thermistor2.

The values for the map statement came from the table in ComponentLib.Thermistor. These show the analog pin reading 250 for 1.4C and 700 for 44.1C. As 'map' uses integers, I used values of 14 and 441 as the output range, then divided by 10.

Hardware (analog side of my Seeeduino):

5V -- thermistor -- 10k resistor -- GND
Then wire from thermistor/resistor junction to Analog 0.

The 10k Thermistor was £0.54 from Ebay, EN3D103J.

The complete code is here:

void toggle(int x)
{
  if (digitalRead(x) == HIGH)
    digitalWrite(x, LOW);
  else
    digitalWrite(x, HIGH);
}

void setup()
{
  Serial.begin(9600);
  Serial.println("Ready");
}

void loop()
{
  float x = map(analogRead(0),250,700,14,441);  // analog pin reads 250-700, corresponds to 1.4C to 44.1C
  x /= 10.0;          // divide by 10; map() uses integers
  Serial.println(x);  // output to serial  
  toggle(13);         // toggle LED
  delay(1000);        // wait 1 second
}

JN2

Share