Introduction: ESP32 Weather Station Solar Powered

In this tutorial we are going to build a WiFi enabled weather station project.

The target is to design Weather station with almost all possible feathures:

  • Show current conditions, time, temperature, humidity, pressure
  • Show forecast for the next days
  • Update on the air
  • Built in web site for configuration and data represantation
  • Upload data to the cloud for history statistics
  • Integrated with Aple Home Kit or MQTT
  • Indepeded Accu powered with possible recharge or connect to solar panel

I can't add more and not more imagination what else must or can be

Step 1: Parts Which Are Required

  • ESP32 (I have used dev module)
  • 2.8" 240x320 TFT LCD SPI ILI9341
  • Plastic case
  • 3 x 18650 Accu
  • Weather sensor BME280 to measure Temperature, Humidity and Pressure
  • USB lithium charger module
  • DC-DC step UP18650
  • battery holder (3pc)
  • HC-SR505 Motion detector
  • 220 Om resistor
  • 2x 10 kOm resistors
  • TIP120 NPN transistor (Darlington) can be used any other compatible
  • ButtonWires, switch, solder board....

Step 2: Wiring and Assembling

First step is assembling of station powers.

I have divided plastic case on two pars, one of them used for battery, switch, USB charger, and DC-DC step out Into this part i put battery holder and make windows for the switch and usb charger. Be aware usb charger module quite heting therefore i have used alluminium plate and put USB charger onto this using Star 922 glue.

Second step is assembling controllers part.

See wiring diagram how it should be connected

I have used Bread board for this purpose with the following steps

  • Solder ESP32 dev board
  • Solder shield to keep TFT display
  • Solder other electronic components: BME280, resistors, buttons
  • Solder wiring between components according diagram

Third step is prepare mounting of bread board to the second part of the plastic case. I have printed on my 3d printer two bars, mount them to bredboard by screws and make rectangular cutting for the display screen.

I glued plastic bars supports to the body of plastic case. Now when glue is dry, the bread board cab be unmount by screws.

Next step is :

  • Solder wiring for Power source
  • Solder wiring for the battery voltage status
  • Solder and mount motion detector

Final step:

  • setup DC-DC convertor by tunning output voltage 5v
  • connect two parts of station controller to power : power wires and voltage reading

For the motion detector and button i have done an additional holes on the face side .

Step 3: Uploading Firmware to ESP32

For this project I have used universal software, developed by myself

Please have a look github page ESPHomeController .This contains full instruction how to compile and setup.

! If you are not familiar with compilation and Arduino have a look step Uploading ready firmware

As soon as you upload firmware first time the ESP32 will start in configuartion mode (Access Point mode)

You should configure them. For this purpose open in any device list of available WiFi. Find HomeController and connect to it. Captive portal should start automatically. If not enter in your browser url: 192.168.4.1 and you will see configuration screen

Follow instruction and configure WiFi credentials to your WiFi network.

The ESP will restart after that as WiFi client and will connect to your Wifi.

As sson firts connection happens it will automatically mount Spiffs file system and downloads required files for the web portal:

  • index.html
  • filebrowse.html
  • js/bundle.min.js.gz

Download happens from the https://github.com/Yurik72/ESPHomeController/tree/... folder

Now you can see file content via web browser. for this you should now ip address of your ESP32

You can find it by one of the following ways:

  • Using serial port monitor to see a ESP32 logs
  • Using any tcp scanner to scan your network devices
  • Press a button on weather station and you will see system information

Put into browse http://192.168.0.XX/browse and you will see a file list of the your ESP

