In this writeup, I am utilising the previous magic 8 ball circuit. You can expand the use of the same circuit to be Internet Weather Station. The code use in this is taken from the Example code of “WeatherStationDemo” that comes with the ESP8266 Weather station library.
Step 1. Downloading the Weather Station Library
From the Ardunio IDE, click on Tools->Manage Library, you should be prompted with the following Library Manager window:
You can then search for “ESP8266 Weather” and install the ESP8266 Weather Station library.
Step 2: Preparation
Once the library have been downloaded, you can restart the Arduino IDE, and then select File->Examples-> ESP8266 Weather Station->WeatherStationDemo. Then follow the following preparation step to configure the code.
- I am in Melbourne, Australia so I made the adjustment to GMT + 10, you will need to make adjustment to the time where you live.
- SSD1306 LED Display: SDA is connected to GPIO 4 (pin D2) and SDC is connected to GPIO 2 (pin D4)
- We are using the OpenWeatherMap, to use this you will need to sign up to get and API key, you can use the following link. Then populate the key into the code below.
- Locate your location for the weather using the link https://openweathermap.org/find?q, using the location found, enter that into the following code below to replace the OPEN_WEATHER_MAP_LOCATION_ID
This is shown in the following code:
#define TZ 10 // (utc+) TZ in hours #define DST_MN 0 // use 60mn for daylight savings ... const int SDA_PIN = 4; //D2 (GPIO 4); const int SDC_PIN = 2; //D4 (GPIO 2); ... String OPEN_WEATHER_MAP_APP_ID = "yourOpenWeatherMapAPIKey"; String OPEN_WEATHER_MAP_LOCATION_ID = "7932632";
Step 2: Upload the code and Test
Once you have setup the code above you can now upload the code to the ESP8266 and if all goes well you should have a working Internet Weather station.
If all goes well you now should have an internet weather station as shown in the following video.
If you like this post, please share and drop me a line. Don’t forget to subscribe if you haven’t already to get more IoT related post.