Building a Budget Friendly Weather Station with Raspberry Pi Monitoring Temperature Humidity and More
How to Build a Raspberry Pi Pico Weather Station
Do you need a digital hydrometer to monitor the temperature and humidity in your home or office? Instead of buying one, now you can make your own with a Raspberry Pi Pico microcontroller board. When the project is complete, string the DHT sensor through a window for the most accurate weather readings (or use this project to monitor your indoor temperature).
In this tutorial, we utilize the Raspberry Pi Pico microcontroller to read temperature and humidity data and display the data on our 16x2 LCD screen. Unlike every other Raspberry Pi, the Pico (see our Raspberry Pi Pico review) is a microcontroller board, rather than a full-fledged Linux computer. That makes it great for handling lightweight projects, involving sensors and other electronic components, especially those that use analog input, something other Pis cant handle without an add-on board.
The Pico board can be programmed with C/C++ or MicroPython. We have chosen C/C++ for this tutorial. As a bonus, this tutorial also includes a basic installation of Pico SDK and cmake. If you wish to see this tutorial in MicroPython, please let us know in the comment section.
What Youll Need
Timing: This project is estimated to take at least 1 hour to complete, but we have included the final package file (UF2 file) as a short-cut method.
The majority of this tutorial is based on terminal commands. If you are not familiar with terminal commands on your Raspberry Pi, we highly recommend reviewing 25+ Linux Commands Raspberry Pi Users Need to Know first.
Setting up your Raspberry Pi Pico
1. This project requires pin connections to your Pico board. If you have not already done so, youll need to solder pins to your Raspberry Pi Pico. Connect your screen, mouse and keyboard to your Raspberry Pi.
2. Boot your Raspberry Pi. If you dont already have a microSD card see our article onhow to set up a Raspberry Pi for the first time or how to do a headless Raspberry Pi install.
Join the experts who read Tom's Hardware for the inside track on enthusiast PC tech news and have for over 25 years. We'll send breaking news and in-depth reviews of CPUs, GPUs, AI, maker hardware and more straight to your inbox.
3. Update Raspberry Pi OS. Open a terminal and enter:
sudo apt-get update && sudo apt-get upgrade
Test your Pico board with the C/C++ Blink sample code found here.
4. Download the blink.uf2 file from the C/C++ Getting Started guide.
5. While holding down the BOOTSEL button on your Pico board, connect your microUSB from your Pico board to your RaspberryPi.
6. Drag and drop the blink.uf2 file from your Downloads folder to RPI-RP2 removable media. Now watch the on-board LED on your Pico board start to blink. You can disconnect your Pico board from your Raspberry Pi for the next step.
Connect Your Pico to LCD screen and DHT22 Temp and Humidity Sensor
1. Place your Pico board on your breadboard.
2. With your jumper wires, connect GND from the Pico to the GND rail, Connect pin 36 / 3.3V to the power rail.
3. Connect your DHT22 sensor to the breadboard and connect GND to the GND rail, power to the power rail and the OUT signal to GPIO15 / Pin 20 (for 3 pin DHT sensors). If you are using a 4-pin DHT22 then include a 10K ohm resistor (see resistor color codes to identify) as shown in the circuit diagram.
4. For your LCD screen, connect SDA to Pin 6 and SCL to Pin 7.
5. To power your LCD screen, connect LCD VCC to VBUS (pin 40) on the Pico and LCD GND to the GND rail of your breadboard.
Short Cut Method - Pico Weather Station
If you are in a hurry to get your Pico Weather Station up and working, you can download the compiled UF2 build file here. Please note that using the compiled file does not allow you to customize the text or change the signal pins.
1. Download weatherstation.uf2 from here.
2. Disconnect your Pico board from your Raspberry Pi.
3. Hold down the BOOTSEL button while connecting your Pico board to your Pi. You should see a pop-up and RPI-RP2 appear as removable media.
4. Drag and drop weatherstation.uf2 to your Pico labeled RPI-RP2 from your downloads folder in your file manager.
In a few seconds (to a minute) you should see your room temperature and humidity display on the LCD screen.
Full Instructions: Raspberry Pi Pico Weather Station
This method produces the same outcome, an LCD that displays temperature and humidity, but you will learn how to compile source code for the Pico board. This method also includes a basic installation of the pico-sdk for users starting from scratch. For a more comprehensive installation with more examples, check out Getting started with Raspberry Pi Pico C/C++ dev PDF here.
1. Open a Terminal on your Raspberry Pi desktop (press Ctrl-T).
2. Well start by creating a directory and cloning the code we need to compile C/C++ for the Pico board with the following commands.
mkdir weather-stationcd weather-stationgit clone -b master https://github.com/raspberrypi/pico-sdk.gitcd pico-sdkgit submodule update --initcd ..git clone https://github.com/carolinedunn/pico-weather-station
3. Install cmake with the appropriate dependencies for Pico. This step could take around 5 minutes on a Raspberry Pi 4.
sudo apt updatesudo apt install cmake gcc-arm-none-eabi build-essential
4. Now is a great time to take a look at the source code well use to build our weather station.
Optional: Navigate to /home/pi/weather-station/pico-weather-station and open weatherstation.c with Geany in your File Manager to review the source code.
Code Notes for weatherstation.c
- weatherstation.c is the main source file for our project today.
- Line 17: We set our Pico to read our DHT from GPIO15. You can set up multiple DHTs or change your GPIO pin here.
- Line 199-200: This printf statement is for troubleshooting purposes and can only be accessed via minicom. Accessing readings via minicom will be discussed in the troubleshooting section.
- Line 202: We will display Farenheit readings in this weather station. You can change the reading to Celsius.
- Line 211: Display an updated temperature at 2 second intervals (or 2000 milliseconds).
Compile the C/C++ code and transfer to Pico
5. In the same terminal from Step 3, enter the following commands to build your UF2 file.
cd pico-weather-stationmkdir buildcd buildexport PICO_SDK_PATH=../../pico-sdkcmake ..make
Image 1 of 2
6. Navigate to /home/pi/weather-station/pico-weather-station/build
7. Disconnect your Pico board from your Raspberry Pi.
8. Hold down the BOOTSEL button while connecting your Pico board to your Pi. You should see a pop-up and RPI-RP2 appear as removable media.
9. Drag and drop weatherstation.uf2 to your Pico labeled RPI-RP2 from your downloads folder in your file manager.
In a few seconds (to a minute) you should see your room temperature and humidity display on the LCD screen.
Once you get your Pico Weather Station working, you can add an LED or a buzzer if the temperature or humidity goes above (or below) a threshold.
Battery Operated and Portable Solution
You can now power the Pico without use of the Raspberry Pi. Simply unplug the USB from the Raspberry Pi (connected to the Pico) and plug in to your power bank charger or USB power adapter.
Troubleshooting Guide
- LCD screen is powered on but blank: Adjust the potentiometer on the reverse side of your LCD screen.
- Temp and Humidity are always zero: Adjust the timing in line 156. if (count > 46).
- LCD screen is working, but Id like to see the raw temp/humidity data: Open a new terminal and type in the following commands:
sudo apt install minicomminicom -b 115200 -o -D /dev/ttyACM0
Running minicom will tax the Picos 2040 chip. Data will freeze and you will see a few bad data readings. This is ok.
Raspberry Pi weather station: build your own temperature monitor
Come rain or shine, a Raspberry Pi weather station makes a great project. With a budget of around $100, Peter Kodermac built a Pi-powered weather station that captures temperature data, graphs it, and publishes it online. His website provides step-by-step instructions to walk you through the process, which involves some simple wiring, and setting up the Raspberry Pi as a web server.
For theRaspberry Pi weather station sensor, Peter recommends the DS18B20. Its waterproof and comes with a long cable so you can keep the sensor away from the weather station, which might generate heat. The DS18B20 doesnt measure humidity, so if you want to track humidity, try the DHT22 instead. Peter warns that the DHT22 tends to give less consistent values and can take more than one attempt to get a reading. Peters code, available through GitHub, is designed to compensate for that, automatically retrying where necessary.
Peter uses a Pi Cobbler breakout cable and a breadboard to make it easy to connect the sensor to the Raspberry Pi. Make sure you buy the correct Cobbler cable for the model of Raspberry Pi you are using! Everything is housed in a plastic food box, with a hole for the power cable to go in, and for the sensor cable to come out. A wooden roof offers shelter, and Peter puts silica gel sachets inside the box to offer additional protection from moisture.
Raspberry Pi weather station circuit
The DS18B20 is a waterproof temperature sensor that gives consistent and fast results. You could use the DHT22 sensor instead, which also measures humidity
The Pi Cobbler breakout cable connects all the GPIO pins to the breadboard, making it easy to connect the sensor to the pins on the Raspberry Pi
The plastic box protects your Pi from the rain. The plastic lid and wooden roof are not shown here. This Pi is externally powered, but you could use a sealed box with a battery inside
Setting up the Raspberry Pi weather station
There were several stages involved in setting up the software for Peters Raspberry Pi Weather Station. First, he installed MySQL and used it to create a database for WordPress, which he uses to store the weather data. Then he installed and configured Apache and WordPress. He installed the Raspberry Weather plugin for WordPress, to generate a graph of the latest temperatures when anybody viewed the webpage. Finally, he used a Python script to query the sensor and put its data into the database, and Cron to schedule the script to run every 30 minutes. The whole process of setting up a web server can be a bit frustrating at times, but it is totally worth the time and effort, Peter says. Its just so great to build your site from scratch and see other people visit it and give you feedback!
Peter has run the project on almost all versions of the Raspberry Pi. WordPress is a bit of a memory hog, so the website loads more slowly on the Pi Zero, or older versions of the Pi. Thats why I also included a neat caching trick to speed up things a bit.
You can also monitor the results on your Android phone, using an application called My Weather Station. It displays the latest data from an XML file, which is updated in parallel with the main WordPress database.
Since Peter shared his weather station design, other makers have added cameras, wind-speed and air-pressure sensors, and are calculating forecasts. If you build one, let Peter know. I have always felt great pride in publishing links to the people who have completed the guide, he says. I get a nice fuzzy feeling when other people improve my code, too all thanks to open source.
Three Weather Station Projects for Raspberry Pi
- Even if you dont have a weather station, you can access the database of Pi Weather Station readings, and use it to plot temperatureson a map using Python.
- The official Weather Station HAT is being used by schools to record data, including humidity, pressure, and air quality readings,in an Oracle database
- Use Scratch to display your weather data, including a thermometer, along with a visual indicator for wind speed and direction. A Python script is used to feed the data to Scratch.
Win! One of ten PaPiRus Zero Screen and Case kits. Click here to enter.