Past exam question: Assignment 3, Q11
Open in the Padhaiko appQuestion
How to measure temperature using Arduino Interfacing?
Solution
Sensor Selection and Hardware Connection (TMP36 / LM35): An Arduino Uno (ATmega328P) measures temperature using an analog linear temperature sensor such as TMP36 (or LM35) connected to an analog input pin (A0):
- Pin 1 (): Connected to Arduino
5Vpin. - Pin 2 (): Connected to Arduino analog input
A0(10-bit ADC, values ). - Pin 3 (): Connected to Arduino
GND.
TMP36 Sensor Arduino Uno (ATmega328P)
+------------+ +------------------------+
| Pin 1 (Vs) |<---------------| 5V |
| Pin 2 (Vo) |--------------->| A0 (10-bit ADC Input) |
| Pin 3 (GND)|<---------------| GND |
+------------+ +------------------------+Conversion Equations (ADC Count Voltage Temperature):
- Voltage Calculation: With a reference and 10-bit (-step) ADC:
- Temperature Calculation (TMP36): The TMP36 outputs with a () offset at (allowing sub-zero readings down to without negative supplies):
(For an LM35 with at , .) For example, if , then .
Arduino Sketch:
#define SENSOR_PIN A0
void setup() {
Serial.begin(9600); // Initialize serial monitor at 9600 baud
}
void loop() {
int reading = analogRead(SENSOR_PIN); // Read 10-bit ADC value (0-1023)
float voltage = reading * (5.0 / 1024.0); // Convert ADC code to volts
float tempC = (voltage - 0.5) * 100.0; // Convert voltage to deg C (TMP36)
float tempF = (tempC * 9.0 / 5.0) + 32.0; // Convert to deg F
Serial.print("Temperature: ");
Serial.print(tempC);
Serial.print(" C | ");
Serial.print(tempF);
Serial.println(" F");
delay(1000);
}Answer:
Connect a linear analog sensor (TMP36 or LM35) to Arduino 5V, GND, and analog pin A0, sample it with analogRead(A0), convert the 10-bit count to voltage , and compute temperature (for TMP36) before displaying over Serial.