Iot Weather Station Using Firebase and MIT App Inventor

5,987

41

11

Introduction: Iot Weather Station Using Firebase and MIT App Inventor

Hello all during this Global Outbreak of COVID-19, the world is swiftly moving towards technology Dependence. Controlling things remotely and Working from Home is the new normal. Learning IOT or say Internet of things is the absolute necessity of time and making a Weather station would be the best way to learn Internet of Things. so in this blog post, we will learn to make a Weather station that will monitor Temperature, Humidity and Rainfall too, we will integrate all of this on an Android APP.

Supplies

Step 1: Watch Video

Step 2: Electronics

In this project, we need to create a hardware interface between our Control Point and Internet, which basically means we need 2 Node Points (or say 2 devices), one at Sensor side and another at Control side. The Medium would be Internet.

MicroController:

For our build, we will need a Microcontroller that can read our Sensor Data, Send it to Internet and also react to any Inputs received from the Internet. Most Capable candidate for this Task Will be a NodeMCU which has ESP8266 Wi-Fi Enabled board along with USB Interface and Complementary Electronics and the best part is that we can Program it with Arduino IDE. Refer to this blog to go through the basics of node MCU.

Sensors:

For Temperature and Humidity, we will use a DH11 Sensor to sense Temperature and Humidity, we have also covered the basics of DHT sensor in this Post.

For Rain, we will use a generic Rain Sensor, which uses Conductive Property of water to change resistance and indicate if it’s raining or not, and also how intense is the rain. It comes as a Set with an operational amplifier to provide more accurate Calibrations which give us Digital or Analog Corresponding Outputs, it has a Potentiometer that can be used to Adjust the Sensitivity of sensor, which we will calibrate by pouring few drops of water on sensor and adjusting the pot until we see output LED glow.

Connections:

For now, connection are very simple,

DHT11

Vcc - 3.3v of Node MCU

GND - GND of Node MCU

Data - D5 of Node MCU

Rain Sensor

Vcc - 3.3v of Node MCU

GND - GND of Node MCU

Data - D2 of Node MCU

Thanks UTSOURCE.net to offer electronic components for my projects

Step 3: Software Overview

To Control or Monitor our Sensor in real time, we will need 2 nodes, one node is Microcontroller that connects to Internet via Wireless ACCESS POINT, but we need a second node or point to store data or Process it, for which we have quite a lot of option like Adafruit IO, Blynk, IFTTT, MQTT, Firebase, etc.

The Initial goal of the project was to push the data on Website server ofminov.in,with Firebase and a Firebase WordPress Integration plugin, but couldn’t get it working like expected, so switched to Firebase and MIT- App inventor to make an Android App that would display our data, and it turned out to be Awesome, We will learn that in the further steps.

Step 4: Firebase Database

First go to firebase.google.com, use your Google Accounts and get started,

start a new Project by naming and completing the follow-up steps till you see the Dashboard, now go to database option on left side, remember we have Real-time data to deal with, so create a Real-time Database, now it asks if we need authentication or not, since we will make an App and we want it to be publicly available, so choose test mode Database, which will keep Authentication off, it is less secure but works for this application.

the Database URL is very important, since we will push our Sensor data to this Node or server. copy the database URL for now.

Step 5: Node MCU Code

Open the code and Libraries attached in this step and Paste the URL copied in previous step in firebase_host definition line without the https and /(backslash). Make sure you remove it or else the data won’t be directed correctly.

#define FIREBASE_HOST "Paste URL here"  // Enter the Firebase Database URL Without Https and backslash<br>

Other than that we need internet connectivity, for which we have to enter our Wi-Fi SSID and Password in definitions.

#define WIFI_SSID "Enter your WiFI SSID"   // Change the name of your WIFI
#define WIFI_PASSWORD "WIFI PASSWORD"      // Change the password of your WIFI<br>

rest of the code is very simple and self-explanatory, where in we are basically pushing all the data from sensor on Real-time Database of firebase.

void loop() 
{
 float h = dht.readHumidity();
 float t = dht.readTemperature();         // Reading temperature as Celsius (the default)
 int r = digitalRead(4);                  // Reading the Rain Sensor Data
  
 Firebase.setFloat ("Temperature",t);
 Serial.println(t);
 Firebase.setFloat ("Humidity",h);
 Serial.println(h);
 if (r == 1)
  {
   Firebase.setString("Rain", "Yeah");
   Serial.println("its raining");
  }
   else 
  {
   Firebase.setString("Rain", "Nah");
   Serial.println("no rains today");
  }
 delay(200);
}<br>

find the code here!

and Libraries here!

Step 6: Mobile APP

We used MIT APP DEVELOPER, so that you can easily reproduce this project for yourself, here is the .aia file which you can import into MIT App inventor and easily customize for your project and application.

Simply import the project and go to build option, which will show you link and QR code, next install this app on your phone.

We can do this entire Task with BLYNK which indeed looks better in terms of UI, but blynk is not completely free, it comes with lot of restrictions, yet coding and backend work of Blynk is way easier than MIT and definitely is useful for making simple Switch projects.

Step 7: Power Electronics

We need to mount this system in Balcony or some place with access to Environment, we can’t power this system with USB wire, so it makes sense to use a Battery, best option would be a Lithium Polymer Battery but my Balcony is home to lots of birds and squirrels, I can’t afford accidental fire here. So safer option would be a Lithium Ion battery, which adds up a little weight but offers higher Capacity and Safety as well. I have this Lithium Ion Cell with 2000 mAh Capacity and we will add a TP4056 Li ion charging module along with it.

