In this tutorial, we will be making a IoT Weather Predictor using a Dot One and a servo motor.
What you will need :
- Account at Wia - You will need to be logged in and / or registered into an account at Wia
- Wia Dot One - Buy Yours Here
- Micro Usb Cable - Buy Yours Here
- Jumper Wires
- Servo Motor Buy yours here
- Create an account at Wia if you haven't already - refer to this tutorial to get started with Wia here.
- Set up your Dot One - You will need to have set up a Dot One and you can find the tutorial on how to do that Here.
Once you have finished the tutorials above and learned all about the Dot One, you are all set to do this tutorial below.
Create a FlowIn order to retrieve the data we require to make the device work as behaved, we're going to create a flow which makes an api call to extract the data needed at a specified time (which can be arranged to your preferred time).
Set up the block arrangement as below:
In the Timer node, we can configure the timer to activate at a user preferred time.
After this, drag over a HTTP Service node from under the Services tab and this is going to create a GET request to a weather api (weatherbit.io - sign up for your own custom api key) and retrieve the probability value for precipitation.
Next, drag over the Run Function node, where we parse the response back from the api call and retrieve the value we want which is the precipitation probability value and set it to equal the output variable of this function.
Then, lastly we drag over the Update State node and configure the code to update the state of the device we are using.
Now that we have the precipitation value located in the state of the device needed for this project all we need to do is write code that retrieves the state value, transforms it to a float and then multiplies by 120 to retrieve a more easy to use % and adds 30 so the servo will turn to a more proportionate angle so as to be able to turn towards and away from the icons
The code to serve this purpose as indicated above is located below:
Create a Code Project
- Note: This portion requires a decent background in coding, specifically in C++ in order to understand how the Dot One and TFT Screen work to print the prices
- Below is the code for this project which you can follow by reading the comments attached to the side of the code.
- Feel free to try and rewrite this code yourself so you can better understand the device! Some advice if you are having trouble is to make a temporary Block Project and take note of what code is pasted into the preview window when you drag certain blocks over!
#include <WiFi.h>
#include <ESP32_Servo.h>
#include <Wia.h>
int pos = 30; // variable to store the servo position
Servo myservo; // create servo object to control a servo
Wia wiaClient = Wia();
void setup() {
WiFi.begin();
delay(2500);
myservo.attach(19); // attaches the servo on pin 5 to the servo object
}
void loop() {
String rawPrecipitation = wiaClient.getDeviceState("weather");
float precipitation = rawPrecipitation.toFloat();
precipitation = precipitation * 120;
precipitation = precipitation + 30;
myservo.write(precipitation);
delay(86400000); // Wait 24 hours until reading again.
}
You can then upload the above code to your Dot One by clicking the rocket icon and now once wired up the servo motor will swing to the icon representing the weather for the day.
Now that we have successfully wrote the software for this tutorial, it's time to wire up the hardware to make the servo motor rotate and behave as required.
Wiring ConnectionsUsing 3 jumper wires connect the Dot One to the pins as specified (in above code) as shown below:
Once the connections are made, you are ready to connect the Micro USB cable and the Dot One to your computer.
Now, that we have it all wired up and coded to do as indicated, this is what your final project should look similar to.
Congratulations and Well Done on completing the tutorial, hope you enjoyed it.
Here's another to keep you entertained - Get the beer of the day to display on your TFT screen
If you are more into building and making your own electronic devices and hooking them up to the cloud, why not try out some of these tutorials:
Coffee Counter with TFT Screen and Button
Slack Toggle Presence with Wia Button Module and Dot One
or build something from our hackster projects
Comments