Analog Sensor to LED Homework

For this project I worked throught he example project used in the Arduino package guide: In this example you make a “love” sensor by using a temperture sensor that rises when touched then corrolating that data within ranges to the LEDs to show a range.

 

Video: http://www.youtube.com/watch?v=3cl2bjT84zY&list=UUzI0K0LLL5j83vjmJUHI6qA

Code:

const int sensorPin = A0;
const float baselineTemp = 20.0;

void setup() {
Serial.begin(9600);
for(int pinNumber = 2; pinNumber<5; pinNumber++){
pinMode(pinNumber, OUTPUT);
digitalWrite(pinNumber, LOW);
}
}
void loop(){
int sensorVal = analogRead(sensorPin);
Serial.print(“Sensor Value: “);
Serial.print(sensorVal);
float voltage = (sensorVal/1024.0)*5.0;
Serial.print(” , Volts: “);
Serial.print(voltage);
Serial.print(” , Degrees C: “);
float temperature = (voltage – .5)*100;
Serial.println(temperature);

if(temperature < baselineTemp){
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
}else if(temperature >= baselineTemp+2 && temperature < baselineTemp+4){
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
}else if(temperature >= baselineTemp+4 && temperature < baselineTemp+6){
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, LOW);
}else if(temperature >= baselineTemp+6){
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, LOW);
}
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