This shows you the differences between two versions of the page.
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:// | + | For more information on thermistor circuits, see |
+ | * [[http:// | ||
+ | |||
===== Wiring diagram ===== | ===== Wiring diagram ===== | ||
Line 9: | Line 12: | ||
===== Arduino Code ===== | ===== Arduino Code ===== | ||
<code c> | <code c> | ||
+ | #include < | ||
+ | #ifdef __AVR__ | ||
+ | #include < | ||
+ | #endif | ||
+ | // pin neopixels are attached to | ||
+ | #define NEOPIXELPIN | ||
- | int lightPin = A0; | + | // Number of neopixels in the strip |
- | int ledPin=13; | + | #define |
- | int threshold = 800; //define threshold value. Below this, the beam is assumed to be broken | + | |
- | int servoPin = 11; //define | + | |
- | int fireposition = 40; | + | |
- | int homeposition = 150; | + | |
- | Servo myservo; | + | // Setup the neopixels |
+ | Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, | ||
+ | |||
+ | //store the thermistor reading | ||
+ | int thermistorPin = A0; | ||
+ | int Vo; | ||
+ | float R1 = 100000; | ||
+ | float logR2, R2, T, Tc, Tf; | ||
+ | float c1 = 1.009249522e-03, | ||
+ | |||
+ | 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 |
- | | + | Serial.begin(9600); |
- | myservo.attach(servoPin); | + | |
- | myservo.write(homeposition); | + | |
- | delay(10000); | + | |
} | } | ||
void loop() | void loop() | ||
{ | { | ||
- | | + | Vo = analogRead(thermistorPin); |
- | delay(1000); | + | R2 = R1 * (1023.0 / (float)Vo - 1.0); // |
- | while (analogRead(lightPin) > threshold){ | + | logR2 = log(R2); |
- | | + | T = (1.0 / (c1 + c2*logR2 + c3*logR2*logR2*logR2)) - 273.15; |
- | digitalWrite(ledPin, 1); | + | |
- | delay(10); | + | |
- | } | + | |
- | myservo.write(fireposition); | + | ledVal = map(constrain(T, lowTemp, highTemp), lowTemp, highTemp, 0, NUMPIXELS); //map temperature to number of pixels |
- | digitalWrite(ledPin, 0); | + | |
- | | + | // loop through all the pixels |
+ | for(int i=0;i< | ||
+ | if (i < ledVal) | ||
+ | thisCol = pixels.Color(0,0,255); // | ||
+ | | ||
+ | thisCol = pixels.Color(0,0,0); //unlit | ||
+ | // pixels.Color takes red/ | ||
+ | pixels.setPixelColor(i, | ||
+ | pixels.show(); | ||
+ | } | ||
+ | delay(100); // delay for 1/10th of a second | ||
} | } | ||
</ | </ |