Temperature Sensing Hat
by imoyer@mit.edu
by Judy Zheng Jia and Ilan Moyer
Our concept is a hat which measures the wearer’s body temperature using a sensor held against their forehead and then displays the measurement with a color-changing antenna.
In Action
Construction
The brain behind the hat is a small microcontroller, the Atmel ATtiny85, mounted to a fabric PCB designed by Prof. Buechley and made by us in lab.
Temperature measurements are currently made by an integrated thermometer-on-a-chip (MCP9700A) which has been sewn in the forehead of the hat.
A tri-color LED is used as the output device and is mounted on an antenna made of clear plastic fiber.
Current Schematic
Future Schematic
Here is our experiment of the codes:
1.AnalogReadSerial:
/*
AnalogReadSerial
Reads an analog input on pin 0, prints the result to the serial monitor
This example code is in the public domain.
*/
int roomTemperature = 689;
void setup() {
Serial.begin(9600);
analogReference(INTERNAL);
}
void loop() {
int sensorValue = analogRead(A0);
Serial.println(sensorValue, DEC);
analogWrite(9, sensorValue – roomTemperature);
}
2. Calibration:
/*
Calibration
Demonstrates one technique for calibrating sensor input. The
sensor readings during the first five seconds of the sketch
execution define the minimum and maximum of expected values
attached to the sensor pin.
The sensor minimum and maximum initial values may seem backwards.
Initially, you set the minimum high and listen for anything
lower, saving it as the new minimum. Likewise, you set the
maximum low and listen for anything higher as the new maximum.
The circuit:
* Analog sensor (potentiometer will do) attached to analog input 0
* LED attached from digital pin 9 to ground
created 29 Oct 2008
By David A Mellis
Modified 4 Sep 2010
By Tom Igoe
http://arduino.cc/en/Tutorial/Calibration
This example code is in the public domain.
*/
// These constants won’t change:
const int sensorPin = A0; // pin that the sensor is attached to
const int ledPin = 9; // pin that the LED is attached to
const int ledPin2 = 3;
// variables:
int sensorValue = 0; // the sensor value
int sensorMin = 1023; // minimum sensor value
int sensorMax = 0; // maximum sensor value
void setup() {
Serial.begin(9600);
// turn on LED to signal the start of the calibration period:
analogReference(INTERNAL);
pinMode(13, OUTPUT);
digitalWrite(13, HIGH);
// calibrate during the first five seconds
while (millis() < 5000) {
sensorValue = analogRead(sensorPin);
Serial.println(sensorValue);
// record the maximum sensor value
if (sensorValue > sensorMax) {
sensorMax = sensorValue;
}
// record the minimum sensor value
if (sensorValue < sensorMin) {
sensorMin = sensorValue;
}
}
// signal the end of the calibration period
digitalWrite(13, LOW);
}
void loop() {
// read the sensor:
sensorValue = analogRead(sensorPin);
sensorValue += analogRead(sensorPin);
sensorValue += analogRead(sensorPin);
sensorValue += analogRead(sensorPin);
sensorValue += analogRead(sensorPin);
sensorValue /= 5;
int difference = sensorValue - sensorMin;
Serial.print(sensorMin);
Serial.print(" ");
Serial.println(sensorValue);
// apply the calibration to the sensor reading
//sensorValue = map(sensorValue, sensorMin, sensorMax, 0, 255);
// in case the sensor value is outside the range seen during calibration
//sensorValue = constrain(sensorValue, 0, 255);
// fade the LED using the calibrated value:
//analogWrite(ledPin, sensorValue);
// if (sensorValue - sensorMin > 5) {
// analogWrite(ledPin, 255);
// } else {
// analogWrite(ledPin, 0);
// }
if (sensorValue – sensorMin == 1) {
analogWrite(ledPin, 1);
} else if (sensorValue – sensorMin == 2) {
analogWrite(ledPin, 2);
} else if (sensorValue – sensorMin == 3) {
analogWrite(ledPin, 4);
} else {
analogWrite (ledPin, 255);
}
//analogWrite(ledPin, sensorValue – sensorMin);
if (difference > 0 && difference < 10) {
analogWrite(ledPin2, 2);
} else if (difference >= 10 && difference < 20) {
analogWrite(ledPin2, 3);
} else if (difference >= 20 && difference < 30) {
analogWrite(ledPin2, 6);
} else if (difference >= 30 && difference < 40) {
analogWrite(ledPin2, 10);
} else if (difference >= 40 && difference < 50) {
analogWrite(ledPin2, 20);
} else if (difference >= 50 && difference < 60) {
analogWrite(ledPin2, 40);
} else {
analogWrite (ledPin2, 255);
}
}