Mohamed Jinas
Published © MIT

Lets Make: A Weather Station

A weather station built using Arduino and javascript.

IntermediateProtip2 hours465

Story

Read more

Schematics

Wiring diagram of DHT11

Code

Code snippet #6

Plain text
io.sockets.emit('data', {
     humidity: humidity,
     temperature: temperature,
     date: date,
     day: day,
     secondDay: secondDay,
     thirdDay: thirdDay,
     fourthDay: fourthDay
});

Code snippet #7

Plain text
feather.replace()

var socket = io.connect('http://127.0.0.1:4000/');
var temperature = new Vue({
    el: '#app',
    data: {
        ApiUrl: 'http://moosunmv.jinas.me/v1/latest',
        temperature: '',
        humidity: '',
        date: '',
        day: '',
        wind: '',
        secondDay: '',
        thirdDay: '',
        fourthDay: ''
    },
    methods: {
        getWeather(){
            var vm = this;
            axios.get(this.ApiUrl)
            .then(function (response) {
                vm.wind = response.data.wind;
                console.log(vm.wind);
            })
        }
    },
    mounted: function () {
        socket.on('data', function (data) {
            this.temperature = data.temperature;
            console.log(this.temperature);
            this.humidity = data.humidity;
            console.log(this.humidity);
            this.date = data.date;
            this.day = data.day;
            this.secondDay = data.secondDay;
            this.thirdDay = data.thirdDay;
            this.fourthDay = data.fourthDay;
        }.bind(this));

        this.getWeather();

    }

});

Code snippet #8

Plain text
feather.replace()

var socket = io.connect('http://127.0.0.1:4000/');
var temperature = new Vue({
    el: '#app',
    data: {
        ApiUrl: 'http://moosunmv.jinas.me/v1/latest',
        temperature: '',
        humidity: '',
        date: '',
        day: '',
        wind: '',
        secondDay: '',
        thirdDay: '',
        fourthDay: ''
    },
    methods: {
        getWeather(){
            var vm = this;
            axios.get(this.ApiUrl)
            .then(function (response) {
                vm.wind = response.data.wind;
                console.log(vm.wind);
            })
        }
    },
    mounted: function () {
        socket.on('data', function (data) {
            this.temperature = data.temperature;
            console.log(this.temperature);
            this.humidity = data.humidity;
            console.log(this.humidity);
            this.date = data.date;
            this.day = data.day;
            this.secondDay = data.secondDay;
            this.thirdDay = data.thirdDay;
            this.fourthDay = data.fourthDay;
        }.bind(this));

        this.getWeather();

    }

});

Code snippet #9

Plain text
<div class="info-side">
    <div class="today-info-container">
      <div class="today-info">
        <div class="precipitation"> <span class="title">PRECIPITATION</span><span class="value">0 %</span>
          <div class="clear"></div>
        </div>
        <div class="humidity"> <span class="title">HUMIDITY</span><span class="value">{{humidity}} %</span>
          <div class="clear"></div>
        </div>
        <div class="wind"> <span class="title">WIND</span><span class="value">{{wind}}</span>
          <div class="clear"></div>
        </div>
      </div>
    </div>

Code snippet #10

Plain text
<div class="info-side">
    <div class="today-info-container">
      <div class="today-info">
        <div class="precipitation"> <span class="title">PRECIPITATION</span><span class="value">0 %</span>
          <div class="clear"></div>
        </div>
        <div class="humidity"> <span class="title">HUMIDITY</span><span class="value">{{humidity}} %</span>
          <div class="clear"></div>
        </div>
        <div class="wind"> <span class="title">WIND</span><span class="value">{{wind}}</span>
          <div class="clear"></div>
        </div>
      </div>
    </div>

Code snippet #1

Plain text
#include "DHT.h"

//Sensor digital pin
#define DHTPIN 8
//Setting the sensor type
#define DHTTYPE DHT11

DHT dht(DHTPIN, DHTTYPE);

void setup() {
    //Starting the serial communication
    Serial.begin(9600);
    dht.begin();
}

void loop() {
    //delay for 2 second before reading again
    delay(2000);
    //setting humidity
    float humidity = dht.readHumidity();
    //setting temperature
    float temperature = dht.readTemperature();

    Serial.print(temperature);
    //Output for splitting the string into two array during serial read.
    Serial.print(",");
    Serial.println(humidity);
}

Code snippet #2

Plain text
#include "DHT.h"

//Sensor digital pin
#define DHTPIN 8
//Setting the sensor type
#define DHTTYPE DHT11

DHT dht(DHTPIN, DHTTYPE);

void setup() {
    //Starting the serial communication
    Serial.begin(9600);
    dht.begin();
}

void loop() {
    //delay for 2 second before reading again
    delay(2000);
    //setting humidity
    float humidity = dht.readHumidity();
    //setting temperature
    float temperature = dht.readTemperature();

    Serial.print(temperature);
    //Output for splitting the string into two array during serial read.
    Serial.print(",");
    Serial.println(humidity);
}

Code snippet #3

Plain text
var today = new Date();
var date = today.getDate() + "-" + (today.getMonth() + 1) + "-" + today.getFullYear();
weekday = [
    "Sunday", "Monday", "Tuesday", "Wednesday", "Thurday", "Friday", "Saturday"
];
var day = weekday[today.getDay()];
var secondDay = weekday[today.getDay() + 1];
var thirdDay = weekday[today.getDay() + 2];
var fourthDay = weekday[today.getDay() + 3];

Code snippet #4

Plain text
var today = new Date();
var date = today.getDate() + "-" + (today.getMonth() + 1) + "-" + today.getFullYear();
weekday = [
    "Sunday", "Monday", "Tuesday", "Wednesday", "Thurday", "Friday", "Saturday"
];
var day = weekday[today.getDay()];
var secondDay = weekday[today.getDay() + 1];
var thirdDay = weekday[today.getDay() + 2];
var fourthDay = weekday[today.getDay() + 3];

Code snippet #5

Plain text
io.sockets.emit('data', {
     humidity: humidity,
     temperature: temperature,
     date: date,
     day: day,
     secondDay: secondDay,
     thirdDay: thirdDay,
     fourthDay: fourthDay
});

Github

https://github.com/adafruit/DHT-sensor-library

Github

https://github.com/axios/axios

Github

https://github.com/jinas123/weather-station-arduino

Github

https://github.com/jinas123/weather-station

Credits

Mohamed Jinas
3 projects • 3 followers
Student, a Software developer based in Maldives.
Contact

Comments

Please log in or sign up to comment.