Skip to content
You Start with one site
Amounts in Start with one site
Build · Farms and sites

The weather station: the weather where you are, not in the nearest town.

A farm decides when to irrigate from the rain reported in a town 20 km away, behind a hill. It rained there, not here, and the crop goes dry. Or the forecast says 6 °C for the night, the valley floor drops to 0 °C, and the frost takes the tea, the tomatoes or the young trees. A school or a site guesses the same way.

Build a weather station for your own ground. It measures the air in a proper shield, counts every millimetre of rain, and warns the right person before the frost and before the heat. Over a season it gives you the record you need to decide: rain per day, the coldest night, the hottest afternoon.

About KSh 8,697USD 67 in parts Printing: 14 to 18 hours Building: a weekend
Found this useful?
The box and the radiation shield from the model. The sensor hangs inside the shield, in the shade, with the air moving past it.

What you end with

A station that reports the temperature, humidity, dew point, pressure, rain and wind every minute, and sends an alert before a frost, in a heat wave, in heavy rain and in a gale, and when the station itself goes quiet. The record shows the minimum, the maximum and the rain of every day, in your own time zone.

Temperaturein a printed shield
Rain0.28 mm a tip
Wind10 min mean, 3 s gust
Readingsone a minute
Kept offline12 hours
Dayyour midnight
Why a shield. A bare sensor in the sun reads the sun, not the air. On a calm, sunny day it can read several degrees too warm, and at night a sensor that sees the open sky can read too cold. The printed shield is a stack of white louvres: they keep off the direct sun and the heat reflected from the ground, and let the air move past the sensor. The firmware also reads the BME280 only once a minute, so the sensor does not warm itself.

What you need

Rough prices for single parts bought online, in

Get the parts wherever suits you: a local electronics shop, or online. Pick a shop and each Find it link searches there.

#PartQtyAbout
1ESP32 DevKitAny 30 or 38 pin boardFind it1KSh 650USD 5.00
2BME280 moduleMust be a BME280: the look-alike BMP280 has no humidityFind it1KSh 390USD 3.00
3Weather meter kitRain gauge, cup anemometer and wind vane, each a plain switch or resistorFind it1KSh 4,550USD 35
4Resistors and capacitors3 x 10 k, 100 nF, 10 nFFind it5KSh 39USD 0.30
5PerfboardAbout 30 x 40 mm, for the pull-upsFind it1KSh 65USD 0.50
6Terminal strip, 8-way5.08 mm: the sensor cables land hereFind it1KSh 104USD 0.80
7PG7 cable glandsFour for the box, one for the shield roofFind it5KSh 260USD 2.00
8Sensor cableFour cores, for the BME280Find it1 mKSh 130USD 1.00
9M4 rod, nuts, washers170 mm each, stainlessFind it3KSh 325USD 2.50
10U-boltsRound a pole up to 42 mmFind it2KSh 390USD 3.00
11USB cable and 5 V adapter1 A or more; or the solar kit in step 6Find it1KSh 520USD 4.00
12Jumper wiresFemale to femaleFind it10KSh 130USD 1.00
13Screws4 x M3 x 10, 2 for the boxFind it6KSh 104USD 0.80
14ASA or PETG, whiteWhite for the shield: it must reflect the sunFind it350 gKSh 1,040USD 8.00
TotalKSh 8,697USD 67

Also: a 3D printer, a soldering iron, a measuring jug and a ruler for the rain check, a pole (a 1.5 to 2 m steel pipe), and an account on siliconwit.io (free).

The box open on the wall, and the radiation shield beside it drawn with four of its six plates and its arm left off, each part marked with its number from the parts list. In the box: 1, the ESP32 DevKit, on the left; 4, the resistors and capacitors, on 5, the perfboard, at the top right; 6, the terminal strip, low down; 7, the cable-gland nuts on the floor. In the shield: 8, the sensor cable, coming down from the cap's gland; 2, the BME280 module, hanging on it in the open middle; 9, the M4 rods and nuts that hold the stack.
Where each part goes, numbered as in the list above. The shield is drawn with four of its six plates and its arm left off, so the BME280 (2) shows where it hangs, in the shade under the cap. The weather meter kit (3) mounts on the pole and its cables land on the terminal strip (6).
The weather meter kit. The common kit has three parts. The rain gauge tips once for each 0.2794 mm of rain and closes a reed switch. The cup anemometer closes a reed once a turn: one pulse a second is 0.667 m/s. The vane is a ring of resistors, one for each of 16 directions. All three are passive, so the firmware reads them with pull-up resistors and no other parts. Use your kit's own figures if they differ.
The BME280. It measures temperature, humidity and pressure on one small chip, over I2C. Many cheap modules carry the BMP280 instead, which has no humidity; the firmware says "NOT found" for it. Buy the 3.3 V module, and check the chip's marking if you can.

