My first weather station

Sorry but I don’t know how to insert the code.

Great. Thanks alot

Since the BME280 is in a closed housing, are there no problems with heat development etc.? I can’t see any pressure equalization in the housing and heat builds up, right?

the box has a hole at the bottom, but I may have to get it out of the box.

Hi @Kastler,
Could you please be so kind to edit your post and put three backticks at the beginning and end of your code?
Triple backticks look like this:

Hi Pete, great project. Were did you get the mounting brackets and slotted tube? I’ve got a number of BME based sensors around the house/yard, but need to get organised and make a consolidated project.
thnx
billd

Hi @Bill_Donnelly I bought mine from this U.K. seller on eBay…

But this seller might prove more economical for you as they are based in China. They also list the various brackets and also a version of the sensor cover that has a solar panel on top…

The cover is actually designed to house the main processing unit for the weather station, so doesn’t mount directly on to the brackets. I just made a circular plastic plate to go in the bottom of the housing, with a square hole to allow it to fit onto the bracket.
I also found that horizontal rain will make it through the slots in the tube and on to the sensor, so some additional protection is needed within the tube, and it’s a good idea to cover the BME280 board with varnish (all except the tiny sensor with the hole in it).

Pete.

Thnx, I found a Chinese/AU sellers with same items sold separately (the UK postage to AU is a killer). Just needed to find the right words. Could probably buy a complete wxr station for 1/2 the price . . . but where’s the fun in that!?
cul
billd

1 Like

Hello @Kastler, great project, can you share the qr code.
Cumps

I think @Robertofz asks you the sketch :wink:

No I ask for qr code

How do you use the Blynk project without the sketch? :thinking:

I only want the structure of blynk.

And I need the sketch :rofl:

I hope that Kastler doesn’t mind. He had attached it here briefly, but now removed it.

