As time permited, over the past few months, I’ve been learning how to turn my Raspberry Pi into a simple weather data logger. Right now, it’s sitting in my office with a waterproof SHT30 sensor connected to it. The SHT30 measures both temperature and humidity and communicates through something called I²C (Inter-Integrated Circuit). This is a communication protocol that allows multiple sensors or devices to share just two wires (one for data and one for clock). It’s a convenient way to connect digital sensors directly to the Pi’s GPIO pins.
Writing the Script
My Python script reads the sensor every 20 minutes and sends the data to a Google Sheet through Google’s API. Each reading is sent as a small JSON object. I’ve learned this is basically a structured data format that makes it easy for the Google Sheet to interpret each entry as a new row.
Here’s what happens in the python script:
- The script initializes the I²C connection and verifies the sensor is working.
- It connects to Google Sheets using a service account key file.
- It reads the temperature (in °C and °F) and humidity from the sensor.
- It sends a timestamped row of data to the sheet.
- It waits for 20 minutes, then repeats the cycle.
Everything worked great manually until I realized the script would stop if I closed my SSH session or rebooted the Pi. Today I decided to make the process fully automatic.
Running Automatically with a Service File
I learned that Linux uses something called systemd services to manage background tasks. By creating a small text file called a service file, you can tell the operating system to start your program automatically on boot and restart it if it ever stops.
[Unit]
Description=Weather Sensor Data Logger
After=network-online.target
Wants=network-online.target
[Service]
Type=simple
User=pi
WorkingDirectory=/home/pi
ExecStart=/usr/bin/python3 /home/pi/sht30_continuous.py
Restart=always
RestartSec=10
StandardOutput=journal
StandardError=journal
# Resource limits
Nice=10
CPUQuota=50%
[Install]
WantedBy=multi-user.target
My service file includes the Python script path and tells the Pi to keep it running continuously. Once installed, it’s easy to manage using simple commands like:
sudo systemctl enable weather-sensor-service
sudo systemctl start weather-sensor-service
sudo systemctl status weather-sensor-service

When I ran it for the first time, there were a few path errors, mostly because I had changed my Raspberry Pi’s hostname, which affected the file paths in the service definition. After fixing those, everything started up cleanly.
What’s Next
Now that I have reliable, automated readings flowing into Google Sheets, I plan to expand this setup into a small weather station for my garden. The next sensors I’ll add are soil moisture probes, an anemometer, a rain gauge, and a wind vane. Some of these use analog outputs, which means I’ll need to convert those signals to digital form for the Pi to understand. I’ll also need to think about waterproofing the hardware, especially the Raspberry Pi itself, and eventually running the system off solar power with Wi-Fi connectivity.
This has been a great exercise in combining hardware, Python programming, and cloud integration. The result is a simple but powerful data logging system. I’m sure there is a hardware solution available cheaply online that will accomplish something similar. For now, I am enjoying customizing a system and building a better understanding of how to make small computers like the Raspberry Pi work in custom ways.