The design, in 3D and on paper

Turn it, open Parts to hide the lid or the shield's plates, and use Section to cut through the shield and see the BME280 hanging inside. The parts carry the numbers of the parts list.

The weather station: the box, the lid, the shield's plates, cap and arm, and the parts inside. Drag to turn, pinch or scroll to zoom. Open in the full viewer.
A3 assembly drawing, first angle. At 1 to 1, the front view of the box with the lid taken off shows the ESP32 DevKit, the perfboard with its resistors and capacitors, the terminal strip and the four gland nuts, and the view from the left; sizes 80.8 by 144.8 by 36.8 mm. At 1 to 2, the shield from above and section B-B through its axis and the arm, hatched: six plates on three rods, the cap, the arm with its pole plate, and the BME280 hanging on its cable from the gland; louvres 120 mm across, 235.8 mm to the top of the pole plate. Balloons match the item list: parts 1 to 9 of the page, then 15 to 19 for the printed parts.
The A3 assembly drawing (click for the PDF). Sheets 2 to 5 give every size of the box, the lid, the shield plate and cap, and the arm.

Build it

Each step links to the lesson section that teaches it. Open one only when you need it.

Build track
Follow this build, one step at a time

Tick each step as you finish it. Your place is kept, so you can stop and come back.

1

Wire it on the desk

Wire it on the desk first, with the kit's cables plugged into the terminal strip, and take it outside only when it works.

Wiring drawing. BME280: SDA to GPIO 21, SCL to GPIO 22, VIN to 3V3, GND to ground. Rain gauge: one wire to ground, the other to GPIO 27, with 10 k to 3V3 and 100 nF to ground. Anemometer: one wire to ground, the other to GPIO 26, with 10 k to 3V3 and 10 nF to ground. Wind vane: one wire to ground, the other to GPIO 34, with 10 k to 3V3.
Open the drawing full size. The resistors and capacitors sit on the perfboard in the box, beside the board.
  • The reed switches bounce for a few milliseconds each time they close. The capacitors take off the worst, and the firmware ignores any second pulse too close to the first: 150 ms for the rain gauge, 4 ms for the anemometer.
  • The vane goes on GPIO 34. It is on the first ADC, which keeps working while the Wi-Fi is on; the second ADC does not.
  • Keep the BME280 cable to about 1 m, and twist SDA and SCL each with a ground wire. The bus runs at 100 kHz to suit the cable.
2

Set your station

At the top of the sketch: the height of the place, your time zone, and the two factors from the kit's maker.

// --- your station ---
const float ALTITUDE_M = 1600; // height above sea level, for the sea-level pressure (a map or GPS)
const long UTC_OFFSET_S = 3 * 3600; // your time zone in seconds, for "today" (UTC+3 shown)
const float MM_PER_TIP = 0.2794; // the gauge maker's figure; check it by pouring (see the README)
const float MS_PER_HZ = 0.667; // the anemometer maker's figure: m/s for one pulse a second
#define HAS_VANE 1 // 0 if you fit no wind vane
const float VANE_FIXED_OHMS = 10000; // the resistor from 3V3 to the vane pin
  • ALTITUDE_M turns the pressure at your station into the pressure at sea level, so you can set it beside a forecast. At 1660 m a station reads about 830 hPa; reduced to sea level that is about 1005.
  • UTC_OFFSET_S sets your midnight. The day's minimum, maximum and rain start again there, not at midnight in London.
3

Flash and check on the desk

