top of page
Colorful Thermometer Code

// Colorful Thermometer Sketch
int temperaturePin = A0;
//This is will read the center pin of the temperature sensor.
float baseTemp = 23.0; //This is the lowest temperature before LEDs will begin turning on.
void setup() {
Serial.begin(9600);
//This sets up the serial port so that the temperature can be read.
pinMode(2, OUTPUT); //Sets pin 2 as an output
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
digitalWrite(2, LOW);
// Starts the LED in pin 2 off.
digitalWrite(3, LOW);
digitalWrite(4, LOW);
}
void loop() {
int sensorVal = analogRead(temperaturePin);
//Stores the value being read by the center pin.
float temperature =(500 * sensorVal) /1024;
Serial.println("Degrees C: ");
Serial.println(temperature);
if (temperature < baseTemp) {
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
}

// if the temperature is between baseTemp and 2 degrees above the baseTemp turn on the first LED on

else if (temperature >= baseTemp && temperature < baseTemp + 2) {
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
}


// if the temperature is between 2 and 4 degrees above baseTemp turn first two LEDs on
else if (temperature >= baseTemp + 2 && temperature < baseTemp + 4) {
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, LOW);
}

// if the temperature is more than 4 degrees C above base temp turn all LEDs on
else if (temperature >= baseTemp + 4) {
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
}
delay(500);
}

Igniting Innovation through Functional Prototyping and Physical Computing

Contact Information

odysseyboardedu.@gmail.com
Phone: (360) 303-5526
24338 Lee Road
Mount Vernon, WA 98274

Contact Us

Thanks for submitting!

© 2017 by Odyssey Board. All rights reserved.

bottom of page