Pi-Thermometer - IoT with Wyliodrin

By Russell Barnes. Posted

Connect your Pi to existing web platforms and easily build your own internet-based thermometer out of LEDs

How often do you check your browser or smartphone to see how cold it is outside? Nowadays, we read the temperature using applications that take data from the internet and display them in a nice interface. This reduces the interactivity and simplicity that old mercury thermometers had, while offering the great flexibility of reading the temperature anywhere on the globe. But what if you could have the best of both worlds? You can put your Raspberry Pi to use and replace the computer with a thermometer-like device, which has the capability of displaying the temperature at whichever location you wish.

You'll need

Wyliodrin STUDIO
3× Green LEDs
5× Yellow LEDs
2× Red LEDs
10× 220-ohm resistors
Breadboard and jumper wires

STEP-01 Set up the Raspberry Pi

Wyliodrin STUDIO is an IDE (integrated development environment) that makes it very easy to create complex applications for your Pi. First of all, you need to download it and follow the first two steps of the Getting Started tutorial for the Raspberry Pi. Once you have an SD card with the extra service installed, you need to connect the Pi to the internet, in the same network as your computer. As soon as the board has booted, you will see it available under Port. Press Connect and you’re ready to go.

STEP-02 Create a new visual application

In order to create the thermometer, press the ‘projects’ button and create a new application. Name it ‘pi‑thermometer’ and select ‘visual’ for the programming language. Open the newly created app and you’ll see the frame in which you need to connect the visual elements. The blocks gallery is on the left. We have chosen this way of programming because it allows you to rapidly create the code, and it doesn’t require you to know any specific programming language. In addition, if you’re familiar with Python, you can press the ‘Show code’ button and see how the code gets generated as you drag and drop the visual elements.

STEP-03 Build the thermometer

From the hardware point of view, you simply need to connect ten LEDs to the GPIO pins of the Pi. You can visualise the number assigned to each pin by selecting the ‘Pin layout’ tab in Wyliodrin STUDIO. We have chosen to connect the LEDs on pins 0 to 9. We will scale the read temperature and light up a variable number of LEDs accordingly.

 Wire up your system just like this

STEP-04 Weather API

The website openweathermap.org offers a complex API that allows you to get weather details from cities around the world. To access the API, you need to sign up for a key at openweathermap.org/appid. You only need to provide your email and choose a password. Once you have created an account, you can use the API key available at home.openweathermap.org.

STEP-05 Writing the application

The application reads the weather from the city of your choice and maps the value to the number of LEDs. The string used within the ‘Init weather API’ block is the key you got in the previous step.

In order to do the mapping, we specified the average minimum and maximum temperature values according to the current time of the year. It’s recommended that you use a reduced range, to make the differences in temperature visible on the thermometer.

If you would like to see the Python code that will get executed once you run the project, you can select ‘Show code’.

You can also download the code

STEP-06 Check the thermometer

All that’s left to do is to run the application. As long as you don’t stop it, the device will read the temperature from the internet every 30 minutes and update accordingly. You could add more LEDs to make it suitable for a larger range of temperature values. We suggest you also put the device in a box so that it looks just like a thermometer. Now you’ll know how warm it is outside with just a turn of your head.

From The MagPi store


Subscribe to the newsletter

Get every issue delivered directly to your inbox and keep up to date with the latest news, offers, events, and more.