After looking at Node MCU’s datasheet, we get to know that NODE MCU uses up to 170 milliamps. At 2000 mAh capacity and current draw of 170 milliamps, we get use time of around 11 hours, which is not much, but luckily we have Deep Sleep Mode in our NodeMCU, which basically puts our System in Deep Sleep to reduce Power Consumption. Simply add Esp.deepsleep (time in microseconds) at the end of our loop.

Esp.deepsleep (3e+8);<br>

Upload the code and then connect D0 to Reset pin,do not connect D0 and Reset before uploading the code else you will get uploading error. During the Sleep mode, our system uses 8 milliamps. Which turns down our overall current consumption of system and it brings battery life to 10 days ideally. We can remove the LEDs on Node MCU, DHT11 and Rain sensor to further reduce power consumption, but honestly 10 days is fine with me and I am happy with this system.

Step 8: Printed Circuit Board

As of yet, this project was on Breadboard, so we need to convert it to a PCB for which can be done using Online PCB services or by using a General Purpose Board. Since I was short on time, I went with a rather unprofessional way, that is a General Purpose Board, yet I have designed PCB and added Gerber File, which can be found here! and Schematic can be Found here!

Step 9: Enclosure

We are done with our PCB and Code, it’s time to test Everything with our APP, system is working well, it is optimized in power consumption, but it looks like mess, let’s try to bring the system in an enclosure, but I don’t have a 3D printer, so I would use a Plastic Container to stuff everything inside, make appropriate slot for DHT11 sensor and I choose to Mount Rain Sensor independent of box to reduce chances of unnecessary water entering into system via slots, after all drilling and cutting was done, I painted the enclosure with a High Temperature Silver Paint and finally used few zip ties to secure this system to my grill.

Step 10: Conclusion!

Finally after doing all the above steps, we can easily monitor Temperature at balcony from anywhere in world, just to get a gist of this, I told my friends to install this app on their phones and see how the app updates sensor’s data in real-time. if you enjoyed this Detailed yet Fun IOT project, do give this blog a Like, if your feel this helped you in any way, share it with your friends, that will help us grow and definitely it boosts our morale.

Thank You!

Backyard Contest

Participated in the
Backyard Contest

Be the First to Share

    Recommendations

    • Back to School: Student Design Challenge

      Back to School: Student Design Challenge
    • Space Contest

      Space Contest
    • Rocks, Gems, and Stones Speed Challenge

      Rocks, Gems, and Stones Speed Challenge

    11 Comments

    0
    DabsyDabs
    DabsyDabs

    Question 4 days ago on Step 7

    Hey! Nice project you got here, was just wondering... What is the voltage of the battery you are using? I'm using a Li-ion battery with 3.7v and it can't run. How can you make yours run on NodeMCU VIN pin that requires 5V input?

    0
    AwesomeBanana120
    AwesomeBanana120

    Question 5 months ago

    Hi MissionCritical!

    I hope you are doing well today. I am going to be building my weather station next week and I was running the code and I got this error message that says "DHT does not name a type" and some other errors which I included in the file named error down below? Do you know why it says that and can you please tell me how to fix this error. I am really looking forward to building this and having my own custom built weather station, but without the code it will not work. I have included in this comment/problem the code plus the error message which you can download so you can take a look at it. I have already added those libraries and downloaded the CP210X downloader for my esp8266. Thanks, and I hope to get my weather station working as soon as possible so I can send you some pics of it and so I can enjoy it.

    Thank you in advance,
    AwesomeBanana120

    dht.png
    0
    sri497875
    sri497875

    11 months ago

    Hello,
    I wanted to ask the rain sensor is always showing rain not detected I even tried changing its senstivity why is it so? please reply asap
    Thankyou

    0
    AwesomeBanana120
    AwesomeBanana120

    Reply 10 months ago

    I also have that probelm?

    0
    ealexispb
    ealexispb

    10 months ago

    My code compiles correctly, but when I put it in my ESP the data isn't sent to my database. Obviously, neither the app works. I already checked the URL of the database, wifi SSID and password and don't find the error. Anyone knows what's happening?

    0
    VinayakNair
    VinayakNair

    1 year ago

    Awesome project, well explained and the video is well edited too. All the very best.

    0
    MissionCritical
    MissionCritical

    Reply 1 year ago

    glad that you liked it, thanks a lot for your support! :)

    0
    juliangonzalez1985
    juliangonzalez1985

    1 year ago

    great great project I love how it looks

    0
    MissionCritical
    MissionCritical

    Reply 1 year ago

    thanks buddy

    0
    AwesomeBanana120
    AwesomeBanana120

    Question 1 year ago

    Hi,
    I am trying to make this project and I am confused a little bit. One is where does everything plug into. It does not fully say. Is it any easier to buy the pcb board and where you plug the stuff into? For the battery where does that go. How does the arduino board get turned on without the 9V battery. If you buy the pcb board do you still have to solder. For the mit app inventor app I downloaded the aia file and then uploaded it but it did not show the 'will you need an umbrella' part. Can you please help me out with these questions. I really want to finish building my own weather station but I cannot finish it yet because I am stuck! If I could get a question back as soon as possible it would be gratefully appreciated!
    Thank you,
    AwesomeBanana120

    0
    MissionCritical
    MissionCritical

    Reply 1 year ago

    hey, you don't need Arduino, you need NODE MCU.
    Even if you order a PCB, you will have to Solder, you could get PCB assembled from few manufacturers, in that way you wont need to solder anything.
    Node MCU needs 3.3 to 5V power supply, for which you can use Lithium ion or Polymer, i have shared Circuit Diagram for Connections.
    about Umbrella part, i will check the .aia again and make necessary changes here itself.
    if you have more questions let me know.

    thank you