https://vimeo.com/169797098
code:
//Libraries
#include <Adafruit_NeoPixel.h>
#include <math.h>
//Converting thermistor input to degrees F
double Thermistor(int RawADC) {
double Temp;
Temp = log(10000.0*((1024.0/RawADC-1)));
Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp ))* Temp );
Temp = Temp - 273.15;
Temp = (Temp * 9.0)/ 5.0 + 32.0;
return Temp;
}
//Photocell
int photocell = 0;
//Lights
int LED = 9;
//Neopixel Setup
#define PIN 9
Adafruit_NeoPixel strip = Adafruit_NeoPixel(8, PIN, NEO_RGB);
void setup() {
strip.begin();
strip.show(); //Initializa all pixels to 'off'
pinMode(LED, OUTPUT);
pinMode(A1, INPUT);
Serial.begin(9600);
}
void loop() {
int val;
double temp;
photocell = analogRead(A1); //photocell is A1
//Read thermistor values
int sensorValue=analogRead(A3);
int sensorValue2=analogRead(A4);
temp=Thermistor(sensorValue/2 + sensorValue2/2);
//Print temperature
Serial.print("Temperature = ");
Serial.print(temp);
Serial.println(" F");
delay(1000);
if (photocell < 200) {
for (int i; i<7; i++) {
strip.setPixelColor(i, 255, 255, 255);
}
}
else {
if (temp < 80) {
strip.setPixelColor(0, 255, 0, 0);
strip.setPixelColor(1, 255, 0, 0);
strip.setPixelColor(2, 255, 0, 0);
strip.setPixelColor(3, 255, 0, 0);
strip.setPixelColor(4, 255, 0, 0);
strip.setPixelColor(5, 255, 0, 0);
strip.setPixelColor(6, 255, 0, 0);
strip.setPixelColor(7, 255, 0, 0);
//Red when the photocell is covered, and temperature is below 80 degrees
delay(10);
}
else if (temp > 80 && temp <= 87) {
strip.setPixelColor(0, 0, 255, 0);
strip.setPixelColor(1, 0, 255, 0);
strip.setPixelColor(2, 0, 255, 0);
strip.setPixelColor(3, 0, 255, 0);
strip.setPixelColor(4, 0, 255, 0);
strip.setPixelColor(5, 0, 255, 0);
strip.setPixelColor(6, 0, 255, 0);
strip.setPixelColor(7, 0, 255, 0);
//Green when the photocell is covered, and temperature is between 80 and 87 degrees
delay(10);
}
else if (temp > 87 && temp <= 92) {
strip.setPixelColor(0, 0, 0, 255);
strip.setPixelColor(1, 0, 0, 255);
strip.setPixelColor(2, 0, 0, 255);
strip.setPixelColor(3, 0, 0, 255);
strip.setPixelColor(4, 0, 0, 255);
strip.setPixelColor(5, 0, 0, 255);
strip.setPixelColor(6, 0, 0, 255);
strip.setPixelColor(7, 0, 0, 255);
//Blue when the photocell is covered, and temperature is between 87 and 92
delay(10);
}
}
Serial.println(photocell);
strip.show();
}
No comments:
Post a Comment