To measure the temperature we are going to use a sensor called a TMP36. The TMP36 produces an analog voltage that is directly proportional (linear) to the temperature.



With the writing facing you, connect the left pin to power. The right pin to ground and the middle pin to an analog pin, A0 in this case.


In the code we convert an analog reading back to mV. The Atmega 328 has a 10bit analog to digital converter, hence the range 0 to 1024. If it reads 0, we have 0v. If it’s 1024, we have 5v. So we work out how much voltage each analog step has, then multiply that by the analog reading.

To see the temperature, load the program and open the serial monitor.

4 thoughts on “Temperature”

  1. You need to change the first line of loop() to this:

    float temp = (analogRead(A0)*5000L)/1024;

    Otherwise it converts the number to a 16-bit signed integer and the result is incorrect.

    Also, the last println needs a closing quote.

Leave a Reply

Your email address will not be published. Required fields are marked *