×

SparkFun will be closing on Monday for Memorial Day (5/28). Orders placed after 2pm MT on Friday (5/25) will process and ship out on Tuesday (5/29).

NeuralNova

Member Since: May 27, 2014

Country: United States

  • To clarify further, the analog pin reading must first be converted to a voltage for this to work.

    Supposing you have the middle pin of the TMP36 hooked up to pin A3, you can use this code:

    #include <stdlib.h>
    char tempString[10] ;
    int tempPin = 3;
    void setup(){
        Serial.begin(9600);
    }
    
    void loop(){
        int tempRead = analogRead(tempPin);
        float tempVolt = float(tempRead) / 310.3;
        float tempCelsius = (100 * tempVolt) - 50;
        dtostrf(tempCelsius, 8, 2, tempString);
        /* dtostrf (from library <stdlib.h>) takes in a float (tempCelsius, in this case) and stores a stringified version of that float in a pre-established character array (in this case, tempString.) This is necessary because if you try to print a float, you get an error. */
        Serial.print("Current temperature in Celsius: ");
        Serial.println(tempString);
    }
    

No public wish lists :(