Temp Sensor & RGB LED

Ok, let’s get it out there. I went through two piezos, one dedicated vibration sensor, three temperature sensors, and a lot of code. Analog sensors and I just don’t get along it seems. The piezos and vibration sensor were way too sensitive. And the temperature sensors were, ironically, temperamental.

I finally wrangled a temp sensor into submission. As it reads my temperature increases, it cycles through blue to green to red. Red is hot. Obviously.

A problem may lie in the fact that I have an abnormally low temperature at rest, but that really shouldn’t affect the performance, because I manually set the baseline temp. Whatever, anger.

Based code off of Arduino examples and rocked serious adjustments.
const int tempSensor = A0;
const float baselineTemp = 46.0;

void setup(){
Serial.begin(9600);
pinMode(9,OUTPUT);
pinMode(10, OUTPUT);
pinMode(11,OUTPUT);
digitalWrite(9, LOW);
digitalWrite(10,LOW);
digitalWrite(11,LOW);
}

void loop(){
int sensorVal = analogRead(tempSensor);

float voltage = (sensorVal/1024.0) * 5.0;

Serial.print(“Degrees C: “);
float temperature = (voltage – .5) * 100;
Serial.println(temperature);

if(temperature < baselineTemp){
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
}
else if(temperature >= baselineTemp+1 && temperature < baselineTemp+2){
digitalWrite(9, HIGH);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
}
else if(temperature >= baselineTemp+2 && temperature < baselineTemp+3){
digitalWrite(9, LOW);
digitalWrite(10, HIGH);
digitalWrite(11, LOW);
}
else if(temperature >= baselineTemp+3){
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, HIGH);
}
delay(1);
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s