Change the color of traffic LED light depending on the weather, using OpenWeatherMap Weather API.
* included in Starter Kit.
How to make
Referring to the parts library of traffic LED, connect it to the obniz Board as below.
|obniz||Keyestudio Traffic Light Module (traffic LED)|
Go to the site of OpenWether API, then click sign up, and fill out the required information to create your account.
After creating an account, click on the API Keys tab, and the API Key is displayed as shown below.
Take note of this API Key. It is necessary when coding later.
WEATHER_API_KEY_HERE with the API Key mentioned above.
(In this code, the API Key is written in the same place, but if you put the code to a public place, you should write the API Key in another file to protect it.)
It gets the weather information every 30 seconds and update the color of traffic LED (It is free up to 60 call/min).
Check Weather API – OpenWeatherMap for more information about Weather API of OpenWeatherMap.
The color of traffic LED changes as follows:
- When an umbrella is needed, such as raining or snowing → red
- When it is cloudy and wether an umbrella is needed depends on the person → yellow
- When it is sunny and no umbrella is needed. → blue