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.
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 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);
delay(2);
}
} 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.
You Might Be Interested


This Arduino project utilizes the Keyes Infrared (IR) Proximity Sensor Module to create a proximity detector. When an object is detected within a certain range, an HW-480 Red/Green 2-Colour LED


This article showcases a beginner-friendly project that utilizes Arduino and touch-sensitive technology to control LED lights. The project involves building a simple circuit and programming the Arduino board to detect


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 sensor’s high sensitivity to alcohol,


Looking for a simple and efficient way to monitor your heart rate? Check out our latest project: the Arduino Heart Rate Monitor. With this easy-to-use device, you can keep track


This article will explore the Arduino Nano’s pinout, explaining each pin’s function and providing practical insights on how to effectively use them in your DIY projects—whether you’re working with digital


This article provides a comprehensive guide on using CMake and rosserial_client to compile and upload code to Arduino for larger Arduino projects, offering an alternative to the Arduino IDE. The


This Arduino project demonstrates how to create the internationally recognized Morse code distress signal “S.O.S” using an LED. By controlling the LED’s duration of illumination, it represents the pattern of


This project demonstrates the construction of a simple thermometer using an Arduino and a DS18B20 digital temperature sensor. The temperature data is displayed in both Celsius and Fahrenheit on a