Who needs Sesame Street when you can learn the same things from micro-controllers? Ok, I still need Sesame Street because life would be bleak without Big Bird. But I’m refreshing my elementary education through the use of my Arduino.
I found a thermistor in a box of parts. It looked like it came from an computer case and I wanted to see how it worked. A few resistors, a multi-colored LED, and some wiring later, I got it working with my Arduino Duemilanove. I haven’t played with analog sensors much so it was a nice little exercise for myself.
Overall its not all that complex, both in the circuit and the code. Though I was giving myself a big headache there for a while trying to find a fault that ended up being a coding error.
…Damn semi-colons… It’s always a semi-colon…
It’s okay though. That just made my victory all the sweeter when I finally got it working. I was able to entertain myself for a good 10 minutes moving the sensor from a cup of hot water to a cup of cold water just to watch the little light blink.
Here’s the code I used.
/*
Hot and Cold sensor.
Experimenting to get a thermistor to work that I found in my parts bin.
kamikazejoe
*/
int hotpin = 13; // pin 13 lights the red light.
int coldpin = 12; // pin 12 lights the blue light.
int sensorpin = 0; // using analog pin 0 for the thermistor
int temp = 0; // variable to store the value coming from the sensor
void setup() {
// initialize the digital pins as an output:
pinMode(hotpin, OUTPUT);
pinMode(coldpin, OUTPUT);
digitalWrite(hotpin, HIGH);
digitalWrite(coldpin, HIGH);
}
void loop() {
int temp = analogRead(sensorpin); // read value from pin 0
if (temp > 100) { // sensor reads an average of about 100 at room temperature. I used that for the comparison.
digitalWrite(coldpin, LOW); // Turn off the blue
digitalWrite(hotpin, HIGH); // and turn on the red.
}
else { // otherwise do the opposite.
digitalWrite(hotpin, LOW);
digitalWrite(coldpin, HIGH);
}
}
Here’s the wiring schematic for the LED and the sensor.
And a couple of pictures of it in action.
I never claimed I was going to do build anything useful.






