#include <Blynk.h>
#include <WiFi.h>
#include <ESPmDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
#define BLYNK_PRINT Serial
#define uS_TO_S_FACTOR 1000000
#define TIME_TO_SLEEP 600 //set deep sleep time (in seconds)
#include <BlynkSimpleEsp32.h>
#include <BME280I2C.h>
#include <Wire.h>
#include <SimpleTimer.h>
BME280I2C bme;
char auth[] = “”; // Blynk projekt token
char ssid[] = “”; // wifi SSID
char pass[] = “”; // wifi password
char server[] = “blynk-cloud.com”; // blynk server
unsigned int port = 8442; // blynk server port
const float pi = 3.14159265; // Pi
int period = 5000; // mérési időköz (ezred másodperc)
int delaytime = 2000; // Time between samples (miliseconds)
int radius = 90; // szélkerék sugara mm-ben
int Wdir = 0;
unsigned int Sample = 0; // Sample number
unsigned int counter = 0; // magnet counter for sensor
unsigned int RPM = 0; // Revolutions per minute
float speedwind = 0; // Wind speed (m/s)
float windspeed = 0; // Wind speed (km/h)
int measurement = 0;
int pinValue = 1;
const int Fesz = 34; // voltage detection pin number
const int rainGauge = 14; // Rain pin number
const int szelseb = 35; // wind speed pin number
const int UVSen = 36; // UV Index detection pin number
const int szelPin = 39; // Wind direction pin number
float rainAmount = .3; // Csapadék növelés értéke
float totalAmount;
float voltage = (((float)analogRead(Fesz)*(3.3/4095))2)+0.24; // battery voltage
float uvindex = ((float)analogRead(UVSen)(3.3/4095))*10; // UV Index GUVA-S12SD
float szelir = ((float)analogRead(szelPin)); // Wind direction
#ifdef __cplusplus
extern “C” {
#endif
uint8_t temprature_sens_read();
#ifdef __cplusplus
}
#endif
uint8_t temprature_sens_read();
BlynkTimer timer;
void setup()
{
// Debug console
pinMode(rainGauge, INPUT);
pinMode(szelseb, INPUT);
pinMode(szelPin, INPUT);
pinMode(UVSen, INPUT);
pinMode(Fesz, INPUT);
float szelir = ((float)analogRead(szelPin)); // Szélirány analóg adat olvasása
Serial.begin(115200);
WiFi.mode(WIFI_STA);
Blynk.connectWiFi(ssid, pass); //conect to wifi
Blynk.config(auth, server, port);
Blynk.connect(); //connect to blynk server
ArduinoOTA.setHostname(“Idojaras”);
ArduinoOTA.begin();
Blynk.setProperty(V1, “rotation”, Wdir);
while(!Serial) {}
Wire.begin();
while(!bme.begin()) //start BME 280
{
Serial.println(“Could not find BME280 sensor!”);
delay(1000);
}
switch(bme.chipModel())
{
case BME280::ChipModel_BME280:
Serial.println(“Found BME280 sensor! Success.”);
break;
case BME280::ChipModel_BMP280:
Serial.println(“Found BMP280 sensor! No Humidity available.”);
break;
default:
Serial.println(“Found UNKNOWN sensor! Error!”);
}
timer.setInterval(300000L, sendSensor); //set timer to execute void sendSensor()
Sample++;
timer.setInterval(500L, WindDir);
timer.setInterval(500L, RainCalc);
timer.setInterval(500L, windvelocity);
timer.setInterval(500L, RPMcalc);
timer.setInterval(500L, WindSpeed);
timer.setInterval(500L, SpeedWind);
}
void loop()
{
Blynk.run(); //start the Blynk sketch
timer.run(); //start the timer
ArduinoOTA.handle();
}
void sendSensor()
{
float temp(NAN), hum(NAN), pres(NAN);
measurement = hallRead();
BME280::TempUnit tempUnit(BME280::TempUnit_Celsius); // read BME 280
BME280::PresUnit presUnit(BME280::PresUnit_hPa); // read BME 280
bme.read(pres, temp, hum, tempUnit, presUnit); // read BME 280
float voltage = (((float)analogRead(Fesz)*(3.3/4095))2)+0.24; // battery voltage
float uvindex = ((float)analogRead(UVSen)(3.3/4095))*10; // UV Index
float szelir = ((float)analogRead(szelPin)); // Szélirány
double gamma = log(hum / 100) + ((17.62 * temp) / (243.5 + temp)); // calculate dewpoint
double dp = 243 * gamma / (17.62 - gamma); // calculate dewpoint
long rssi = WiFi.RSSI(); // read signal strength
Blynk.setProperty(V1, “rotation”, Wdir); //Szélirány
Blynk.virtualWrite(V1, 1);
Blynk.virtualWrite(V2, temp); //temperature
Blynk.virtualWrite(V3, windspeed); //Wind speed
Blynk.virtualWrite(V4, hum); //humidity
Blynk.virtualWrite(V5, totalAmount); //Rain amount
Blynk.virtualWrite(V6, pres); //pressure
Blynk.virtualWrite(V7, measurement); //hallsensor
Blynk.virtualWrite(V8, szelir); //Wind direction binary (test function)
Blynk.virtualWrite(V9, (temprature_sens_read() - 32) / 1.8); //CPU Temp
Blynk.virtualWrite(V10, (temprature_sens_read() - 32) / 1.8); //CPU Temp
Blynk.virtualWrite(V11, voltage); //Battery Voltage
Blynk.virtualWrite(V12, uvindex); //UV index
Blynk.virtualWrite(V13, dp); //Dew point
Blynk.virtualWrite(V14, dp); //Dew point
Blynk.virtualWrite(V15, rssi); //rssi
Blynk.virtualWrite(V16, rssi); //rssi
// Serial.println(“Mentem aludni…”);
// delay(500);
// esp_sleep_enable_timer_wakeup((uint64_t)TIME_TO_SLEEP * uS_TO_S_FACTOR); //set deepsleep time
// esp_deep_sleep_start(); //deepsleep start
// delay(100);
}
void WindDir()
{
float szelir = ((float)analogRead(szelPin)); // Szélirány analóg adat olvasása
if (szelir < 190) Wdir =270; // nyugati
else if (szelir < 420) Wdir = 315; // északnyugati
else if (szelir < 700) Wdir = 292.5; // nyugat-északnyugati
else if (szelir < 900) Wdir = 0; // északi
else if (szelir < 1300) Wdir = 337.5; // észak-északnyugati
else if (szelir < 1500) Wdir = 225; // délnyugati
else if (szelir < 1600) Wdir = 247.5; // nyugat-délnyugati
else if (szelir < 2250) Wdir = 45; // északkeleti
else if (szelir < 2400) Wdir = 22.5; // észak-északkeleti
else if (szelir < 2900) Wdir = 180; // déli
else if (szelir < 3100) Wdir = 202.5; // dél-délnyugati
else if (szelir < 3400) Wdir = 135; // délkeleti
else if (szelir < 3600) Wdir = 157.5; // dél-délkeleti
else if (szelir < 3840) Wdir = 90; // keleti
else if (szelir < 3950) Wdir = 67,5; // kelet-északkeleti
else if (szelir < 4095) Wdir = 112.5; // kelet-délkeleti
else Wdir = 0;
Blynk.setProperty(V1, “rotation”, Wdir); // V1 image rotating to wind direction
Blynk.virtualWrite(V1, 1); // V1 image number
Blynk.virtualWrite(V8, szelir); // wind direction binary (test function)
}
void RainCalc()
{
attachInterrupt(digitalPinToInterrupt(rainGauge),addrain, RISING);
Blynk.virtualWrite(V5, totalAmount); // Rain amount
}
void addrain(){
totalAmount += rainAmount;
}
void windvelocity(){
speedwind = 0;
windspeed = 0;
counter = 0;
attachInterrupt(digitalPinToInterrupt(szelseb),addcount, RISING);
unsigned long millis();
long startTime = millis();
while(millis() < startTime + period) {
}
}
void RPMcalc(){
RPM=((counter)*60)/(period/1000); // Calculate revolutions per minute (RPM)
}
void WindSpeed(){
windspeed = ((4 * pi * radius * RPM)/60) / 1000; // Calculate wind speed on m/s
}
void SpeedWind(){
speedwind = (((4 * pi * radius * RPM)/60) / 1000)*3.6; // Calculate wind speed on km/h
Blynk.virtualWrite(V3, speedwind); // Wind speed sending
}
void addcount(){
counter++;
}


