Physical Computing Blog 4

Task: Come up with a simple application of what you’ve learned.

Last week, I worked with a photocell, speaker and servo motor, so for this week, I wanted to work with another type of analog input. I found that the Arduino starter kit comes with a temperature sensor that works as an analog input, so I made a thermometer “instrument”. I used this link as a reference to utilize the temperature sensor. I got the temperature sensor to start reading temperatures and convert the output voltage into a temperature in Fahrenheit. I then added a speaker component, with a potentiometer to control the amount of volume coming out of the resistor. I realized that playing the Fahrenheit temperatures were not an interesting range of tones for the speaker, so I mapped the output voltages of the temperature sensor to a tone range of 300 to 500. To change the temperature rapidly enough to notice a significant tone change, I applied my own body heat (by touching the sensor). The code, schematic, pictures and a video are below.

Schematic for simple circuit. Note that the temperature sensor used was a TMP36, not an LM50, but that was all that I could find that was remotely similar to the TMP36 in the Eagle library.

Schematic for simple circuit. Note that the temperature sensor used was a TMP36, not an LM50, but that was all that I could find that was remotely similar to the TMP36 in the Eagle library.

int tempPin = 0;
int sensorVal;
int speakerPin = 8;
int speakerTone;

void setup() {
  pinMode(tempPin, INPUT);
  pinMode(speakerPin, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  sensorVal = analogRead(tempPin);
  Serial.println(sensorVal);
  speakerTone = map(sensorVal, 145, 170, 300, 500);
  float voltage = (sensorVal * 5.0) / 1024.0;
  float tempF = ((((voltage - 0.5) * 100) * 9.0) / 5.0) + 32.0;
  tone(speakerPin, speakerTone);
  Serial.println(tempF);
  delay(500);
}
GIF of temperatures being read as I apply head to temperature sensor

GIF of temperatures being read as I apply head to temperature sensor