The first step we tackled with the prototyping process was trying to
read temperature. Since the kit provided for us came with a thermistor, we
searched the web for code to go with it. We found some code (http://www.circuitbasics.com/arduino-thermistor-temperature-sensor-tutorial/) that takes
temperature readings from the thermistor, and converts it to Fahrenheit. Lucky
for us, the code was also accompanied by photographs of the Arduino and
breadboard, so we were able to figure out how to wire the thermistor and the
correct resistor pretty quick and get accurate temperature readings from our
hands.
After talking
with Dominic about our project, he convinced us to use a photocell rather than
a pressure sensor as a switch for the temperature readings. We used our
previous knowledge from the Arduino experiments early on to wire this and get
it running.
Finally, we
plugged the multicolor LED into the bread board and used 'If' statements in our
code to make the light turn on, and change color depending on the temperature
reading the Arduino was receiving for the thermistor. A small step for programmers, but a big step for Peter and Kylen.
Once we were confident that our plan would work, we collected thermistors from our classmates who weren't using them, and ordered some neopixels so that we'd have a bright enough light source for our final lamp. We purchased 8 individual neopixels, and also a 12 neopixel ring. We decided to use the individual neopixels in the end.
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;
}
int redPin = 11;
int greenPin = 10;
int bluePin = 9;
int light = 0;
void setup() {
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
pinMode(A0, INPUT);
Serial.begin(9600);
}
void setColor(int red, int green, int blue)
{
analogWrite(redPin, red);
analogWrite(greenPin, green);
analogWrite(bluePin, blue);
}
void loop() {
int val;
double temp;
light = analogRead(A0);
//read the input on analog pin 0;
int sensorValue=analogRead(A1);
int sensorValue2=analogRead(A2);
temp=Thermistor(sensorValue/2 + sensorValue2/2);
//print out the value you read;
Serial.print("Temperature = ");
Serial.print(temp);
Serial.println(" F");
delay(1000);
if (light < 200) {
setColor(255, 255, 255); //white
}
else {
if (temp < 80) {
setColor(255, 0, 0); //red
}
else if (temp > 80 && temp <= 87) {
setColor(0, 255, 0); //green
}
else if (temp > 87 && temp <= 92) {
setColor(0, 0, 255); //blue
}
else if (temp > 92 && temp < 100) {
setColor(80, 0, 80); //purple
}
}
Serial.println(light);
}
No comments:
Post a Comment