Austin Detzel
Published © CC BY-NC-SA

How To Make An Mini IOT Weather Station

Let's make a little portable IoT weather station for under $20 using Arduino and the Blynk library!

IntermediateFull instructions provided2 hours9,854
How To Make An Mini IOT Weather Station

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
DHT11 Temperature & Humidity Sensor (4 pins)
DHT11 Temperature & Humidity Sensor (4 pins)
×1
433mhz Transmitter (Generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE
Blynk
Blynk

Story

Read more

Code

Code snippet #1

Plain text
#include <VirtualWire.h> //Download Here#include "DHT.h"DHT dht(2, DHT11);int Sensor1Data;
int Sensor2Data;
char Sensor1CharMsg[4];
char Sensor2CharMsg[4];void setup()
{
  vw_set_ptt_inverted(true);  // Required by the RF module
  vw_setup(2000);            // bps connection speed
  vw_set_tx_pin(3);         // Arduino pin to connect the receiver data pin  //Serial.begin(9600); //uncomment to debug
  dht.begin();
  Serial.println();}void loop()
{
  Serial.println("\n");  Sensor1Data = dht.readTemperature(true);
  Sensor2Data = dht.readHumidity();
  delay(2000);
  // Convert integer data to Char array directly
  itoa(Sensor1Data, Sensor1CharMsg, 10);
  itoa(Sensor2Data, Sensor2CharMsg, 10);  Serial.print("Read sensor: ");  char astr[4] = {'t', 'e', 'm', 'p',};
  char bstr[4] = {'h', 'u', 'm', 'i',};
  Serial.print("Humidity (%): ");
  Serial.println((float)dht.readHumidity(), 2);  Serial.print("Temperature (oC): ");
  Serial.println((float)dht.readTemperature(true), 2);  delay(1000);  //Message to send:
  digitalWrite(13, true); // Turn on a light to show transmitting
  vw_send((uint8_t *)astr, 4);  
  vw_send((uint8_t *)Sensor1CharMsg, strlen(Sensor1CharMsg));
  vw_send((uint8_t *)bstr, 4);
  vw_send((uint8_t *)Sensor2CharMsg, strlen(Sensor2CharMsg));
  vw_wait_tx(); // Wait until the whole message is gone
  digitalWrite(13, false); // Turn off a light after transmission
  delay(9000);
}

Code snippet #2

Plain text
#include <SPI.h>#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
#include <VirtualWire.h>
#include <Wire.h>int TEMP;int tempurature;
int humidity;char auth[] = "9bb52b5cfa6b4c4bbcde617a64886ed5";void setup()
{
  Serial.begin(9600);
  vw_set_rx_pin(2);
  vw_setup(2000);
  vw_rx_start();
  Blynk.begin(auth);
}void loop()
{
  Blynk.run();
  uint8_t buf[VW_MAX_MESSAGE_LEN];
  uint8_t buflen = VW_MAX_MESSAGE_LEN;
  if (vw_get_message(buf, &buflen)) // Non-blocking
  {    int i;
    char c;
    String input;
    for (i = 0; i < buflen; i++)
    {
      c = ((char)buf[i]);
      input += ((char)buf[i]);
      //Serial.print((char)buf[i]);
    }
    if (c == 'p') {
      Serial.print("TEMPURATURE CHECK");
      TEMP = true;
    }
    if (c == 'i') {
      Serial.print("HUMIDITY CHECK");
      TEMP = false;
    }
    if (c != 'p' && c != 'i') {
      if (TEMP == true) {
        tempurature = input.toInt();
        if (tempurature != humidity) {
          Blynk.virtualWrite(V12, tempurature);
        }
        Serial.print(tempurature);
      }
      else {
        humidity = input.toInt();
        if (tempurature != humidity) {
          Blynk.virtualWrite(V13, humidity);
        }
        Serial.print(humidity);
        /*double celsius = (tempurature - 32) * 5/9;
          double a = 17.271;
          double b = 237.7;
          double temp2 = (a * celsius) / (b + celsius) + log(humidity*0.01);
          double Td = (b * temp2) / (a - temp2);
          Td = ((Td*9) / 5) + 32;
          Blynk.virtualWrite(V14, Td);
        */
      }
    }    Serial.println();  }
}

Credits

Austin Detzel

Austin Detzel

26 projects • 33 followers

Comments

Add projectSign up / Login