User Tools

Site Tools


arduino_thermometer

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Last revision Both sides next revision
arduino_thermometer [2020/02/14 14:57]
glassgiant [Arduino Thermometer]
arduino_thermometer [2020/02/14 15:37]
glassgiant [Arduino Code]
Line 33: Line 33:
 float c1 = 1.009249522e-03,​ c2 = 2.378405444e-04,​ c3 = 2.019202697e-07;​ 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() void setup()
Line 43: Line 47:
 { {
   Vo = analogRead(thermistorPin); ​ //read the voltage at the sensor pin   Vo = analogRead(thermistorPin); ​ //read the voltage at the sensor pin
-  R2 = R1 * (1023.0 / (float)Vo - 1.0);+  R2 = R1 * (1023.0 / (float)Vo - 1.0);  //​calculate the resistance on the thermistor
   logR2 = log(R2);   logR2 = log(R2);
   T = (1.0 / (c1 + c2*logR2 + c3*logR2*logR2*logR2)) - 273.15; ​ //math   T = (1.0 / (c1 + c2*logR2 + c3*logR2*logR2*logR2)) - 273.15; ​ //math
Line 49: Line 53:
   Serial.println(T); ​ //send the Celcius value to serial monitor   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   // loop through all the pixels
   for(int i=0;​i<​NUMPIXELS;​i++){   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.Color takes red/​green/​blue values, from 0,0,0 up to 255,255,255
-    pixels.setPixelColor(i, ​pixels.Color(0,​150,​0)); +    pixels.setPixelColor(i, ​thisCol); 
     pixels.show();​ // send pixel colors to the neopixels     pixels.show();​ // send pixel colors to the neopixels
   }   }
arduino_thermometer.txt · Last modified: 2020/02/14 15:37 by glassgiant