×

Please see all COVID-19 updates here as some shipments may be delayed due to CDC safety and staffing guidelines. If you have an order or shipping question please refer to our Customer Support page. For technical questions please check out our Forums. Thank you for your continued support.

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 :(