Open weather_station/weather_station.ino in the Arduino IDE, choose ESP32 Dev Module, install PubSubClient, ArduinoJson (version 7) and Adafruit BME280, and upload. Compiled for the ESP32 with the esp32 core 4.0.0: 1.15 MB of flash (87 % of the default app space) and 76 KB of RAM for global data, with no warnings, with and without the vane and TLS.

The rain gauge and the anemometer are counted on interrupts. A task of its own takes the wind once a second, at a steady pace, so a slow connection never spoils a gust:

// once a second, at a steady pace, whatever loop() is doing: the wind sample, the vane, the rain minute
void sampler(void*) {
esp_task_wdt_add(NULL);
TickType_t wake = xTaskGetTickCount();
uint32_t prev = millis(), minuteStart = millis();
for (;;) {
vTaskDelayUntil(&wake, pdMS_TO_TICKS(1000));
esp_task_wdt_reset();
uint32_t now = millis();
portENTER_CRITICAL(&pulseMux);
float ms = wind.take(now - prev);
if (now - minuteStart >= 60000) { minuteStart += 60000; rain.nextMinute(); }
portEXIT_CRITICAL(&pulseMux);
prev = now;
float deg = -1;
#if HAS_VANE
long mv = 0;
for (int i = 0; i < 8; i++) mv += analogReadMilliVolts(VANE_PIN);
deg = vaneDecode(mv / 8.0f / 3300.0f, VANE_FIXED_OHMS);
#endif
xSemaphoreTake(lock, portMAX_DELAY);
windStats.add(ms);
vaneNow = deg;
if (ms > 0.3f) vaneMean.add(deg); // a vane in still air points anywhere: leave it out
xSemaphoreGive(lock);
}
}

The logic was tested on a laptop first; these lines come from those tests:

rain: 10 tips with 30 bounces counted as 2.79 mm; 200 mm/h kept every tip
rain: 100 ml in a 110 mm funnel in 37 tips = 0.2844 mm a tip
wind: 6 Hz = 4.00 m/s, bounces dropped
wind: a 1 s puff of 15 m/s is a gust of 7.0, a 4 s one a gust of 15.0
vane: all 16 directions decode with the resistor 5 % off; a broken wire gives -1
vane: 350 and 10 degrees average to 0, not 180
day: at UTC+3 the day turns at 21:00 UTC; yesterday kept as min 14.0, max 27.5, rain 1.6 mm
air: dew point at 20 C and 50 % is 9.26 C
air: 898.75 hPa at 1000 m and 8.5 C is 1013.28 hPa at sea level

Check the rain gauge. Pour 100 ml of water slowly, over a few minutes, through the funnel, and count the tips. mm a tip = 100 000 / funnel area in mm² / tips. A funnel 110 mm across has 9503 mm², so 37 tips is 0.2844 mm a tip. Send it with the mm_per_tip command.

Breathe on the BME280. Check: the humidity rises within a minute and falls again. Spin the cups by hand: wind moves. Turn the vane to north, east, south and west: dir reads about 0, 90, 180 and 270.
4

Print the shield and the box

ASA, or PETG, in white: the shield must reflect the sun. 0.2 mm layers, 3 to 4 walls, 20 % infill, no supports. About 350 g in all.

PartLay it
Shield plate (print 6)Outer edge and tabs down.
Shield capRoof down.
Shield armFlat on the bed, the pole plate standing up.
BoxOn its back, open side up.
LidFront face down, skirt up.

Each louvre is a cone at 45 degrees, so it prints with no supports. The rods pass through tabs outside the louvres, and the columns on the tabs stack one on the next, so nothing else holds the plates apart. Three M4 rods, a nut and a washer at each end, hold the stack, the cap and the arm together.

Checked in FreeCAD 1.1: the six louvres, the cap and the arm stack without touching, with 15 mm of air between louvres; the rods and the gland clear every part; the sensor hangs 8 mm from the axis in a 64 mm opening; and every module fits the box with 8 mm to spare under the lid.

5

Site it

Where the station stands decides what it measures. Weather services use these rules, and they are worth following:

  • The shield 1.25 to 2 m above short grass or open ground, not above concrete or a roof, and away from walls. Push the sensor up through the gland in the roof so the board hangs in the middle of the stack.
  • The rain gauge level, its rim clear of everything: a tree, a wall or a roof should be at least twice its own height away.
  • The wind sensors as high and open as you can. The standard height is 10 m; lower down the wind is weaker, so compare your station with itself, season to season, more than with a town.
  • The box on the pole below the shield, every cable entering from below through a gland.
