User Tools

Site Tools


arduino_thermometer

Arduino Thermometer

For more information on thermistor circuits, see

Wiring diagram

Arduino Code

#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
  #include <avr/power.h>
#endif
 
// pin neopixels are attached to
#define NEOPIXELPIN            12
 
// Number of neopixels in the strip
#define NUMPIXELS      5
 
// Setup the neopixels
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, NEOPIXELPIN, NEO_GRB + NEO_KHZ800);
 
//store the thermistor reading
int thermistorPin = A0;
int Vo;
float R1 = 100000;  //set to value of resistor
float logR2, R2, T, Tc, Tf;
float c1 = 1.009249522e-03, c2 = 2.378405444e-04, c3 = 2.019202697e-07;
 
int lowTemp = 17;  //lowest temp we'll bother with
int highTemp = 100;  //highest temp we'll bother with
int ledVal; //number of LEDs we'll light up
int thisCol; //pixel colors
 
void setup()
{
	pixels.begin(); // initialize the neopixel library
	Serial.begin(9600);   //enable communication over serial monitor/plotter
}
 
void loop()
{
  Vo = analogRead(thermistorPin);  //read the voltage at the sensor pin
  R2 = R1 * (1023.0 / (float)Vo - 1.0);  //calculate the resistance on the thermistor
  logR2 = log(R2);
  T = (1.0 / (c1 + c2*logR2 + c3*logR2*logR2*logR2)) - 273.15;  //math
 
  Serial.println(T);  //send the Celcius value to serial monitor
 
  ledVal = map(constrain(T, lowTemp, highTemp), lowTemp, highTemp, 0, NUMPIXELS); //map temperature to number of pixels
 
  // loop through all the pixels
  for(int i=0;i<NUMPIXELS;i++){
    if (i < ledVal)
   	  thisCol = pixels.Color(0,0,255);  //blue
    else
      thisCol = pixels.Color(0,0,0); //unlit
    // pixels.Color takes red/green/blue values, from 0,0,0 up to 255,255,255
    pixels.setPixelColor(i, thisCol); 
    pixels.show(); // send pixel colors to the neopixels
  }
	delay(100); // delay for 1/10th of a second
}
arduino_thermometer.txt · Last modified: 2020/02/14 15:37 by glassgiant