Weather Indicator With IoT (TfCD Project)
by StephanPetekTCD in Circuits > Gadgets
10186 Views, 95 Favorites, 0 Comments
Weather Indicator With IoT (TfCD Project)
The Internet of Things (IoT) has many possibilities to connect devices to the internet and the readily available data and information in your home to make your life easier and more efficient.
This Weather Indicator will let you know what the current weather condition is and when the weather conditions changes. Based on the current weather condition, it will display a certain color in it's own cloud-connected cloud:
Clear weather: Yellow
Cloudy: Blue
Rain: Purple
Snow: White
It is a perfect gadget for rooms from which you cannot view the conditions outside and besides that, it is a great base to start other IoT projects.
What do you need?
- Vase
- 3D printed lid
- Cottonwool (non flammable)
- Particle Photon
- NeoPixel 12 ring
- Breadboard (optional)
- 2 momentary switches (optional)
- Wires
- Micro USB cable with adapter
- Wireless network to connect Particle Photon to the internet
- Account for Particle (particle.io)
- Account for IFTTT (ifttt.com)
Preparing the Electronics
To display the colors, an AdaFruit NeoPixel ring with 12 digital controllable WS2812B LEDs is used. The LED-ring is controlled by a Particle Photon, which combines a powerful STM32 ARM Cortex M3 microcontroller and a Cypress Wi-Fi chip and is easily programmable through the Particle development tools.
The Particle Photon is powered through USB (use the Micro USB cable with adapter for this).
The NeoPixel ring can now be connected to Photon. We recommend using a breadboard for easy prototyping, but you may also directly connect the wires to your Photon.
Connect PWR on the NeoPixel ring to the Photon's VIN pin.
Connect GND on the NeoPixel ring to the Photon's GND pin.
Connect IN on the NeoPixel ring to the Photon's D4 pin.
The following connections are optional:
For testing purposes, we have connected two momentary switches to the Photon through a breadboard, so it is possible to manually change the LED colours as well. The momentary switches are fed with 3.3V DC from the 3.3V Pin on the Photon. The two switches are then connected to pins D2 and D3 on the Photon.
See the schematic on how to connect the Photon, NeoPixel ring and momentary switches to the breadboard.
The switch connected to pin D2 will be used to cycle through the colours, the switch connected to pin D3 will be used to turn the LED ring off.
Note: You may connect the Neopixel Ring IN and momentary switches to different digital pins, but you will then need to change the pin numbers in the code in the next step accordingly.
Setup the Particle Photon
To work as an IoT device, the Particle Photon needs to be connected to your Wifi network and connected to your Particle account.
When connected to the Wifi network, the LED on the Photon will breathe cyan.
If it is not yet connected to the Wifi and/or linked to your Particle account, please follow this guide to connect it: https://docs.particle.io/guide/getting-started/st...
To program the Photon, log on to https://build.particle.io with your Particle account. Your Photon should be listed here.
Create a new app and import or copy the code attached. The only thing you may need to do is remove the line
#include "neopixel/neopixel.h"
Then go to the library and add the NeoPixel library to the app you have just created so it will correctly recognize this library (otherwise it may give you an error while compiling the code). It should automatically add the line
#include "neopixel/neopixel.h"
back to the code.
If you have connected your Photon, breadboard, NeoPixel ring and momentary switches in the same way as on the schematic in the previous step, you do not need to change anything to the code.
To better understand the code we will briefly walk through it.
Definitions:
A couple of colours are predefined. When you want to change a certain colour, just replace the current colour in the loop section of the code with one of the other colours defined here.
Besides colours, the NeoPixel settings and pin are defined and also used pins for momentary switches and other used variables are defined:
// Define colors (R, G, B)<br>#define PEACH 200,50,5 #define CYAN 10,150,70 #define PURPLE 180,3,180 #define BLUE 20,20,255 #define WHITE 255,255,255 #define GREEN 10,180,10 #define YELLOW 200,150,0 #define LIGHTBLUE 135,206,250 #define INDIGO 75,0,130 #define OFF 0,0,0
// IMPORTANT: Set pixel COUNT, PIN and TYPE #define PIXEL_PIN D4 #define PIXEL_COUNT 12 #define PIXEL_TYPE WS2812B
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);
int knop1 = D2; int knop2 = D3;
int var_knop1 = 0; int var_knop2 = 0;
int i = 0; int weather = 0;
Setup:
In the setup stage of the code, the pins for momentary switches are set to monitor an input. Also a Particle function "Led" is setup, which will be used by IFTTT to change the colours. Then the NeoPixel is initialized.
void setup()<br>{ // Declare inputs pinMode(knop1, INPUT_PULLDOWN); pinMode(knop2, INPUT_PULLDOWN);
// register the Particle function Particle.function("Led", LedAansturing); strip.begin(); strip.show(); // Initialize all pixels to 'off' }
Loop:
First, the two momentary switches are programmed. When the a switch is pressed it will return the value HIGH.
For the first swich, it will add one to the variable weather, and will set it to 1 when it reaches 5 (as we only have four weather conditions programmed).
The second switch will simply set the variable weather to 0.
Then the code will monitor the value for weather (as a change in this variable indicates a weather change), with a couple of if statements. It will set a different colour for the LED ring (1 corresponds to Rain, 2 to Snow, 3 to Cloudy, 4 to Clear and 0 corresponds to turning to the LED ring off).
void loop()<br>{ var_knop1 = digitalRead(knop1); var_knop2 = digitalRead(knop2); if(var_knop1 == HIGH) { // Knop AAN / CHANGE weather++; if(weather == 5) { weather = 1; } delay(500); }
if(var_knop2 == HIGH) { // Knop UIT weather = 0; delay(500); } // weather functies if(weather == 1) { // RAIN for(i=0; i < PIXEL_COUNT; i++) { strip.setPixelColor(i, INDIGO); } strip.show(); } if(weather == 2) { // SNOW for(i=0; i < PIXEL_COUNT; i++) { strip.setPixelColor(i, WHITE); } strip.show(); } if(weather == 3) { // CLOUDY for(i=0; i < PIXEL_COUNT; i++) { strip.setPixelColor(i, BLUE); } strip.show(); } if(weather == 4) { // CLEAR for(i=0; i < PIXEL_COUNT; i++) { strip.setPixelColor(i, YELLOW); } strip.show(); }
if(weather == 0) { // OFF for(i=0; i < PIXEL_COUNT; i++) { strip.setPixelColor(i, OFF); } strip.show(); } }
The IFTTT function:
This part of the code lets IFTTT change the colour of the LEDs. Based on the command given by IFTTT (RAIN, SNOW, CLOUDY or CLEAR), it will set the variable weather to a different value. The loop will recognize this value change and change the LED colour accordingly.
// this function automagically shows up in IFTTT<br>int LedAansturing(String command) { if(command == "RAIN") { weather = 1; } if(command == "SNOW") { weather = 2; } if(command == "CLOUDY") { weather = 3; } if(command == "CLEAR") { weather = 4; }
if(command == "OFF") { weather = 0; } }
Downloads
Setup IFTTT to Monitor Weather Changes
To make the LED colour change according to the current weather conditions, the created Led function needs to be called with command RAIN, SNOW, CLOUDY or CLEAR. To do so, we use the platform IFTTT (IF This Then That) which enables various cloud services to be linked together, including Particle.
Log on to IFTTT.com with your IFTTT account and click on My Applets. There click on New Applet to link a weather service to the Particle Photon in six steps. We will explain how to setup the function for Rain, you can walk through the same steps to setup the weather conditions Snow, Cloudy and Clear as well.
Step 1: Choose a service.
The screen will display 'if this then that'. Click on the highlighted 'this' to continue to select a service.
The service Weather Underground can monitor the current weather condition, so choose Weather Underground.
Step 2: Trigger
Choose the trigger 'Current condition changes to' and select Rain at 'Current Condition'.
Step 3: Action service
The screen will display 'if this then that' again. Choose the highlighted that to continue.
For the action service we will use Particle. When clicking on Particle it may ask you to log in, use your Particle account here to connect it to IFTTT.
Step 4: Choose Action
The action we want Particle to perform is to call a function (as we created one earlier in the code).
Step 5: Complete action fields
Setup the action according to the image above, use function 'Led' and replace the input text with 'RAIN'.
Step 6: Summary
A summary of the completed applet is now given and you may change the name of the applet for easier referencing.
When you have completed the steps to create applets for each weather condition, your applet screen should have four weather underground applets, one for each weather condition.
Making the Lid
A lid will cover the vase to give it a nicer appearance. The lid will also house the electronics and has a separate bottom which separates the electronics from the cottonwool, so you cannot see the electronics when looking through the vase. The bottom will later be glued onto the lid.
We've chosen to 3D print the lid, however you can make the lid any way you want, as long as the lid will not conduct electricity and is able to house the electronics.
We've supplied our 3D models as a base to start with. Depending on the design and measurements of your vase, you need to change the inner and outer diameter of the lid and lid bottom. You may also want to change the lid design if you prefer to give it another look.
When you are satisfied with the model, you can use a 3D printer to print it. If you do not have access to a 3D printer, you can use 3D Hubs (https://www.3dhubs.com/) to find someone who will print it for you for a small fee.
Note: The actual 3D printing will not be discussed here. The settings and steps needed to succesfully print the lid are largely dependant on the actual 3D printer make and model and on the used filament.
It All Comes Together!
Now everything is setup, it is time to assemble your Weather Indicator!
- First, fill the vase with cottonwool, as this will be the cloud. Make sure this is non flammable material, as the LEDs might get hot over time!
- Put the LED ring wires through the hole in the lid bottom and connect them back to the breadboard (or Photon if you connected them directly).
- Pull the USB cable through the hole in the lid.
- Testfit the LED ring in between the cottonwool and make sure the light is spread evenly through the cottonwool.
- Testfit the electronics between the lid and lid bottom.
- If everything fits nicely, spot glue the lid bottom in the lid (just use a little glue on 2 or 3 spots, as you need to remove the glue again if you need to access the electronics for some reason).
- Make sure the Led-ring is still in the right position and fit the lid on the vase.
- Connect the adapter from the USB cable to your wall outlet: the Photon should connect to your Wifi network and start displaying colors for the current weather after the first weather change.
Your Weather Indicator is ready for use!