Permalink
Browse files

Add test for temperature sensor

  • Loading branch information...
1 parent ea52720 commit 3025d3680ac5525c22cee5dd7f7e74e3ead53c3d @karlduino committed Mar 15, 2012
Showing with 44 additions and 0 deletions.
  1. +44 −0 temperature_sensor/temperature_sensor.ino
@@ -0,0 +1,44 @@
+/* temperature sensor
+ *
+ * with flat side with numbers facing toward you (mine says TMP / 36GZ / # 1139 / 217182
+ * left pin to 3.3V
+ * center pin to analog input 5
+ * right pin to ground
+ *
+ * Convert 0-1023 input to 0-5000 mV
+ *
+ * temp in deg C = (mV - 500) / 10
+ */
+
+
+int tempPin = 5; // analog input
+
+void setup(void)
+{
+ Serial.begin(9600);
+}
+
+void loop(void)
+{
+ int tempReading;
+ float temp_mV, tempC, tempF;
+
+ tempReading = analogRead(tempPin); // returns 0-1023
+
+ temp_mV = map(tempReading, 0, 1023, 0, 5000); // convert to milliVolts
+
+ tempC = (temp_mV - 500)/10;
+ tempF = 9*tempC/5 + 32;
+
+ Serial.print("Analog reading = ");
+ Serial.print(tempReading);
+ Serial.print("\tmV=");
+ Serial.print(temp_mV);
+ Serial.print("\tdeg C=");
+ Serial.print(tempC);
+ Serial.print("\tdeg F=");
+ Serial.print(tempF);
+ Serial.print("\n");
+
+ delay(1000);
+}

0 comments on commit 3025d36

Please sign in to comment.