Build a Multi‑Sensor Temperature & Light Monitoring System with Raspberry Pi & DS18B20
Build a Multi‑Sensor Temperature & Light Monitoring System with Raspberry Pi & DS18B20
What You’ll Need
- 2 × DS18B20 digital temperature sensors
- 2 × 4.7 kΩ pull‑up resistors
- Standard breadboard, jumper wires, and a 3.3 V power source from the Pi
- Optional: 47 Ω resistor, 1 × LED, female‑to‑male jumper wire for an indicator
Understanding the DS18B20 and 1‑Wire Protocol
The DS18B20 is a highly reliable sensor that can share a single GPIO pin with multiple devices thanks to the 1‑Wire protocol. Each sensor carries its own unique address, so the Raspberry Pi can read each one independently.
Setting Up the Breadboard
Most breadboards have a pair of power rails—red for +3.3 V and blue for GND. These rails connect all attached wires on their respective sides, making it simple to add more components later.
The central section of the board consists of rows split into two halves by a vertical gap. Connecting a wire to one side of a row links it to all other pins on that side but not to the opposite half.
For the DS18B20, the pinout is:
- Pin 1: GND
- Pin 2: Data (connected to GPIO4 on the Pi)
- Pin 3: VDD (3.3 V)
Place a 4.7 kΩ resistor between Pin 2 and Pin 3 to provide the required pull‑up. Wire Pin 1 to the blue GND rail and Pin 3 to the red 3.3 V rail. Repeat the same setup for the second sensor.
Programming the Pi
Insert a Raspbian SD card, power on the Pi, and open a terminal. Log in with the default credentials (pi / raspberry) and run:
sudo python dstemp.py
The first execution loads the necessary drivers; subsequent runs display temperature readings from each sensor every few seconds.
Verifying Sensor Operation
- Touching the sensor gradually raises its reading.
- Blowing warm air or using a hair dryer accelerates the rise.
- Applying an ice cube quickly drops the temperature.
- Occasional spurious values (e.g., 0.06 °C) can appear but are typically one‑off.
Press Ctrl+C to exit.
Adding a Second Sensor
With the Pi powered down (sudo halt), insert the second DS18B20 into the breadboard, connect its pins as described, and power the Pi again. Running sudo python dstemp.py should now show readings from both devices.
Adding an LED Indicator
To light an LED when sensor 1 exceeds 25 °C, add the following components:
- Female‑to‑male jumper from GPIO 24 to the LED’s anode (long leg)
- LED (any color)
- 47 Ω resistor from the LED’s cathode (flat side) to the blue GND rail
Modify your Python script to monitor sensor 1 and toggle GPIO 24 accordingly. Remember to keep the Pi powered off while wiring.
For more detail: Raspberry Pi Temperature and Light Sensor
Manufacturing process
- Build a Raspberry Pi Temperature Logger with a $5 I2C Sensor
- Connect Multiple DS18B20 1‑Wire Sensors to a Raspberry Pi for Accurate Temperature Monitoring
- Build a Remote Temperature Sensor with Raspberry Pi and Python – Step‑by‑Step Guide
- Seamless Temperature & Humidity Monitoring on Raspberry Pi with EzTemp
- How to Connect a DS1820 One‑Wire Temperature Sensor to a Raspberry Pi Using GPIO
- Raspberry Pi–Based Bathroom Occupancy Sensor with Voice & SMS Alerts via Twilio
- Mastering Raspberry Pi Sensor & Actuator Control: Accelerometer, Servo, and Data Streaming
- Build an Automated Aeroponics System with Raspberry Pi and Humidity Sensor
- Raspberry Pi Light Sensor Tutorial – Wire an LDR and Read Light Levels with Python
- Build a Raspberry Pi Home Temperature Monitor with MCP9808, InfluxDB & Grafana