Due to the impacts of the coronavirus outbreak, we are experiencing longer than normal lead times on certain products. We encourage back-ordering out-of-stock items to receive them as soon as possible.

Star Machinery

Member Since: December 12, 2012

Country: Australia

  • Here's some code:

    const int tempSensorPin = A0;  
    int sensorValue = 0;       
    float degreesC = 0;
    void setup() {
    void loop() {
      sensorValue = analogRead(tempSensorPin);
      degreesC = sensorValue/2.046 - 50.0;
      Serial.print("sensor = ");
      Serial.print("\t degrees C = ");

    I think this is correct, but I am getting fairly high temperatures, ~ 28 degrees, while the weather is more like 22. I don't have a commercial device to verify though. Here's my reasoning:

    The formula given above ("This sensor will output 0.5V at 0 degrees C, 0.75V at 25 C, and 10mV per degree C") is

    Degrees C = Voltage out x 100 - 50

    But you don't get Voltage out from the AnalogRead() function (http://arduino.cc/en/Reference/AnalogRead). If you use the default settings it maps 0-5V on to 0-1023. This combined with the previous gives the formula:

    Degrees C = analogRead() x 0.489 - 50

    or without rounding

    Degrees C = analogRead()/2.046 - 50