On a sunny afternoon, hold a second thermometer in the shade of a wall nearby. Check: the two agree within about 1 °C.
6

Power: why it stays awake

A board that sleeps between readings uses far less power, and that is the right choice for a station with only temperature and rain: it can wake on each rain tip. But a gust is the highest 3 second mean in each 10 minutes, and a sleeping board cannot see a gust. So this station stays awake.

  • With the mains: a 5 V USB adapter, indoors, with the cable through a gland.
  • Away from the mains: a 10 W panel, a small solar charge controller, a 12 V 7 Ah battery and a 5 V buck converter, each positive lead fused. The board uses about 0.3 W, some 7 Wh a day; measure yours. The battery carries several cloudy days.
7

Connect it

On siliconwit.io, our monitoring service: Add Device, then Define my own device, with the fields of the reading below. Set the data interval to 60 seconds. To look around first, with no sign-up, siliconwit.io/try gives you a device for about 30 minutes. Copy the Device ID and Access Token into these lines, with your Wi-Fi above them, and upload again:

const char* MQTT_HOST = "mqtt.siliconwit.io";
const int MQTT_PORT = 8883; // MQTT over TLS
const char* DEVICE_ID = "SWD-XXXXXX"; // client ID, username, and the topic name
const char* MQTT_PASS = "your-access-token"; // the Access Token
#define USE_TLS 1 // 0 only for a test broker on your own network: then port 1883, and no certificate

One reading a minute, on d/<device-id>/t:

{"temp":18.4,"rh":71.2,"hpa":1012.6,"rain_1h":0.8,"wind":2.3,"gust":5.9,"sensor":1,"dew":13.0,
"rain_rate":1.7,"rain_today":2.8,"dir":225,"tmin":12.1,"tmax":24.6,"rain_yday":0.0,"ts":1795000630}

The link is MQTT over TLS on port 8883, with the ISRG Root X1 certificate in the sketch. After a failed connect it waits 5, 10, 20, 40, then 60 seconds. While the network is down it keeps up to 12 hours of readings and sends them later, each with its own time, and the rain keeps counting. A watchdog restarts the board if the code ever gets stuck. Your own Mosquitto broker works the same: change the broker lines, as on the live sensor node.

8

Make it act

This is where the weather stops being a surprise. Email alerts come with the free account (up to 10 rules); SMS with the Business plan. Rules can wait for a value to hold, so one cold minute does not wake anyone. Send each alert to the person who can act on it:

Frost comingtemp below 3, held for 15 minutes Heattemp above 35, held for 30 minutes Heavy rainrain_1h above 20 Strong windgust above 17 Sensor faultsensor equal to 0, held for 10 minutes Not reportingthe device silent for 15 minutes

Why 3 °C for frost: the air at shield height is warmer than the ground on a clear, still night, so the ground can freeze while the station still reads 2 or 3 °C. A low dew point (dew) on a clear evening says the night will cool fast. Change the numbers to suit your crop.

Commands set the factors from the device page, and each gets a reply:

d/SWD-XXXXXX/c {"command":"mm_per_tip","value":0.2844,"session":"a1"}
d/SWD-XXXXXX/k/a1 {"status":"ok"}
d/SWD-XXXXXX/c {"command":"altitude_m","value":1600,"session":"a2"}
d/SWD-XXXXXX/k/a2 {"status":"ok"}
d/SWD-XXXXXX/c {"command":"wind_factor","value":12,"session":"a3"}
d/SWD-XXXXXX/k/a3 {"status":"error","message":"wind_factor must be 0.05 to 5"}
// a command on d/<id>/c: run it, then reply on d/<id>/k/<session>
void onCommand(char* t, byte* data, unsigned int len) {
JsonDocument msg;
if (deserializeJson(msg, data, len)) return; // not JSON: ignore it
const char* session = msg["session"] | "";
const char* error = nullptr;
float n = msg["value"] | -1.0f;
if (msg["command"] == "mm_per_tip") { // after a pouring test
if (n >= 0.05f && n <= 2) { portENTER_CRITICAL(&pulseMux); rain.mmPerTip = n; portEXIT_CRITICAL(&pulseMux); }
else error = "mm_per_tip must be 0.05 to 2";
} else if (msg["command"] == "wind_factor") { // m/s for one pulse a second
if (n >= 0.05f && n <= 5) { portENTER_CRITICAL(&pulseMux); wind.msPerHz = n; portEXIT_CRITICAL(&pulseMux); }
else error = "wind_factor must be 0.05 to 5";
} else if (msg["command"] == "altitude_m") {
float a = msg["value"] | -9999.0f;
if (a >= -500 && a <= 6000) altitudeM = a; else error = "altitude_m must be -500 to 6000";
} else if (msg["command"] == "reset_rain") { // after cleaning the gauge, which tips it
portENTER_CRITICAL(&pulseMux); tipsSent = rain.tips; for (int i = 0; i < 60; i++) rain.minute[i] = 0; portEXIT_CRITICAL(&pulseMux);
day.rainMm = 0; pendingRainMm = 0;
} else {
error = "unknown command";
}
if (!error) saveSettings();
if (*session) {
char reply[128];
if (error) snprintf(reply, sizeof(reply), "{\"status\":\"error\",\"message\":\"%s\"}", error);
else snprintf(reply, sizeof(reply), "{\"status\":\"ok\"}");
mqtt.publish((topic("k/") + session).c_str(), reply);
}
}
9

Read the record

  • Rain per day. rain_today runs from your midnight; rain_yday is yesterday's total. Irrigate on what fell on your ground, not on the town's report.
  • The coldest night and the hottest afternoon. tmin and tmax are today's, in local time. A season of them shows where your place differs from the forecast, and by how much.
  • Rain rate. rain_rate is the rate over the last 10 minutes, in mm an hour. When it is high, much of the water runs off before it soaks in; how much depends on your soil.
  • Wind. wind is the 10 minute mean and gust the highest 3 second mean in those 10 minutes, as weather services report them. Spray when the mean is low and steady.
  • Pressure. hpa falling a few hPa in three hours often comes before rain.

The free account keeps 7 days of history. Share the device with up to 2 people, for example the farm manager and the school's science teacher.

You are done when

  • The temperature agrees with a second thermometer in the shade within about 1 °C, on a sunny afternoon.
  • 100 ml poured through the gauge reads what the funnel's size says, after you set mm_per_tip.
  • The vane reads the four main directions within one step.
  • An alert reaches your phone when you unplug the station for fifteen minutes.
  • After your first midnight, the reading carries rain_yday, and you know what the day's numbers mean for your crop.

Downloads

Checked: the firmware compiles for the ESP32 with no warnings in all its variants (with or without the vane and TLS). Its logic (the rain debounce and rate, the gauge calibration, the wind and the gust, the vane decoding and its mean, the day's minimum, maximum and rain at local midnight, the dew point and the sea-level pressure) passes 40 checks on a laptop, with the address and undefined-behaviour checkers on. The parts were checked in FreeCAD 1.1 with every module in place. A season outside is next: if yours needs a change, tell us in the discussion below.

References

  • Sampling intervals and aggregation: counters, gaps, and the daily boundary.
  • Power Management and Deep Sleep: the power budget of a weather node, and when to sleep.
  • WMO Guide to Instruments and Methods of Observation (WMO-No. 8): air temperature at 1.25 to 2 m in a ventilated screen, wind at 10 m, the gust as the highest 3 second mean.
  • Magnus formula with the coefficients of Sonntag (1990): a = 17.62, b = 243.12 °C.
  • BME280 data sheet: forced mode, and the humidity sensor that the BMP280 does not have.
  • Build: the live sensor node: the same firmware family, with one sensor.

Ways to take this build

Supervised, with an engineer

KSh 15,000USD 150 for the build

Four video meetings over about six weeks: plan it, show progress, show it working. Ends in a project record anyone can check.

Build it with a supervisor
On your own

Open to all

Every step, the firmware and the printable files. Tick the steps as you go.

Start step 1
For a team or a class

Priced for the group

Your staff or students build the weather station together, with reviews and a record for each person.

Ask for a group

Plus opens the worked answers in the lessons each step links to: see Plus.

Made by

Engineers who build what they teach, and answer for it.