Introduction: DIY Weather Station With ESP32
Hello! Today we are going to look at this smart weather station I built. The weather station I built measures temperature, humidity, air pressure, wind speed and direction, and the amount of rain that falls. All the data is collected by an ESP32, which is a kind of Arduino, and via wifi it is sent to the mobile app. On the app, or on the web page, we can see real-time data from the weather station and graphs, for example of the temperature, with minimum and maximum of every day, and the pressure graph, which we can use to make a rough weather forecast. If this sounds difficult, don't worry, in this guide you can find all the informations.
To see more details about the construction, watch the video on YouTube (it is in Italian but it has English subtitles ).
Supplies
To build the weahter station, we will need:
- ESP32 board with external wifi antenna
- micro usb cable
- plastic box for the electronics
- DHT22 temperature and humidity sensor
- BMP180 pressure sensor
- various wires and cables
- 3D printer white filament
- 5v to 3,3v level shifters
- 6 Hall effect sensors
- perfboard
- M4 and M5 threaded rods
- M4 and M5 bolts and nuts
and a lot of other things i forgot to add to the list!
Tools:
- 3D printer
- soldering iron
- drill
- hot glue
- computer
Also, to connect the project to the app you need to have Home Assistant running on a raspberry pi or on a computer. If you don't have Home Assistant you can connect the weather station to Blynk , but you need to write the code for it. If you write the code for Blynk, if you like you can share it so others can use it.
Step 1: Temperature Sensor
To measure temperature and humidity I will use the DHT22 sensor. I soldered the sensor onto a perfboard, with a connector and a pull-up resistor between 3,3v and the signal pin. I put the sensor inside a Stevenson screen. The Stevenson screen protects the sensor from direct sun and rain, while allowing air to pass through. By avoiding the sun to heat the sensor, it allows to get more accurate temperature readings. To build it, I 3D printed all the parts, and attached them togheter with two threaded rods. I glued the perfboard with the sensor inside the Stevenson screen, and underneath I put the bracket that will hold the sensor up.
Down here you can find all the 3d printable files for the Stevenson screen.
Stevenson Screen 3
Step 2: Wind Vane
Then we have the wind vane, which detects which direction the wind is coming from. Also for this one I had to make some parts with the 3D printer. The wind vane has this arrow-shaped piece at the back and the tip at the front, with a bolt inside as a weight to balance it. The flag can rotate freely with a ball bearing that I put in the base. To detect the 4 cardinal points from which the wind comes (north, east, south, west) I will use 4 hall effect sensors, which are magnetic sensors that are activated when a magnet approaches.
My idea is to put the hall sensors like shown in the second photo, with the magnet spinning and activating the sensor of the cardinal point towards which the flag is turned. For intermediate points, e.g. north-east, the two corresponding sensors (north and east) will be activated. I have placed the magnetic sensors here on the base of the wind vane, raised of about 1 cm to keep them away from the metal bolts which can attract the magnet. On the upper part, that is free to rotate, I glued the magnet. This piece also has the function of protecting the sensors from the rain. I inserted the actual wind vane onto the threaded rod, and secured it with a self-locking nut. The hall sensors each have 3 wires, which go to their original board with the little LED, which is useful to see if the sensors work correctly. I soldered the four boards onto a perfboard. From there I used an old network cable to bring gnd and 5v to the sensors and the four signal pins to the main board, which we will see later. I put the four sensor's boards in this 3d printed box, with a piece of acrylic on top.
Down here you can find all the 3d printable files.
Wind vane
Step 3: Anemometro
Now comes the anemometer. I already talked about this in a video last year, which you can find here . I also made the anemometer with the 3D printer, and below you can find the STL files. The anemometer is composed of the base and the rotating part. For the rotating part, the cups and the center piece are printed separately and assembled with 3 screws. Inside the anemometer there is a magnetic hall sensor on the base and a magnet on the rotating part. The sensor sends out an impulse at each revolution. From the revolutions per minute we can calculate the wind speed, but at the moment I don't know what number I have to multiply the revolutions per minute by to get km/h. If someone knows how to calculate it, please write those calculations in the comments below. By what I found online, a rough (an probably wrong) estimation is to multiply the rpm by 0,18.
Anemometer
Attachments
Step 4: Rain Gauge
Lastly, there is the rain gauge. I showed this in a previous Instructable , so you can find all the details there, including the 3D printable files. However, this also uses a magnetic sensor, and each change of state of the sensor means that a certain amount of water has passed through. The rain is measured in mm of height.
Step 5: Aluminium Frame
To make it easier to mount the weather station in it's final collocation, I will put the various sensors on a single structure. To make it, I used a rectangular aluminium profile. In the centre I fixed the rain gauge, and on the two sides I put the anemometer and the wind vane. To hold everything up I cut two more pieces of aluminium profile. On one side of them I made this nice big hole, which allows me to fix them without having the bolt sticking out underneath. After bolting everything togheter, this is the result. This step is optional, because if you want you can mount the single sensors on a structure you already have, for example the side of a roof.
Step 6: Electronics and Pressure Sensor
But now we have all the electronics, which will be in this junction box. To make the connections easier, I bought this board that carries the ESP32 pins on terminals. I don't know why, but my ESP32 doesn't fit on this board. So I had to make adapters with a perfboard to move the pins. I screwed the ESP32 in the box, and on the underside I put the antenna for the WiFi connection.
I almost forgot about the atmospheric pressure sensor, which is the BMP180. I put it here in the box, and to let the air pass through I made this grid on the underside. This sensor communicates via i2c, so it needs two wires to connect to the ESP32, other than 3,3v and GND.
Now we have all the other sensors coming in here with their wires. The temperature sensor has only one signal wire, and it connects directly to an ESP32's pin. The problem are the hall sensors of the anemometer, rain gauge and wind vane, which operate at 5v, while the ESP32 operates at 3.3v. So to convert the signal from 5v to 3.3v I will use some level converters, like these. To make everything neater, I soldered them onto perfboards. To make the connections between the boards and the ESP32 I used JST connectors, which are more solid than classic jumpers. Finally, I joined together the wires for gnd, 5v and 3.3v, and tidied up the wires with cable ties.
Above you can find the schematics for all the electrical connections for the sensors.
Step 7: Home Assistant
The weather station will be connected to Home Assistant, which is a kind of local server for controlling the various home automation devices we have in our home. Home Assistant can be run on a Raspberry Pi or on a computer on a Virtual Machine, like I do. To connect the weather station to Home Assistant I will use ESPhome, which allows you to connect the ESP32 to Home Assistant. After setting everything up, I can see the weather station data in real time, either from the web page or the app. In addition, the data is recorded, and I can also see graphs of the long-term trend.
Step by step:
- Install Home Assistant on a Raspberry or on a computer with a Virtual Machine, if you haven't already done it (there are many tutorials online for the different systems)
- From the official add-on store, install ESPhome
- Add a new device in ESPhome and select ESP32
- In the space for the ESPhome code, paste the following code after the one provided by ESPhome, and insert wifi ssid and password where needed
i2c: sda: 21 scl: 22 scan: true id: bus_a sensor: - platform: dht pin: 4 temperature: name: "Temperatura esterna" humidity: name: "Umidità esterna" update_interval: 10s - platform: pulse_counter pin: 23 count_mode: rising_edge: INCREMENT falling_edge: INCREMENT unit_of_measurement: 'mm' name: 'Pioggia istantanea' filters: - multiply: 0.173 total: unit_of_measurement: 'mm' name: 'Pioggia' accuracy_decimals: 3 filters: - multiply: 0.173 update_interval: 5s - platform: bmp085 temperature: name: "Temperatura centralina" pressure: name: "Pressione esterna" update_interval: 10s - platform: pulse_counter pin: 19 unit_of_measurement: 'Km/h' name: 'Velocità del vento' filters: - multiply: 0.18 update_interval: 5s - platform: uptime name: Uptime binary_sensor: - platform: gpio pin: 33 name: "Vento direzione NORD" - platform: gpio pin: 25 name: "Vento direzione OVEST" - platform: gpio pin: 26 name: "Vento direzione SUD" - platform: gpio pin: 27 name: "Vento direzione EST"
- Click install and on plug into computer , and connect the ESP32 to the computer with the micro usb cable
- Follow the instructions on screen to install the code on the ESP32
Step 8: Wind Vane Configuration
The wind vane gives the states of the four sensors separately as binary sensors (on or off). To convert these four values to a more esay to read format (e.g. north or south-west ) we have to create a custom sensor in Home Assistant. There is some code but it is very esay.
- To create the custom sensor, we have to edit the configuration.yaml fiel
- For that we need to have the file editor plugin installed or something equivalent
- Paste the following code under sensor:
sensor: - platform: template sensors: direzione_vento: friendly_name: Wind direction value_template: >- {% if states('binary_sensor.vento_direzione_ovest') == 'off' and states('binary_sensor.vento_direzione_nord') == 'off' %} NORTH-WEST {% elif states('binary_sensor.vento_direzione_est') == 'off' and states('binary_sensor.vento_direzione_nord') == 'off' %} NORTH-EAST {% elif states('binary_sensor.vento_direzione_ovest') == 'off' and states('binary_sensor.vento_direzione_sud') == 'off' %} SOUTH-WEST {% elif states('binary_sensor.vento_direzione_est') == 'off' and states('binary_sensor.vento_direzione_sud') == 'off' %} SOUTH-EAST {% elif states('binary_sensor.vento_direzione_nord') == 'off' %} NORTH {% elif states('binary_sensor.vento_direzione_est') == 'off' %} EAST {% elif states('binary_sensor.vento_direzione_sud') == 'off' %} SOUTH {% elif states('binary_sensor.vento_direzione_ovest') == 'off' %} WEST {% endif %}
- Then, check the configuration and if it's valid reboot Home Assistant.
Step 9: Rain Gauge Configuration
The rain gauge sends via ESPhome the total of rain, which increases at every step. If the ESP32 is rebooted, this value goes to zero. So, to have a value that can only increase and that reset when a certain amount of time has passed, we can use a utility meter , which is provided by Home Assistant. With that we can show in the dashboard the total rain, the rain of that day and so on.
- Go to devices and then helpers
- Create a new hepler and select utility meter
- Select the rain gauge entity and insert the name of the conuter
- Select every how much time reset the counter (e.g. 24h or 1 month)
Create other counters for every time interval you want to show the amount of rain for.
Step 10: Dashboard
Once the weather station is finally online, we can create the custom dashboard to show the sensors readings and graphs. For graphs I suggest to use the mini graph card integration, which can be installed via the Home Assistant Community Store. At the top you can find a screenshot of my dashboard, if you want to get ideas for your dashboard. Below i uploaded the code file of my dashboard, if you want to edit it via the text editor.
To record the data you can configure a database in Home Assistant (recorder integration). I haven't posted details on how to configure it because I'm still learing a lot about Home Assistant and I haven't finished configuring it.
To see the data from your smartphone you can download the Home Assistant app. To connect from outside the local network I'm using the Nabu Casa Cloud, which is the simplest solution but it's not free. There are other solutions but they are not totally safe.
Attachments
Step 11: Done!
This project is done, and I hope you found it interesting. Of course, you can also build some of the sensors and not all of them. If you have any questions, write them here in the comments. If you want to see more details, please check the video that you can find at the top or here . It is in Italian, but don't worry, it has also english subtitles. Thanks a lot for reading my guide, bye!
Be the First to Share
Recommendations

