Accurate Temperature Monitoring in a Server Closet with Raspberry Pi
The Problem
After renovating my home office I dedicated a closet for all my electronics – servers, NAS, AV receiver, and more. I installed an exhaust fan to vent hot air into the adjoining office, but the closet still stays around 90 °F (32 °C) even with the fan running. Although this is within most hardware limits, it’s warmer than I’d like. To determine whether additional cooling is necessary, I needed a reliable way to record temperature changes over several days.
Using a Raspberry Pi for this task is ideal. I had previously worked with the analog TMP36GZ sensor on an Arduino, but the Pi’s GPIO pins are digital only, making an analog sensor unsuitable without an extra ADC. I wanted a straightforward solution that allowed me to start coding immediately.
The DS18B20 digital temperature sensor solved the problem. It communicates over a single‑wire bus, which fits perfectly with the Pi’s BCM GPIO4 (pin 7). The sensor can be accessed directly from the Linux terminal, and multiple DS18B20 units can share the same data line.
The Build
- Use a short length of CAT5e cable and solder the DS18B20’s three pins: orange = +3.3 V, brown = GND, green = DATA.
- Install a 4.7 kΩ pull‑up resistor between the 3.3 V and data lines.
- Wrap the exposed wiring in electrical tape and shrink‑wrap the bundle for protection.
- Attach female jumper connectors to the cable’s end for quick connections to a splitter.
- Create two 2‑male‑to‑1‑female Y‑splitters to combine VDD, GND, and DATA from two sensors into the Pi’s single pin.
- Connect the splitters to the Pi: 3.3 V to pin 1, GND to pin 6, DATA to pin 7.
- Place the sensors inside the closet – one on each side of the exhaust fan – to capture temperature variation.
Below is a photo of the finished build. Notice the three splitters neatly plugged into the Pi’s GPIO pins.
Reading the Sensor from the Terminal
Once the DS18B20s are wired, you can read their output directly from the file system. The following commands load the necessary kernel modules, list available devices, and display the temperature data for a chosen sensor.
# Load the 1‑Wire drivers
sudo modprobe w1-gpio
sudo modprobe w1-therm
# List attached devices (e.g., 28-0000055f311a)
ls /sys/bus/w1/devices
# Read the temperature from a specific sensor
cat /sys/bus/w1/devices/28-0000055f311a/w1_slave
The w1_slave file returns two lines. The first line contains a CRC check; the second line ends with t=XXXXX, where XXXXX is the temperature in thousandths of a degree Celsius. Convert it to Fahrenheit if desired.
With this setup, you can log readings to a CSV file, push data to a remote server, or trigger alerts if temperatures exceed a threshold. The DS18B20’s accuracy is ±0.5 °C, making it more than sufficient for routine hardware monitoring.
For more detailed instructions and sample code, visit Raspberry Pi GPIO documentation and Adafruit’s DS18B20 guide.
Manufacturing process
- Build a Raspberry Pi Temperature Logger with a $5 I2C Sensor
- Efficiently Monitor Room Temperatures with Raspberry Pi and Nagios
- How to Read Temperature with a DS18B20 on Raspberry Pi 2
- Professional Raspberry Pi Temperature Monitoring with DS18B20
- Measuring Temperature on Raspberry Pi with Maxim 1‑Wire Sensors and DS2482 I2C Bridge
- Home Energy Centre: Monitoring Solar PV, Thermal Panels, and Room Temperatures with Raspberry Pi and Moteino
- Remote Weather Monitoring with Raspberry Pi 3 and PubNub
- Raspberry Pi‑Based Room Temperature Monitoring with Gnuplot Graphs and Email Alerts
- Build a ThingSpeak Temperature Monitor with Raspberry Pi & BrickPi
- Build a Raspberry Pi Home Temperature Monitor with MCP9808, InfluxDB & Grafana