Projects / Temperature threshold alarm

Temperature threshold alarm

Beginner40 minGuided buildReviewed
Arduino UnoD4A0D9D8GNDDS18B20LimitAlarmBuzzer
Serial at 9600 baud

Tap a part to see what it does.

Tap the parts to see what each one does. A teaching simulation, not a circuit simulator.

Build it step by step

0 of 4 done
  1. UNO

    Probe and pull-up

    Yellow to D4 with 4.7 kΩ to 5V.

  2. UNO

    Limit knob

    Wiper to A0.

  3. UNO11.8 mA

    LED and buzzer

    LED on D9 through 220 Ω, buzzer on D8.

  4. UNODS18B2023.9°C

    Set and test

    Turn the knob to just above room temperature, then hold the probe.

In short

How do you build a temperature threshold alarm?

A waterproof DS18B20 probe watches a fridge, aquarium or room. A knob sets the limit, and a buzzer and LED warn when it is crossed. You need Arduino Uno R3, DS18B20 Temperature Sensor, Resistor 4.7 kΩ, Potentiometer 10 kΩ, Active buzzer 5 V, LED 5 mm red, Resistor 220 Ω and Breadboard 830 Tie Points. It takes 4 steps and about 40 minutes.

Level
Beginner
Time
About 40 min
Parts
8

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
DS18B20 red / black5V / GNDPower
DS18B20 yellowD4, with 4.7 kΩ to 5V1-Wire data
Pot wiperA0 (ends to 5V and GND)Limit knob
D9 → 220 Ω → LEDAlarm light
BuzzerD8Alarm sound

Code

Libraries: OneWire and DallasTemperature. A missing probe also raises the alarm, because silence would be unsafe.

Runs on a virtual Arduino Uno in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).

#include <OneWire.h>
#include <DallasTemperature.h>
OneWire bus(4);
DallasTemperature probe(&bus);
const int LED = 9, BUZZ = 8;
bool alarm = false;

void setup() { Serial.begin(9600); probe.begin(); pinMode(LED, OUTPUT); pinMode(BUZZ, OUTPUT); }

void loop() {
  probe.requestTemperatures();
  float t = probe.getTempCByIndex(0);
  float limit = map(analogRead(A0), 0, 1023, 0, 500) / 10.0;   // 0.0 to 50.0 °C
  if (t == DEVICE_DISCONNECTED_C) { Serial.println("Probe missing"); alarm = true; }
  else if (t > limit + 0.5) alarm = true;
  else if (t < limit - 0.5) alarm = false;   // 1 °C of hysteresis
  digitalWrite(LED, alarm);
  digitalWrite(BUZZ, alarm && (millis() / 400) % 2);
  Serial.print(t); Serial.print(" C, limit "); Serial.println(limit);
  delay(500);
}

What the serial monitor should show

Open the serial monitor at the baud rate in the code. This is what our simulator prints for a virtual Arduino Uno with its sensors at their default values. Your numbers will follow your real readings, but the format should match.

24.50 C, limit 25.00

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
Hold the probeAlarm starts once it passes the limit + 0.5 °C
Let goAlarm stops only after it falls 1 °C, no chattering
Unplug the probe"Probe missing" and the alarm sounds

If it does not work

Reads −127

Missing 4.7 kΩ pull-up or yellow wire not on D4.

Reads 85 every time

Power-on value: the conversion did not finish; check supply wiring.

Limit jumps around

Pot wiper loose; average a few readings.

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the temperature threshold alarm?

Arduino Uno R3, DS18B20 Temperature Sensor, Resistor 4.7 kΩ, Potentiometer 10 kΩ, Active buzzer 5 V, LED 5 mm red, Resistor 220 Ω and Breadboard 830 Tie Points.

How long does the temperature threshold alarm take to build?

About 40 minutes for a beginner maker, in 4 steps.

How do I know the temperature threshold alarm works?

Hold the probe: Alarm starts once it passes the limit + 0.5 °C. Let go: Alarm stops only after it falls 1 °C, no chattering. Unplug the probe: "Probe missing" and the alarm sounds.

Reads −127: what should I check?

Missing 4.7 kΩ pull-up or yellow wire not on D4.

Reads 85 every time: what should I check?

Power-on value: the conversion did not finish; check supply wiring.

Limit jumps around: what should I check?

Pot wiper loose; average a few readings.