2 Likes

I scrambled the code from this forum too. This project is not finalized yet.

1 Like

Thank you !

Does this code actually produce sensible results?

In my opinion, the attachInterrupt commands should be in your void setup, and you should be using volatile variable types within your interrupt service routines.
You may also want to use nointerrupts() and interrupts() in your timed wind speed and rainfall calculations to ensure that the processing of these functions isn’t interrupted by an interrupt (if you know what I mean).
As a result, I’d aim to keep these timed calculation routines as slick as possible, so I’d do all the Pi x diameter calculation stuff once and hard code the value rather than recalculating it on the fly every time.

I found that I needed to debounce the contacts on the reed switch of the rainfall tipping bucket gauge, as I was getting multiple interrupts per tip of the bucket. The denouncing was done using standard debounce code.

I struggled a bit with what I wanted to see on my rainfall figures, so eventually settled for calculating rainfall in mm during the last minute, hour and rolling 24 hour periods. This required two arrays, one with 60 elements and another with 24.
This works well, but obviously when your MCU starts-up it takes 24 hours before the rolling rainfall data is fully populated.

Pete.

1 Like

could point to reading rain sensor (instead of Attachinterrupt) sorry my english

like that? https://www.arduino.cc/en/tutorial/debounce

Hi, you’d still attach an interrupt to the rain gauge (and the wind speed meter), but I find that I get multiple consecutive interrupts from the rain gauge when it tips. The debounce code you linked to looks fine, except that the variables should really be volatile as they are used within the ISR.
In theory, timers within ISRs are inaccurate, but in practice I find that they are fine for the short periods that are needed for debouncing.

I’m travelling in Thailand at the moment and don’t have access to my weather station code (which is written to use MQTT rather than Blynk code anyway), so I can’t share code snippets at the moment I’m afraid.

Pete.

1 Like