(192.168.0.XX is IP address of your device

For the final tuning you need to prepare configuration files.

Step 4: Uploading Ready Firmware

This section is specially for auditory who is not going to produce firmware by yourself. You just need to upload "ready" firmware

1. Donwload flash upload tools from this page

2. Download attached (extract from archives) files HomeController.bin and bootloader_qio_80m.bin to your hard drive

3.Start ESP32 download tool and enter values according screenshot

4. Press start

Step 5: Configuration

Before starting preparation of configuration you need:

  1. Create your channel on the thingspeak and key for you channel. Prepare 4 field and properly name them Temperature, Humidity, Pressure, Voltage
  2. Register on the Weather.com to obtain your api key

Thingspeak are needed to upload your data and monitor trends and values

Weather are neccessary to get forecast data.

Ok, finally you need create services.json file with the following content

[{"service":"TimeController","name":"Time","enabled":true,"interval":1000,"timeoffs":7200,"dayloffs":3600,"server":"pool.ntp.org","enablesleep":true,"sleeptype":1,"sleepinterval":900000,"restartinterval":18000000},<br>{"service":"BME280Controller","name":"BME","enabled":true,"interval":900000, "i2caddr":118,"uselegacy":true,"temp_corr":-3.0,"hum_corr":10.0},
{"service":"WeatherClientController","name":"WeatherForecast","enabled":true,"interval":500000,"uri":"https://api.weather.com/v3/wx/forecast/daily/5day?geocode=50.30,30.70&format=json&units=m&language=en-US&apiKey=weatherapi"},
{"service":"WeatherDisplayController","name":"WeatherDisplay","enabled":true,"interval":500},
{"enabled":"true","interval":600000,"pin":36,"service":"LDRController","name":"LDR","cvalmin":0.0,"cvalmax":7.2,"cfmt":"%.2f V","acctype":10},
{"service":"ThingSpeakController","name":"ThingSpeak","enabled":true,"interval":1200000,"value":[1,1,1,1,0,0,0,0],"apiKey":"thingspeakapi"},
{"enabled":true,"interval":1,"pin":"","service":"ButtonController","name":"Button","pins":[27]}</p></p><p>]</p>

!Please replace

  • thingspeakapi with your thingspeak api key
  • weatherapi with your weather api key
  • geocode with your location for which you want to obtain forecast

Than prepare second file triggers.json

[{"type":"BMEToWeatherDisplay","source":"BME","destination":"WeatherDisplay"},<br>{"type":"TimeToWeatherDisplay","source":"Time","destination":"WeatherDisplay"},
{"type":"WeatherForecastToWeatherDisplay","source":"WeatherForecast","destination":"WeatherDisplay"},
{"type":"BMEToThingSpeak","source":"BME","destination":"ThingSpeak","t_ch":1,"h_ch":2,"p_ch":3},
{"type":"ButtonToWeatherDisplay","source":"Button","destination":"WeatherDisplay"},
{"type":"LDRToThingSpeak","source":"LDR","destination":"ThingSpeak","ch":4}
]

Both files has to be uploded to the root of esp.

You can do this via browser http://192.168.0.XX/browse , where http://192.168.0.XX is IP adress of your device

After uploading the ESP must be restarted and everything was done right. Esp will show the proper screen as on the photo and video above

Step 6: Tunning and Power Consumption

I'm using my device with the connection to Solar Panel and to be sure that it can work "infinitely"

power consumptions is important and after several experiment i have used two major tricks

  1. Reduce consumption of the bacground LED of TFT screen.

According measurement it's eating 15-20 mA (a lot) therefore i have used tactics with Motion detector. It works perfectly Motion detectors able to recognize any detection up to 8-10 meters and raise voltage on the signal cable. This is openings a transistor and backround Led receive a power. Usually detector keep this state up to 10 sec which is more than enought to see monitor, but if you continue movements the signal is still high and LED is lighting.

Such approach give me a big economy, without additional effects, I do not meet with any problem to see my screen when i want

2. Reduce power consumption by ESP32

When ESP is connected to WiFi , it's constantly eatinmg 7-10 mA, I'm talking about constant time, not startup and first connection. This is can be acceptable if you have always see actual date and time, access your system from the Apple home kit

For my solar power in winter time as well it was to match to works without addiiotnal power sources,

Therefore i decided periodically put ESP32 on the sleep mode (eating is less than 1 mA) . This is Ok to me, for instance ESP is sleeping 20 minutes, than wake up, refresh screen (actual data and forecast) sends data to the thingspeak and back to sleep mode again

Minuses are:

  • Weather screen displays outdated time values
  • Station is not acessible from the browser and Apple Home Kit during the sleep time

It's up to you to decide what is more important, you can simple reconfigure that.

Please have a look services.json file and line

[{"service":"TimeController","name":"Time","enabled":true,"interval":1000,"timeoffs":7200,"dayloffs":3600,"server":"pool.ntp.org","enablesleep":true,"sleeptype":1,"sleepinterval":900000,"restartinterval":18000000}</p>

"enablesleep":true enables sleep at all, if put there false or remove paramater (false is default) ESP will never sleep

"sleepinterval":900000 this is millis, or 15 min, means every 15 min ESP will wake up and doing neccessary staff

So, now everybody can easylly play according neccessity

Step 7: Sensors Tuning

To minimize impact of internal heating to BME280 temperature sensor

Firts I did some tube around sensor and holes. Hovewer in my mode when LED normally is turned off and ESP is sleeping is not so importnat. In other cases BME280 sensor should move somewhere to exclude influence of internal heating. Any how small influence i found therefore there are two parameters to compensate

<p>{"service":"BME280Controller","name":"BME","enabled":true,"interval":900000, "i2caddr":118,"uselegacy":true,"temp_corr":-3.0,"hum_corr":10.0},</p>

temp_corr":-3.0

"hum_corr":10.0

which are means those values will be added after measurment

Second is calibrate battery voltage measurement,

<p>{"enabled":"true","interval":600000,"pin":36,"service":"LDRController","name":"LDR","cvalmin":0.0,"cvalmax":7.2,"cfmt":"%.2f V","acctype":10},</p>

"cvalmin":0.0

"cvalmax":7.2

are for this purposes, becasue voltage is measured after resistors dividers and compared with 3.3 V ,playing with cvalmax value you can reach exact voltage tuning with your multimetr value

Step 8: Adding Device to Apple Home Kit

Finally when your device is working properly it can be added to Apple Home Kit and you will be able to see

sensors values on the Apple home screen.

First you need restart device, as ssoon as device started it will not go to sleep 20 minutes is more than enought

Than open Home Kit App on your iOS device , and select or create new Home
1. Press Add (+)

2. Select Add accessory.

3. Press I don't have a Code or Cannot scan (further on scanning will be added)

4. if everything going fine you should see your new esp device in a list (see picture)

5. Select device and confirm adding without official certification

6. Type password 11111111

7. That All ! You should see that device paired succesfully, otherwise start pairing process again..

Based on thid setting you will see two devices on the Apple

1. Temp sensor & Hum sensor , going deep it will display values on full screen

2. Light sensor :) Actually Apple is able to show ligth Ambience, but not Voltage, therefore battery voltage is showing in Lux

Step 9: OTA: Over the Air Updates

Before start any updating is better to reboot ESP32, as mentioned before it will not go to sleep first 20 minutes

There are two possibilities to update

  1. Configuration using http://192.168.0.XX/browse you can access your file system on ESP and change configurations files
  2. You can completelly update firmware. for this purposes first you need create new one . It can be done via Arduino or Visual Studio IDE. Then type in browser http://192.168.0.XX/update, select your firmware and press update. Wait until is process finished and you will get response OK, otherwise repeat step again