We have a
be nice
policy.
Please be positive and constructive.
43 Comments
Question 2 days ago on Step 5
7 days ago
20 days ago
I still have to find a temp/hum sensor strong enough to survive outside my house (rarely below 0, max 40, but a lot of humidity and saltiness)
Reply 7 days ago
I did a bit of work on these, but granted not put in a beach house!
ESDK: https://www.rs-online.com/designspark/air-quality-...
Hope this is useful. =)
Reply 13 days ago
Reply 19 days ago
Reply 18 days ago
The problem is not the high humidity, but the salt.
Reply 15 days ago
7 days ago
2. Calculate kd=sqrt(cd1/cd2)=1.9331
3. Calculate K = (kd+1)/(kd-1)= 3.1434
4. Measure "r" rotational radius of cup-center, express in meter
5. Measure "f" rotations per seconds
6. Calculate "V" wind speed (in m/s) as V=K * 2π * f * r = 19.75 * f * r
or in km/h: V = 71.1 * f * r
10 days ago on Introduction
Adding a lot of sensors to the build would make things a lot more complicated and kind of go against the main goal, which is to provide an introductory material covering the whole stack from hardware to software.
20 days ago on Step 10
Reply 16 days ago
Reply 18 days ago
Reply 20 days ago
16 days ago
Bellissimo lavoro davvero.
Unico appunto è perché tu non abbia usato un BME280 al posto dell'accoppiata BMP180-DHT22. Avresti avuto tutto su bus I2C a vantaggio della semplicità di costruzione e di scrittura del software.
Comunque, ottimo lavoro e cieli sereni.
16 days ago
I have seen this done with two carbon conductive rods side by side with a small gap between them for the water to short the rods together. The one I have seen the two rods was potted in compound in a plastic tube (pipe), then the tube was sanded down half way (diameter) of the tube exposing the tops of the carbon rods now sanded flat imbedded in the compound. Again as you can guess when a drop of water shorted the carbon this would indicate the possibility of rain starting.
Question 18 days ago
Tip 19 days ago
Reply 18 days ago
19 days ago
Reply 18 days ago
Question 20 days ago on Introduction
Answer 18 days ago
20 days ago
Reply 18 days ago
Tip 20 days ago
Reply 18 days ago
20 days ago
1. Measure the distance from cup
center to the center of the shaft.
It is about 16 cm.
2. Count the number of rotations in
one minute as the anemometer
spins. Use a stopwatch to time
the interval and count the number
of times the contrast cup passes.
3. When a cup makes one full revolution,
it covers a distance equal
to the perimeter of a circle of
radius 8 cm. It covers a distance
equal to 2πr, which would mean:
2 x 3.1416 x 8 cm, or 50.3 cm.
• Your anemometer cup therefore
moves through 50.3 cm each time
it revolves.
4. Calculate the speed of your
anemometer. Example: you
counted 60 revolutions in one
minute. Your anemometer speed
would be 60 RPM (revolutions
per minute). It means a linear
distance of 60 x 50.3 cm covered
per minute.
5. Convert this into km/hr using the
following calculation:
60 x 50.3cm x 60min x 1 km
1 min 1 hr 100000cm
= 60 x 0.003 km/hr
= 1.8 km/hr
• If you had counted 30 revolutions
per minute instead of 60, your
anemometer speed would have
been 30 x 0.003 km/hr; or if the
number of revolutions were 15,
the anemometer speed would be
15 x 0.003 km/hr. You can use a
“shortcut” method in calculating
the anemometer speed. Multiply
the rpm by 0.03 to obtain your
anemometer speed in km/hr.
5. Once you know your anemometer
speed, you can figure out
the wind velocity that moved it.
• Remembering that the anemometer
moves only 1/6 as fast as
the wind, multiply your speed by
6 to get wind speed:
(6 x 1.8) or 10.8 km/hr
• For anemometer speed of 60
rpm, wind velocity is 10.8 km/hr.
Reply 18 days ago
20 days ago
Reply 18 days ago
20 days ago
Reply 18 days ago
20 days ago
all calculation for anemometer speed are true BUT a coeff is missing.
The only good method is expériement to find k and true air speed:
Test your disposal in a constant speed running car; (no wind as much as possible this day)
Check the car speed VS your anemometer indication and calculate the proper correction K (or curve, in case of non linearity)
Put the coef in your computations.... et voila.
For information, another way is possible: Mesure the dynamique pressure of the wind and the statique pressure of the ambient and .... compute.
Reply 20 days ago
Wonderful instructable. I have always wanted to make a weather station and this may give me the inspiration! Thanks for sharing!
Reply 20 days ago
20 days ago
Reply 20 days ago
Reply 20 days ago
20 days ago
Reply 20 days ago
21 days ago
Reply 21 days ago