Introduction
It might look like a small project at first glance, but don’t let that fool you. A motion-triggered alarm system like this packs a surprising amount of real-world value especially when you realize how much it teaches in the process. You’re not just wiring components and uploading code. You’re learning how sensors communicate, how microcontrollers respond, and how even basic systems can evolve into smart, responsive tools.
With a handful of parts and a bit of logic, you’ve put together a working device one that can detect motion and react immediately. That alone is powerful. But what really makes it stand out is where it can take you next. Maybe you start adding Wi-Fi alerts. Maybe you build in a camera. Maybe this small circuit becomes the first step toward something bigger a home automation setup, a security network, or even a robotics project.
What matters most is that you’ve built something useful. From scratch. With your own hands. That’s not just rewarding it’s the foundation of everything else you’ll create from here.
What is the DS18B20 Digital Temperature Sensor?
The DS18B20 is a reliable digital temperature sensor from Maxim Integrated, widely appreciated for its ease of use and precision. Unlike analog options like the LM35 which convert temperature into a voltage that needs further processing the DS18B20 communicates temperature data directly over a digital signal using the OneWire protocol. That alone simplifies integration and reduces signal interference.
What Makes DS18B20 Stand Out
Clean Digital Output
You don’t have to worry about signal noise or adding an ADC (Analog-to-Digital Converter). The DS18B20 handles everything internally and sends the temperature data straight to your microcontroller in digital form.
Handles Harsh Environments
There’s a waterproof version that comes sealed in a metal probe, making it perfect for outdoor setups, weather stations, aquariums, and even soil monitoring.
Covers a Broad Range
It works across a wide temperature span from -55°C to +125°C, and for the most common range (-10°C to +85°C), it maintains a precision of about ±0.5°C.
Multiple Sensors, One Wire
Each sensor has a unique 64-bit serial code. That means you can connect several DS18B20s to the same data line without any interference. This makes it great for distributed temperature sensing like in multi-room HVAC setups or greenhouse zones.
Flexible Power Options
It supports both traditional 3-wire connections (GND, VCC, Data) and parasite power mode which means it can run with just two wires by drawing power directly from the data line.
Why It’s a Favorite Among Hobbyists
You won’t need to manually calibrate analog voltages or deal with fluctuations.
Libraries like OneWire and DallasTemperature make it extremely easy to set up with Arduino.
Its digital signal holds up well over long wires, making it ideal when the sensor needs to be placed several feet away from the microcontroller.
What is an OLED Display and Why Use It?
OLED screens short for Organic Light Emitting Diode have become a go-to choice for electronics enthusiasts who want clear, efficient, and space-saving displays. If you’ve ever worked on a DIY project that needed real-time visual feedback, you’ll appreciate what a small OLED panel brings to the table.
In this setup, we’re using a 0.96-inch I2C OLED display, featuring a 128×64 resolution and powered by the SSD1306 driver. Despite its tiny footprint, it packs a surprising amount of visual detail.
Why Go with an OLED?
Clear, Crisp Output
Text and graphics are razor-sharp, and thanks to high contrast, the screen remains legible even in bright daylight.
Energy-Friendly
These displays sip power instead of guzzling it, which makes them ideal for battery-powered or always-on devices.
Perfect for Tight Spaces
Its small size means you can tuck it into compact enclosures, handheld units, or wearables without trouble.
Minimal Wiring
Since it communicates via I2C, it only needs two pins (SCL and SDA) freeing up most of your Arduino’s GPIO pins for sensors, actuators, or other modules.
Whether you’re displaying sensor readings, menu systems, or simple animations, this little screen handles it with elegance and reliability no backlight needed, and no visual compromise.
Pin Mapping and Wiring
Here’s how to connect the components to your Arduino Uno:
Sensor/Module
Arduino Connection
DS18B20 VCC
5V
DS18B20 GND
GND
DS18B20 DATA
Digital pin 2
DS18B20 + 4.7kΩ Resistor
Between DATA and 5V
OLED SDA
A4
OLED SCL
A5
OLED GND
GND
OLED VCC
5V
Important Note:
The DS18B20 requires a 4.7kΩ pull-up resistor between the DATA pin and 5V to function properly in normal-powered (3-wire) mode.
Required Components
Below is the complete list of components you’ll need. Each item is explained in terms of its function and connection method.
Component Name
Purpose
Connection/Usage
Arduino Uno
Microcontroller that runs the code and handles logic
Main controller via USB
DS18B20 Sensor
Measures temperature and sends data digitally
Data to D2, VCC to 5V, GND
OLED Display (I2C)
Displays temperature readings in real-time
SDA to A4, SCL to A5
4.7kΩ Resistor
Pull-up resistor required for DS18B20 data line
Between D2 and 5V
Breadboard
Prototyping platform for connections
Mounting components
Jumper Wires
Connect modules and sensors to the Arduino
General wiring
Understanding the OneWire and I2C Protocols
This project involves two major communication protocols:
OneWire (DS18B20 Sensor)
Single digital pin for both sending and receiving data.
Multiple devices can share the same bus.
Requires software control to manage timing (handled via OneWire library).
I2C (OLED Display)
Uses SDA (data) and SCL (clock) lines.
Each device has a unique address (e.g., 0x3C for SSD1306).
Ideal for reducing pin usage with display modules.
Installing Required Arduino Libraries
Before uploading the code, install these libraries via the Library Manager in Arduino IDE:
OneWire – For communication with DS18B20
DallasTemperature – High-level functions for reading DS18B20
Adafruit SSD1306 – Driver for OLED display
Adafruit GFX Library – Required for rendering text and graphics on OLED
Step-by-Step Hardware Assembly
Follow these steps carefully to build your digital thermometer on a breadboard.
1. Place the DS18B20 Sensor
Insert the DS18B20 into the breadboard.
Identify the three pins (flat side facing you):
Left: GND
Middle: DATA
Right: VCC
2. Connect the Pull-Up Resistor
Place a 4.7kΩ resistor between the DATA pin and 5V line on the breadboard.
This is essential for proper signal stability in OneWire communication.
3. Wire the DS18B20 to Arduino
DS18B20 Pin
Arduino Connection
DATA
Digital pin 2
VCC
5V
GND
GND
4. Connect the OLED Display (I2C)
OLED Pin
Arduino Connection
SDA
A4
SCL
A5
VCC
5V
GND
GND
5. Double-Check Your Connections
Ensure there are no short circuits or reversed wires.
Secure all jumper wires and verify orientation of the OLED and sensor.
Writing the Arduino Code
This code will:
Read temperature data from the DS18B20
Format the temperature reading
Display it on the OLED screen in real-time
Full Code:
Code:
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
// Pin assignment
#define ONE_WIRE_BUS 2
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
// Create objects
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
void setup() {
Serial.begin(9600);
sensors.begin();
// Initialize OLED
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(“OLED allocation failed”);
while (true); // Halt
}
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(10, 10);
display.print(“Starting…”);
display.display();
delay(1000);
}
void loop() {
sensors.requestTemperatures();
float tempC = sensors.getTempCByIndex(0);
Serial.print(“Temperature: “);
Serial.print(tempC);
Serial.println(” *C”);
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(10, 20);
display.print(“Temp: “);
display.print(tempC, 1);
display.print(” C”);
display.display();
delay(1000); // Read every second
}
Line-by-Line Code Explanation
#include statements bring in the necessary libraries for OneWire, temperature reading, and OLED display.
DallasTemperature sensors(&oneWire); uses the OneWire instance to interact with the DS18B20.
Adafruit_SSD1306 object is configured for 128×64 resolution and I2C communication.
In setup(), the sensor and display are initialized, and a startup message is briefly shown.
In loop(), the temperature is requested from the sensor and then printed to both the serial monitor and the OLED display.
Testing the Digital Thermometer
1. Upload the Code
Open Arduino IDE.
Select Tools > Board > Arduino Uno.
Choose the correct COM port.
Click Upload.
2. Open the Serial Monitor
Go to Tools > Serial Monitor and set baud rate to 9600.
You should see continuous temperature readings like: Temperature: 25.3 *C
3. Check the OLED Display
After initialization, the OLED should show a live temperature like:
Temp: 25.3 C
4. Physical Test
Hold the sensor with your fingers or place near a warm surface.
Observe the temperature increasing on the screen.
Remove it and watch it fall to ambient room temperature.
Advanced Display Formatting (Optional)
To make the display more readable and professional, consider:
Add degree symbol: Use \xB0 for the degree symbol (°)
Example: display.print(“\xB0”); display.print(“C”);
Add Fahrenheit conversion:
Code:
float tempF = tempC * 9.0 / 5.0 + 32.0;
display.print(tempF, 1);
display.print(” F”);
Animated transition: Fade or scroll effects using setRotation(), drawRect(), or invertDisplay() functions from Adafruit GFX.
Real-World Applications
This thermometer can be embedded in various practical projects.
1. Indoor/Outdoor Weather Station
Combine with DHT22 for humidity.
Add RTC module to timestamp readings.
2. Greenhouse Monitoring
Display real-time data on OLED and send logs to SD card.
Use relay to control a fan when temperature exceeds threshold.
3. Refrigerator/Freezer Monitoring
Use the waterproof version of DS18B20.
Add buzzer to alert if temperature rises above safe level.
4. Body Temperature Thermometer
Contactless enclosure with audio alert and display output.
Can be used for pets, livestock, or basic human readings.
Troubleshooting Guide
Issue
Cause
Solution
OLED not displaying anything
Incorrect I2C address or wiring
Use I2C scanner sketch to detect address
DS18B20 returns -127 or 85°C
Sensor not detected or faulty resistor
Check connections and 4.7kΩ pull-up resistor
Temperature updates slowly
Delay too long or poor loop logic
Reduce delay time or recheck loop
Display flickers or distorts
Poor power supply to OLED
Use capacitor or switch to better supply
Inaccurate readings
Sensor close to heat source (e.g., Arduino)
Extend wire and isolate sensor
Customization Ideas
Switch between Celsius and Fahrenheit with a push button.
Add buzzer alarm if temperature exceeds threshold.
Use LCD (16×2) instead of OLED for a classic interface.
Log temperature to SD card using a module like the Catalex SD Adapter.
Display on mobile device using Bluetooth (e.g., HC-05).
Detailed Insights on DS18B20 Temperature Reading
The DS18B20 sensor operates digitally, meaning it outputs temperature in digital format directly, eliminating the need for ADC (Analog-to-Digital Conversion). This makes it more resistant to noise and signal degradation, especially across longer wires.
How It Works Internally:
Internally, the sensor uses a silicon-based temperature measuring element.
It digitizes the analog signal and holds the reading in an onboard register.
When requested by a microcontroller via the OneWire protocol, the sensor sends back the temperature reading in a calibrated format.
Communication Process:
The Arduino sends a reset pulse.
The DS18B20 responds with a presence pulse indicating it’s connected.
A ROM command (to identify the sensor) and a function command (like “read temperature”) are sent.
The sensor responds with two bytes of data: one for the LSB (lower byte) and one for the MSB (higher byte).
The temperature is calculated by combining and interpreting these bytes.
Benefits of Digital Format:
Consistent output regardless of power supply voltage
Reliable over long wires
Supports multiple devices on the same data line, using unique 64-bit serial addresses
Understanding the OLED Display Interface
OLED displays work using organic semiconducting materials that emit light when a voltage is applied. In our 128×64 I2C model:
Each pixel is addressable via the SSD1306 controller.
The display operates via I2C protocol (2 wires only: SDA and SCL).
The Adafruit_SSD1306 and Adafruit_GFX libraries abstract low-level code, allowing simple text rendering, image drawing, and animation.
OLED Functionality Used in This Project:
setCursor(x, y) positions the text on the screen.
setTextSize() controls the size of the characters.
clearDisplay() resets the screen for the next update.
display() pushes the drawn content to the screen buffer.
Limitations:
OLEDs have a finite number of write cycles per pixel (burn-in risk if static content is displayed continuously).
Limited real estate (only 128×64 pixels), requiring efficient design of text and graphics.
Expanded Arduino Code Concepts
Modular Coding Advice:
Instead of writing everything inside loop(), you can modularize code for easier debugging and scalability:
Code:
void displayTemperature(float temperature) {
display.clearDisplay();
display.setCursor(10, 20);
display.setTextSize(2);
display.setTextColor(WHITE);
display.print(“Temp: “);
display.print(temperature, 1);
display.print(” C”);
display.display();
}
This function can then be called from loop() to handle all OLED display operations in one place.
Common Sensor Behaviors Explained
Behavior
Interpretation
Returns -127°C
Sensor not detected or disconnected
Returns 85°C consistently
Sensor just powered on and hasn’t been read properly
No reading at all
Pull-up resistor missing or too low in value
Display stuck or frozen
I2C display not refreshed (display() not called), or incorrect wiring
Serial prints but no display
I2C address mismatch; most common is 0x3C but can vary
How to Add °F/°C Toggle Feature with a Button
Add a push button to digital pin 7. In the code, set up a simple toggle:
Code:
bool useCelsius = true;
void loop() {
if (digitalRead(7) == LOW) {
useCelsius = !useCelsius;
delay(300); // debounce
}
float tempC = sensors.getTempCByIndex(0);
float tempF = tempC * 9.0 / 5.0 + 32.0;
if (useCelsius) {
displayTemperature(tempC, “C”);
} else {
displayTemperature(tempF, “F”);
}
}
This lets the user cycle between Fahrenheit and Celsius with one press.
Realistic Application Blueprint Examples
Let’s break down practical scenarios where this system can be adapted.
Home Room Thermometer
Mounted in a living room, this setup can track daily temperature changes.
Connect to an SD card or EEPROM for data logging.
Aquarium Temperature Monitor
Use waterproof DS18B20.
Set buzzer alarm if temperature falls below or exceeds safe thresholds for fish.
PC Cooling System
Place the sensor near GPU or motherboard.
Use relay or transistor circuit to power up fans at a threshold temperature.
Powering the System Autonomously
If you want to use the thermometer standalone (without USB/computer), here’s how:
Behavior
Interpretation
Returns -127°C
Sensor not detected or disconnected
Returns 85°C consistently
Sensor just powered on and hasn’t been read properly
No reading at all
Pull-up resistor missing or too low in value
Display stuck or frozen
I2C display not refreshed (display() not called), or incorrect wiring
Serial prints but no display
I2C address mismatch; most common is 0x3C but can vary
Use the barrel jack or VIN pin for input power between 7V and 12V if not using USB.
How to Waterproof the Sensor
For environments with moisture (greenhouses, aquariums, freezers), always use the waterproof version of DS18B20:
Encapsulated in stainless steel with epoxy seal
Available with 1m, 2m, or 5m cables
Ensure exposed wires are heat-shrinked or sealed with hot glue/silicone
Final Expansion Summary
This digital thermometer using DS18B20 and OLED:
Demonstrates sensor interfacing with the OneWire protocol.
Explains how to visualize real-time data on small form-factor displays using I2C.
Shows proper modular programming practices in Arduino.
Can be upgraded into full weather stations, mobile thermometers, IoT dashboards, and automation triggers.
Conclusion
Building a digital thermometer using the DS18B20 sensor and an OLED display is not only an excellent introduction to microcontroller-based projects but also a practical application that demonstrates how digital sensors, I2C communication, and display modules work in harmony. This project empowers beginners to grasp foundational electronics concepts such as digital temperature sensing, data processing with the Arduino, and real-time visual output on an OLED screen.
By integrating a 4.7kΩ pull-up resistor with the DS18B20 and properly configuring I2C communication for the OLED, users achieve accurate and responsive readings that can be trusted for everyday use. Whether you’re planning to build a DIY weather station, monitor room or equipment temperature, or simply practice your circuit-building and programming skills, this thermometer offers the flexibility and expandability needed to evolve into more advanced systems like WiFi-enabled monitors or logging solutions.
Its ease of assembly, minimal components, and real-world utility make it a rewarding project for hobbyists, students, and educators alike. With clear visual feedback, customizable code, and future-ready integration potential, this digital thermometer serves as both a functional tool and a stepping stone into the broader world of embedded systems and IoT.