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
Next revision
Previous revision
arduino_thermometer [2020/02/14 14:32]
glassgiant
arduino_thermometer [2020/02/14 15:37] (current)
glassgiant [Arduino Code]
Line 2: Line 2:
  
  
-For more information on thermistor circuits, see [[http://www.circuitbasics.com/arduino-thermistor-temperature-sensor-tutorial/]]+For more information on thermistor circuits, see  
 +  * [[http://www.circuitbasics.com/arduino-thermistor-temperature-sensor-tutorial/]] 
 + 
  
 ===== Wiring diagram ===== ===== Wiring diagram =====
Line 9: Line 12:
 ===== Arduino Code ===== ===== Arduino Code =====
 <code c> <code c>
 +#include <Adafruit_NeoPixel.h>
 +#ifdef __AVR__
 +  #include <avr/power.h>
 +#endif
  
 +// pin neopixels are attached to
 +#define NEOPIXELPIN            12
  
-int lightPin = A0;  //define a pin for Photo resistor +// Number of neopixels in the strip 
-int ledPin=13;     //define a pin for LED +#define NUMPIXELS      5
-int threshold = 800; //define threshold value. Below this, the beam is assumed to be broken +
-int servoPin = 11;  //define a pin for the servo +
-int fireposition = 40; +
-int homeposition = 150;+
  
-Servo myservo;+// 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() void setup()
 { {
-    Serial.begin(9600);  //Begin serial communcation + pixels.begin(); // initialize the neopixel library 
-    pinMode( ledPin, OUTPUT ); + Serial.begin(9600);   //enable communication over serial monitor/plotter
-    myservo.attach(servoPin);  +
-    myservo.write(homeposition);  //move servo to home position +
-    delay(10000);   //10 second delay at startup +
 } }
  
 void loop() void loop()
 { {
-   myservo.write(homeposition); +  Vo = analogRead(thermistorPin);  //read the voltage at the sensor pin 
-   delay(1000); +  R2 = R1 * (1023.0 / (float)Vo - 1.0);  //calculate the resistance on the thermistor 
-   while (analogRead(lightPin> threshold){ +  logR2 = log(R2); 
-     Serial.println(analogRead(lightPin)); //Write the value of the photoresistor to the serial monitor. +  T = (1.0 / (c1 + c2*logR2 + c3*logR2*logR2*logR2)) - 273.15;  //math 
-     digitalWrite(ledPin1); +   
-     delay(10)+  Serial.println(T);  //send the Celcius value to serial monitor 
-   } + 
-   myservo.write(fireposition); +  ledVal = map(constrain(TlowTemp, highTemp), lowTemp, highTemp, 0, NUMPIXELS); //map temperature to number of pixels 
-   digitalWrite(ledPin, 0); +   
-   delay(1000);+  // 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
 } }
 </code> </code>
arduino_thermometer.1581690779.txt.gz · Last modified: 2020/02/14 14:32 by glassgiant