Skip to content
All prices in US$ - All orders receive free delivery, worldwide - Click here to learn more
All prices in US$ - All orders receive free delivery, worldwide - Touch here to learn more
Displaying the Current Weather with LEGO and a Raspberry Pi

Displaying the Current Weather with LEGO and a Raspberry Pi

from hackster.io

In a previous project, Katie Dumont had created a simple camera that integrated a High Quality Raspberry Pi Camera module into a LEGO enclosure, which could capture photos in a fun manner.

Drawing from this as inspiration, Dumont wanted to build a weather station that would physically manipulate certain components to show what the conditions were outside.



The core of the weather station is a Raspberry Pi Build HAT, which allows the Raspberry Pi that it's attached to communicate over UART with any attached LEGO peripherals. Dumont was able to pick up a LEGO SPIKE Prime kit that contains an array of various sensors, motors, and miscellaneous bricks that can be assembled into a near-infinite number of ways. The station, however, would only require three motors that all have integrated encoders for absolute positioning.



Dumont started the build process by combining a pair of large yellow plates together along with a smaller stand in the back for an upright orientation. The first motor was placed near the bottom of the station, and it is responsible for rotating a dial that indicates the current wind speed from 0 up to 70 miles per hour. Next, the second motor was attached above the previous one, and it controls a basic spinning which rotates a wheel of eight weather types, including sunny, cloudy, and rain, into a single wedge cutout.

Finally, the last motor was placed on the left along with a cog that transforms the rotational motion into linear. This allows for the motor to move a strip of half blue/half red paper up or down to indicate the current temperature between -5C and 25C. The paper cover was designed in inkscape and then printed.



In order to get the current weather conditions, Dumont retrieved an API key from the UK's Met Office that allows her to send API requests for a given location code and receive weather data in return. Once the JSON response has been parsed and decoded, the weather type, temperature, and wind speed can all be stored as variables for later use.

One problem Dumont encountered was that the Met Office has a total of 31 different weather types, whereas her wheel can only show eight. So to get around this limitation, her program uses a lookup table that, which translates the Met Office's types into a compatible one.



With the program now retrieving the current weather, the last step was to get the motors to display it physically. Her program sets up three motors with some help from the LEGO buildhat Python package, resets their positions to zero, and then maps each weather data point to a rotational angle. For instance, the maximum wind speed of 70mph would have an angle equal to 180 degrees, whereas 35mph would be 90.

To see more about how this project was built, you can watch element14 present's video below!

Finally - to keep up to date with interesting news, offers and new products - interact with us on facebookinstagram, and twitter.

Previous article These special windshield wipers move to the beat of a car’s stereo
Next article Andrew Schmelyun's Raspberry Pi-Powered Printer Makes GitHub Issues Into Physical Tickets

Leave a comment

Comments must be approved before appearing

* Required fields