Temperature Monitoring With LM35 Sensor

Temperature Monitoring With LM35 Sensor

Main Diagram

Hardware Required

  • PICUNO Microcontroller board
  • 1 × LED
  • 1 × 220Ω resistor
  • 1 × LM35 Temperature Sensor
  • 1 × Buzzer
  • Breadboard
  • Jumper wires
  • USB cable

Description

The LM35 outputs an Analog voltage proportional to temperature in °C (10mV per °C). The PicUNO reads this voltage, converts it to Celsius, and prints it to the Serial Monitor. If the temperature exceeds a preset threshold (e.g., 40°C), an LED and buzzer are activated to indicate overheating.

Circuit Diagram

[Fritzing image to be added here]

Circuit

  • Connect the PICUNO board to the computer using a USB cable.
  • Connect the Anode of the LED to one terminal of a 220Ω resistor.
  • Connect the other terminal of the resistor to GPIO pin 6.
  • Connect the Cathode of the LED to GND.
  • Connect the Leftmost pin of the LM35 sensor to 3.3V, Rightmost pin to GND and the Middle pin to Analog pin A0 on PicUNO.
  • Connect positive terminal of the buzzer to GPIO 7.
  • Connect negative terminal of the buzzer to GND.

Schematic

LM35 has 3 pins:

Left pin (VCC) → 3.3 V

Right pin (GND) → GND

Centre Pin (Vin) → A0

LED anode → 220-ohm resistor → GPIO 6

LED cathode → GND

Buzzer +ve terminal → GPIO 7

Buzzer -ve terminal → GND

Code - C

int sensorPin = A0;
int ledPin = 6;
int buzzerPin = 7;
float threshold = 40.0; // Temperature threshold

void setup() {
  pinMode(ledPin, OUTPUT);
  pinMode(buzzerPin, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  int analogValue = analogRead(sensorPin);
  float voltage = analogValue * (3.3 / 1024.0); // Adjust if using 5V
  float temperatureC = voltage * 100.0;

  Serial.print("Temperature: ");
  Serial.print(temperatureC);
  Serial.println(" °C");

  if (temperatureC > threshold) {
    digitalWrite(ledPin, HIGH);
    digitalWrite(buzzerPin, HIGH);
  } else {
    digitalWrite(ledPin, LOW);
    digitalWrite(buzzerPin, LOW);
  }
  delay(1000);
}
analogRead(sensorPin) - Reads voltage from LM35.

voltage * 100.0 - Converts to temperature in Celsius.

if (temperature > threshold) - Activates LED and buzzer if hot.

Code - Micropython

from machine import ADC, Pin
import time

sensor = ADC(0)  # A0 pin
led = Pin(6, Pin.OUT)
buzzer = Pin(7, Pin.OUT)
threshold = 40.0

while True:
    analog = sensor.read_u16()
    voltage = analog * 3.3 / 65536
    temperature = voltage * 100

    print("Temperature:", round(temperature, 2), "°C")

    if temperature > threshold:
        led.value(1)
        buzzer.value(1)
    else:
        led.value(0)
        buzzer.value(0)
    time.sleep(1)
analog = sensor.read_u16() - Reads LM35 Analog output.

voltage = analog * 3.3 / 65536 - convert the Analog reading into voltage.

voltage * 100 - Converts voltage to temperature.

if temperature > threshold - Turns on alerts.