Arduino Temperature Alarm Project

When we need to monitor the temperature in an environment close to a heat source, a temperature alarm is essential. This small electronic device can sense the temperature in the surrounding environment, and once it exceeds a predefined value, it emits a sharp sound alarm, alerting you to take necessary actions. In this article, we will create a simple temperature alarm model using Arduino. In this example, when the ambient temperature exceeds 25 degrees Celsius, a buzzer will be triggered, producing a sound warning. Simultaneously, Arduino will output the current temperature value via the serial port, allowing you to monitor temperature changes in real-time.

To obtain temperature readings from the surrounding environment, we need to use a sensor. This sensor acts like a sensory organ, converting physical quantities into electrical signals for transmission. In this project, we have chosen the LM35 temperature sensor, which has lower power consumption and is suitable for a wide temperature range. This is particularly helpful for hobbyists and makers in their projects.

Table of Contents

Required Components and Wiring

  • 1 × Arduino UNO R3 (with accompanying USB data cable)
  • 1 × Breadboard
  • 5 × Colored Jumper Wires
  • 1 × Buzzer
  • 1 × LM35 Temperature Sensor

Arduino temperature alarm project wiring diagram

Arduino Temperature Alarm Project Code

					void setup() {
    pinMode(10, OUTPUT);        // Set the buzzer pin
    Serial.begin(9600);        // Set the baud rate to 9600 bps
void loop() {
    int val;            // Variable to store the LM35 reading
    double data;        // Variable to store the converted temperature value
    val = analogRead(0);   // LM35 is connected to the analog port, read its value
    data = (double) val * (5.0 / 1024.0) * 100.0;  // Temperature conversion formula
    if (data > 25) {        // If the temperature is greater than 25 degrees Celsius, activate the buzzer
        for (int x = 0; x < 180; x++) {
            // Convert the angle of the sine function to radians
            sinVal = (sin(x * (3.1412 / 180)));
            // Generate the sound frequency using the sine function value
            toneVal = 2000 + (int(sinVal * 1000));
            // Apply the tone to pin 10
            tone(10, toneVal);
    } else {          // If the temperature is less than 25 degrees Celsius, turn off the buzzer
        noTone(10);       // Turn off the buzzer
    if (millis() - tepTimer > 500) {     // Output the temperature value to the serial monitor every 500ms
        tepTimer = millis();
        Serial.print("Temperature: ");     // Print "Temperature" to the serial monitor
        Serial.print(data);         // Print the temperature value
        Serial.println("°C");         // Print the temperature unit


Code Explanation

Setup Function:

  • pinMode(10, OUTPUT);: Configures pin 10 as an output, which is connected to a buzzer.
  • Serial.begin(9600);: Initializes serial communication at a baud rate of 9600 bps for debugging and displaying temperature data.

Loop Function:

  • int val; and double data; are variables used to store the LM35 sensor reading and converted temperature, respectively.
  • val = analogRead(0);: Reads an analog value from analog input 0, connected to the LM35 sensor.
  • data = (double) val * (5.0 / 1024.0) * 100.0;: Converts the analog reading to a temperature value in degrees Celsius. The LM35 outputs a voltage proportional to temperature.

The following block checks if the temperature exceeds 25°C:

  • if (data > 25) {: If the temperature is above 25 degrees Celsius:
  • A for loop is used to create a sine wave sound with the buzzer, providing an audible signal.

If the temperature is below 25°C:

  • else {: If the temperature is 25 degrees Celsius or lower:
  • The noTone(10); command turns off the buzzer.
  • if (millis() – tepTimer > 500) {: Every 500 milliseconds (0.5 seconds), the code checks and outputs temperature data to the serial monitor.
  • tepTimer = millis(); updates a timer variable to keep track of time.
  • Serial.print(“Temperature: “); prints “Temperature” as a label.
  • Serial.print(data); prints the temperature value.
  • Serial.println(“°C”); prints the temperature unit.

More content you may be interested in

Arduino MQ-3 Alcohol Sensor Project
Arduino MQ-3 Alcohol Sensor Project

Creating an alcohol sensing project with an MQ-3 sensor and Arduino allows for accurate alcohol concentration monitoring in environments like bars and factories. The MQ-3

Arduino Temperature Alarm Project
Arduino Temperature Alarm Project

This Arduino temperature alarm project effectively demonstrates how to create a practical temperature monitoring system. By utilizing the LM35 temperature sensor and a buzzer, it

Arduino Breathing LED Project
Arduino Breathing LED Project

A breathing light is an LED lighting effect that simulates the human breathing process, gradually increasing or decreasing in brightness within a specific cycle. This

arduino vibration sensor
Arduino Vibration Sensor Project

This Arduino project employs a vibration sensor, ball switch, and LED to detect tilt or collision events. The LED lights up when vibrations occur and

arduino smart robot car
Arduino Smart Robot Car DIY Tutorial

In this project, TechSparks will use Arduino to create a smart car project that can achieve Bluetooth remote control, obstacle avoidance, and line tracking functions.

Scroll to Top