Showing posts with label Mysensor. Show all posts
Showing posts with label Mysensor. Show all posts

Monday, July 13, 2015

Mysensor Weather forecast using BMP180 and DHT11

Dear Readers, 

This schematic/circuit is a node for MySensor Gateway. For more information on Mysensor, please visit here

Material Required:

  • Arduino Mini Pro 5V 16M
  • NRF24L01+
  • BMP180 Pressure sensor module
  • DHT11 Temp+Humidity module
  • Breadboard Power Supply
  • Breadboard
  • Jumper wire (Male/Female) as required


Arduino Mini Pro
Arduino Mini Pro
NRF24L01+ with homemade breadboard adapter
NRF24L01+ with homemade breadboard adapter


DHT11 (Temperature+Humidity)
DHT11 (Temperature+Humidity)

BMP180 (Pressure+Temperature)
BMP180 (Pressure+Temperature)


Complete Parts





Schematic


Source Code:

I am still trying to figure out how I can get the code formatted on blogger, till then bear with me.
 #include <SPI.h>
    #include <MySensor.h> 
    #include <DHT.h> 
    #include <Wire.h>
    #include <Adafruit_BMP085.h>
   
    #define CHILD_ID_HUM 1
    #define CHILD_ID_TEMP 2
    #define CHILD_ID_BARO 3
    #define CHILD_ID_BTEMP 4
   
    #define HUMIDITY_SENSOR_DIGITAL_PIN 4
   
    boolean metric = false;
    int altitude = 216; // 741 feet above sealevel
    float lastBmpTemp = -1;
    float lastPressure = -1;
    float lastHum = -1;
    float lastTemp = -1;
    int updateAll = 60;
    int updateCount = 0;
    unsigned long SLEEP_TIME = 60000;
   
    Adafruit_BMP085 bmp = Adafruit_BMP085();
    DHT dht;
    MySensor gw;
   
    MyMessage msgHum(CHILD_ID_HUM, V_HUM);
    MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
    MyMessage msgBtemp(CHILD_ID_BTEMP, V_TEMP);
    MyMessage msgPressure(CHILD_ID_BARO, V_PRESSURE);
   
    void setup() 
    {
      analogReference(INTERNAL);
      gw.begin();
      dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN);
      bmp.begin();
      gw.sendSketchInfo("Weather Station", "1.0");
      gw.present(CHILD_ID_HUM, S_HUM);
      gw.present(CHILD_ID_TEMP, S_TEMP);
      gw.present(CHILD_ID_BARO, S_BARO);
      gw.present(CHILD_ID_BTEMP, S_TEMP);
      metric = gw.getConfig().isMetric;
    }
   
    void loop()     
    {
      updateCount += 1;
      if (updateCount == updateAll) {
        lastTemp = -1;
        lastHum = -1;
        lastBmpTemp = -1;
        lastPressure = -1;
        updateCount = 0;
      }
      delay(dht.getMinimumSamplingPeriod());
      float temperature = dht.getTemperature();
      if (isnan(temperature)) {
          lastTemp = -1;
      } else if (temperature != lastTemp) {
        lastTemp = temperature;
        if (!metric) {
          //temperature = temperature * 1.8 + 32.0;
        }
        gw.send(msgTemp.set(temperature, 1));
      }
      float humidity = dht.getHumidity();
      if (isnan(humidity)) {
          lastHum = -1;
      } else if (humidity != lastHum) {
          lastHum = humidity;
          gw.send(msgHum.set(humidity, 1));
      }
      float pressure = bmp.readSealevelPressure(altitude) * 0.01;
      float bmptemp = bmp.readTemperature();
      if (!metric) {
        //bmptemp = bmptemp * 1.8 + 32.0;
      }
      if (bmptemp != lastBmpTemp) {
        gw.send(msgBtemp.set(bmptemp,1));
        lastBmpTemp = bmptemp;
      }
      if (pressure != lastPressure) {
        gw.send(msgPressure.set(pressure, 0));
        lastPressure = pressure;
      }
      gw.sleep(SLEEP_TIME);
    }

Download Sketch here