Temperature Measurement with Analog Sensor Module

This project demonstrates how to measure temperature using an analog temperature sensor module with an Arduino Uno. The analog sensor provides a voltage output proportional to the ambient temperature, which is then converted to Celsius temperature and displayed on the serial monitor.

How It Works

An analog temperature module converts temperature into a voltage the Arduino Uno can sample directly. Two parts dominate hobby kits: the LM35 precision sensor and NTC thermistor modules such as the KY-013.

The LM35 is the easier of the two because its output is linear by design: exactly 10 mV per °C, referenced to 0 V, so 25 °C produces 250 mV. No calibration curve is required — divide the measured millivolts by 10 and you have degrees Celsius.

A thermistor is a resistor whose value falls as it warms. The KY-013 places a 10 kΩ NTC in a divider with a fixed 10 kΩ resistor, so the module outputs a voltage that changes with temperature but not linearly. Converting it properly needs the Steinhart–Hart relationship, or its simplified B-parameter form, using the thermistor's nominal resistance at 25 °C and its B coefficient (around 3950 for common parts).

The Arduino Uno samples with a 10-bit ADC, so analogRead() returns 0–1023 across 5 V.

Components Needed

  • Arduino Uno
  • Analog Temperature Sensor module
  • Arduino Uno
  • USB cable for programming and power
  • Arduino Uno

Wiring to the Arduino Uno

Connect the module's signal pin to A0, VCC to the 5 V rail and GND to ground. With a 5 V supply the output spans 0–5 V, matching the ADC range directly.

Any of A0–A5 (six channels) will work; A0 is used here by convention.

Keep the sensor away from the board's voltage regulator and any motor driver. Both dissipate heat and will bias readings upward by several degrees if the sensor sits next to them.

Module pinArduino Uno pinFunction
S / OUTA0Analog voltage proportional to temperature
VCC / +5VSupply
GND / −GNDCommon ground

Example Code

Reading an LM35 on the Arduino Uno with averaging to suppress ADC noise. Upload it with the board set to Arduino Uno and open the Serial Monitor at 9600 baud.

Reading an LM35 on the Arduino Uno with averaging to suppress ADC noise
const int SENSOR_PIN = A0;
const float VREF = 5.0;      // ADC reference voltage
const int   ADC_MAX = 1023;   // 10-bit converter
const int   SAMPLES = 16;

void setup() {
  Serial.begin(9600);
}

float readCelsius() {
  long total = 0;
  for (int i = 0; i < SAMPLES; i++) {
    total += analogRead(SENSOR_PIN);
    delay(5);
  }
  float counts  = (float)total / SAMPLES;
  float volts   = counts * VREF / ADC_MAX;
  return volts * 100.0;            // LM35: 10 mV per degree C
}

void loop() {
  float c = readCelsius();
  Serial.print("Temperature: ");
  Serial.print(c, 1);
  Serial.print(" C  /  ");
  Serial.print(c * 9.0 / 5.0 + 32.0, 1);
  Serial.println(" F");
  delay(1000);
}

Applications

A analog temperature sensor turns up in a wide range of projects. These are the uses where it is the right choice rather than a compromise:

  • Room and greenhouse climate logging
  • Over-temperature cut-outs for motors, power supplies and battery packs
  • Thermostat control for heaters, fans and incubators
  • Cold-chain monitoring where a readable margin of ±1 °C is acceptable
  • Compensation inputs for other sensors whose output drifts with temperature

Working with the Arduino Uno

The Arduino Uno is built around the ATmega328P and runs on 5 V logic with 2 KB of SRAM and 32 KB of program flash. These details change how this circuit is wired and what the sketch can do, so they are worth stating plainly before you build.

The Uno runs at 5 V, so most hobby sensor modules connect directly with no level shifting.

With only 2 KB of SRAM, avoid large buffers and prefer the F() macro for constant strings.

The single hardware UART is shared with the USB connection, so heavy Serial printing competes with uploads.

Arduino Uno characteristicValueWhy it matters here
Logic voltage5 VMatches most hobby modules directly
ADC resolution10-bit (0–1023)Sets how finely an analog reading can be resolved
Analog inputsA0–A5 (six channels)Determines how many analog sensors can share the board
PWM outputsD3, D5, D6, D9, D10 and D11Needed for brightness, speed and tone control
I²C pinsA4 (SDA) and A5 (SCL)Fixed by hardware — wiring copied from another board may not match
Interrupt pinsD2 and D3 onlyRequired for counting fast or asynchronous events
Seriala single hardware UART shared with USBMonitor runs at 9600 baud by default

Troubleshooting

Most problems with this module fall into a handful of categories. Work through these before suspecting the part itself:

  • Readings sit around 0 or jump wildly — the signal pin is on a digital pin rather than an analog one.
  • Temperature reads several degrees high — the sensor is picking up heat from the regulator or a nearby driver; move it away from the board.
  • Values drift slowly over minutes — self-heating. Sample periodically rather than continuously.
  • A thermistor module reads nonsense when treated as linear — the KY-013 needs the B-parameter conversion, not the LM35 formula.
  • Code written for an ESP board gives odd analog values — the Arduino Uno uses a 10-bit ADC returning 0–1023; rescale any constant taken from a 12-bit example.
  • An I²C sensor is not found after copying wiring from another Arduino — on the Arduino Uno I²C is on A4 (SDA) and A5 (SCL).

Taking It Further on the Arduino Uno

Once the basic reading works, where you go next depends very much on which board you are using. These are the directions that suit the Arduino Uno specifically:

The Uno’s shield ecosystem is its real advantage. Once the circuit works on a breadboard, a prototyping shield turns it into something permanent that still stacks with a data-logging or Ethernet shield without rewiring.

Logging to an SD card via a shield is the natural next step, since the Uno has no onboard storage and no network. Timestamp each reading with a DS3231 real-time clock so the log survives power cuts with correct times.

Because SRAM is limited to 2 KB, keep logged strings short and write them out immediately rather than buffering. Building a long String in memory is the most common cause of an Uno sketch that runs for hours and then freezes.

Notes and Practical Limits

Averaging sixteen samples, as the sketch does, trades response speed for stability and removes most of the least-significant-bit jitter. Each ADC step is roughly 4.9 mV, which corresponds to about 0.5 °C with an LM35 — the practical resolution limit without an external amplifier.

For better than ±1 °C, or for readings sent over any distance, prefer a digital sensor such as the DS18B20 or DHT22. Digital parts transmit numbers rather than voltages, so cable resistance and connector corrosion stop mattering.