Build a Remote Temperature Sensor with Raspberry Pi and Python – Step‑by‑Step Guide
Build a Remote Temperature Sensor with Raspberry Pi and Python – Step‑by‑Step Guide
After years of refining this project based on community feedback, this updated guide delivers a ready‑to‑use IoT temperature sensor that runs on any embedded Linux board with Python and 1‑wire support. From a simple LED demo to a full‑featured remote monitor, you’ll learn how to assemble, configure, and deploy your own sensor in just a few hours.
What You’ll Create
Using a Raspberry Pi, a DS18B20 1‑wire temperature sensor, and a basic LED, you’ll build:
- A remote temperature logger that can be expanded with humidity or light sensors.
- A Wi‑Fi‑enabled device that reports data to a cloud platform (DeviceHive) and can be controlled via a mobile app.
- An example of how to replace the LED with a relay to switch room lighting.
Hardware List
- Raspberry Pi Rev. B (or any inexpensive embedded Linux board – e.g., Gumstix, BeagleBone).
- DS18B20 1‑wire temperature sensor (widely available).
- Any standard LED.
- Resistors: 510 Ω for the LED and ~4.7 kΩ for the DS18B20 pull‑up.
- Breadboard and jumper wires.
The schematic is straightforward: power the sensor from the Pi’s 5 V pin (pin 2). No external power is required.
Step 1 – Set Up Your Raspberry Pi
- Flash a fresh Raspbian image onto an SD card and boot the Pi.
- Use a reliable 5 V/1 A micro‑USB charger (a smartphone charger usually works).
- Configure network access: you can skip HDMI and USB peripherals by connecting via Ethernet, obtaining a DHCP address, and accessing the Pi with SSH (default credentials: pi/raspberry).
- Wire the sensor and LED to the breadboard according to the schematic.
- Load the 1‑wire kernel modules:
sudo modprobe w1-gpio sudo modprobe w1_therm
- Persist the modules across reboots by adding them to
/etc/modules:echo "w1-gpio" | sudo tee -a /etc/modules echo "w1_therm" | sudo tee -a /etc/modules
- Locate your sensor ID:
ls /sys/bus/w1/devices/
The directory will resemble28-00000393268a. - Verify the sensor works:
cat /sys/bus/w1/devices/28-00000393268a/w1_slave
Step 2 – Install DeviceHive on the Pi
- Download the latest DeviceHive package from devicehive.com.
- SSH into your Pi and create a working directory:
mkdir ~/devicehive
- Transfer the Python source from your host machine using
scp:scp -r ~/Downloads/devicehive/python/device/Source/* [email protected]:~/devicehive
- Visit DeviceHive Playground and sign up for a free account to receive your API key.
Step 3 – Run the Sample
Navigate to the devicehive/python/device/Source folder, edit the configuration with your API key, and launch the script. The sensor data will stream to DeviceHive, where you can visualize it on the web dashboard or trigger actions via the mobile app.
Expand the Project
With the basic framework in place, you can:
- Swap the LED for a 5 V relay to control room lighting.
- Attach additional 1‑wire sensors (humidity, light) on the same bus.
- Add MQTT or HTTP endpoints for custom integrations.
- Implement OTA firmware updates for long‑term deployments.
Enjoy building your first IoT device and explore endless possibilities with Raspberry Pi and Python!
Manufacturing process
- Build a Raspberry Pi Temperature Logger with a $5 I2C Sensor
- Accurate Raspberry Pi Temperature Profiling with Python, SQLite, and LabVIEW
- Connect Multiple DS18B20 1‑Wire Sensors to a Raspberry Pi for Accurate Temperature Monitoring
- TMP006 Infrared Temperature Sensor with Raspberry Pi: Python Library & Setup Guide
- Control an LED with a PIR Motion Sensor on Raspberry Pi
- Build a Multi‑Sensor Temperature & Light Monitoring System with Raspberry Pi & DS18B20
- Raspberry Pi–Based Bathroom Occupancy Sensor with Voice & SMS Alerts via Twilio
- Mastering Raspberry Pi Sensor & Actuator Control: Accelerometer, Servo, and Data Streaming
- Build a Raspberry Pi Home Temperature Monitor with MCP9808, InfluxDB & Grafana
- Build a Robot with Raspberry Pi and Python: A Complete Guide