PadhaikoAll subjects

Past exam question: Assignment 3, Q11

Instrumentation · 5 marks

Open in the Padhaiko app

Topic: Sensor/Actuator interfacing with Atmega328P (Arduino): Analog and…

Question

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

Arduino Uno to TMP36 Temperature Sensor WiringText
   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):

  1. Voltage Calculation: With a reference and 10-bit (-step) ADC:
  1. 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:

Arduino Temperature Measurement using TMP36C
#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.

All past exam questions for Instrumentation