Monday, December 29, 2014

The temperature sensor on my hat works!

In my last post, I shared my first completed eTextile, a hat that plays Rudolph the Red-Nosed Reindeer in sync with his flashing nose! After quite a bit of trial and error, I added a temperature sensor and got my hat working the way I want it to! Figuring out the code for this sensor wasn't entirely intuitive.

For example, I wanted the buzzer music to come on when the temperature dipped well below room temperature.  When trying to figure out the code for the temperature sensor, I spent a lot of time writing things like:

if(sensorValue <=155)
and if(sensorValue <=100) 
and if(sensorValue <=50)

By using the Arduino Serial Monitor, I'd determined that the ambient temperature of my room equated to approximately 157 (I don't yet know how that translates to degrees in Fahrenheit).  I thought that using the <= sign would tell the LilyPad that I wanted it to trigger the music when the temperature went down.   This was NOT the case.

The correct way to achieve the result I was after actually looks like this:

 if(sensorValue >=155)

The >= sign doesn't seem to mean GREATER than in this case, because when the temperature goes DOWN, my music comes on.  I would like to understand this better.

In any case, when I wear my hat indoors the lights flash, but the music doesn't come on unless the ambient temperature is pretty chilly. The beauty of this is that the music should only come on when I'm outside, away from the delicate nerves of my loved ones (or to signal our need to heave another log onto the family hearth).

No comments:

Post a Comment

Thanks for commenting.