Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. My Project
  3. Basement Monitor

Basement Monitor

Scheduled Pinned Locked Moved My Project
temperaturephoto-resistorgas sensorwater sensorhumidityflame sensor
9 Posts 4 Posters 3.8k Views 6 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • micahM Offline
    micahM Offline
    micah
    wrote on last edited by micah
    #1

    Hi everyone.

    Been wanting to implement some mysensors goodness for awhile now, and I finally got around to building the first node for my home automation project.

    I'm learning as I go, so things aren't pretty yet.

    Before I continue, I wanted to start by thanking everyone on here, I've learned so much by reading your posts.

    This first node is called "BasementMonitor". It'll eventually be mounted to the wall under the stairs in the basement. It's purpose is to scan the following and report them to my (soon to be built) Raspberry Pi OpenHAB.

    • Temperature
    • Humidity
    • Gas (CO2)
    • Ambient light (to know if the lights were left on)
    • Flame
    • Water (on the floor)

    Since this is my first build it's not pretty... basically stuff hot glued into a tupperware container. I'll pretty it up once I'm done all my testing.

    My Node
    My Node view 2

    Here is my sketch so far. It's still pretty raw and I've got a bunch more things to implement, but it works :)

    #define MY_NODE_ID 2
    #define CHILD_ID_HUM 0
    #define CHILD_ID_TEMP 1
    #define CHILD_ID_LIGHT 2
    #define CHILD_ID_FLAME 3
    #define CHILD_ID_WATER 4
    #define CHILD_ID_GAS 5
    
    #include <SPI.h>
    #include <MySensor.h>  
    #include <DHT.h>  
    
    #define HUMIDITY_SENSOR_DIGITAL_PIN 5
    #define LIGHT_SENSOR_ANALOG_PIN A2
    #define FLAME_SENSOR_DIGITAL_PIN 3
    #define WATER_SENSOR_ANALOG_PIN A0
    #define GAS_SENSOR_ANALOG_PIN A1
    
    MySensor gw;
    DHT dht;
    float lastTemp;
    float lastHum;
    boolean metric = true; 
    MyMessage msgHum(CHILD_ID_HUM, V_HUM);
    MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
    MyMessage msgLight(CHILD_ID_LIGHT, V_LIGHT_LEVEL);
    MyMessage msgFlame(CHILD_ID_FLAME, V_STATUS);
    MyMessage msgWater(CHILD_ID_WATER, V_LEVEL);
    MyMessage msgGas(CHILD_ID_GAS, V_LEVEL);
    
    unsigned long pMillis_Photo = 0;
    unsigned long pMillis_WS = 0;
    unsigned long pMillis_DHT = 0;
    unsigned long pMillis_GS = 0;
    unsigned long pMillis_FS = 0;
    long sCheck_Photo = 60000;
    long sCheck_WS = 60000;
    long sCheck_DHT = 60000;
    long sCheck_GS = 20000;
    long sCheck_FS = 20000;
    int lastLightLevel;
    int lastFlameLevel;
    int lastWaterLevel;
    int lastGasLevel;
    
    void setup(){ 
      gw.begin(NULL, MY_NODE_ID, true);
      dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN); 
    
      gw.sendSketchInfo("Basement Monitor", "1.0");
    
      gw.present(CHILD_ID_HUM, S_HUM);
      gw.present(CHILD_ID_TEMP, S_TEMP);
      gw.present(CHILD_ID_LIGHT, S_LIGHT_LEVEL);
      gw.present(CHILD_ID_FLAME, S_LIGHT);
      gw.present(CHILD_ID_WATER, S_MOISTURE);
      gw.present(CHILD_ID_GAS, S_AIR_QUALITY);
      
      metric = gw.getConfig().isMetric;
    }
    void loop(){
      unsigned long currentMillis = millis();
      
      // Check Temp and Humidity
      if (currentMillis - pMillis_DHT >= sCheck_DHT){
        pMillis_DHT = currentMillis;
        
        float temperature = dht.getTemperature();
        if (isnan(temperature)) {
            Serial.println("Failed reading temperature from DHT");
        } else if (temperature != lastTemp) {
          lastTemp = temperature;
          if (!metric) {
            temperature = dht.toFahrenheit(temperature);
          }
          gw.send(msgTemp.set(temperature, 1));
          Serial.print("T: ");
          Serial.println(temperature);
        }
        
        float humidity = dht.getHumidity();
        if (isnan(humidity)) {
            Serial.println("Failed reading humidity from DHT");
        } else if (humidity != lastHum) {
            lastHum = humidity;
            gw.send(msgHum.set(humidity, 1));
            Serial.print("H: ");
            Serial.println(humidity);
        }
      }
      // Check light level
      if (currentMillis - pMillis_Photo >= sCheck_Photo){
        pMillis_Photo = currentMillis;
        
        //int lightLevel = (1023-analogRead(LIGHT_SENSOR_ANALOG_PIN))/10.23; 
        int lightLevel = analogRead(LIGHT_SENSOR_ANALOG_PIN); 
        Serial.print("L: ");
        Serial.println(lightLevel);
        if (lightLevel != lastLightLevel) {
          gw.send(msgLight.set(lightLevel));
          lastLightLevel = lightLevel;
        }
      }
      // Check Flame
      if (currentMillis - pMillis_FS >= sCheck_FS){
        pMillis_FS = currentMillis;
        // 1=no fire  0=fire
        int flameLevel = digitalRead(FLAME_SENSOR_DIGITAL_PIN);
        Serial.print("F: ");
        Serial.println(digitalRead(FLAME_SENSOR_DIGITAL_PIN));
        if (flameLevel != lastFlameLevel) {
          gw.send(msgFlame.set(flameLevel));
          lastFlameLevel = flameLevel;
        }
      }
      //Check water
      if (currentMillis - pMillis_WS >= sCheck_WS){
        pMillis_WS = currentMillis;
        //under 10 ignore   up to 70 = 1 drop   over 300 = really wet
        int waterLevel = analogRead(WATER_SENSOR_ANALOG_PIN);
        Serial.print("W: ");
        Serial.println(waterLevel);
        if (waterLevel != lastWaterLevel) {
          gw.send(msgWater.set(waterLevel));
          lastWaterLevel = waterLevel;
        }
      }
      // Check gas
      if (currentMillis - pMillis_GS >= sCheck_GS){
        pMillis_GS = currentMillis;
    
        int gasLevel = analogRead(GAS_SENSOR_ANALOG_PIN);
        Serial.print("G: ");
        Serial.println(gasLevel);
        if (gasLevel != lastGasLevel) {
          gw.send(msgWater.set(gasLevel));
          lastGasLevel = gasLevel;
        }
      }
    }
    
    1 Reply Last reply
    6
    • Mike MusskopfM Offline
      Mike MusskopfM Offline
      Mike Musskopf
      wrote on last edited by
      #2

      Good stuff! You manage to cover everything... maybe just a PIR sensor to control the lights?! ;)

      Don't forget to replace the breadboard with some protoboard and proper soldering! I hate when my prototypes start to misbehaving, and after 2 hours debugging, I discover that was a bad contact from the breadboard... :(

      Also an Arduino Nano/Pro might help you saving some space and will look great if you attach everything into a protoboard and connect your sensors with those 2.54mm white board-to-wire connectors (like those ones: http://uk.farnell.com/productimages/standard/en_GB/CN09580-40.jpg).

      Cheers,
      Mike M.

      http://talk2.wisen.com.au

      micahM 1 Reply Last reply
      1
      • Mike MusskopfM Mike Musskopf

        Good stuff! You manage to cover everything... maybe just a PIR sensor to control the lights?! ;)

        Don't forget to replace the breadboard with some protoboard and proper soldering! I hate when my prototypes start to misbehaving, and after 2 hours debugging, I discover that was a bad contact from the breadboard... :(

        Also an Arduino Nano/Pro might help you saving some space and will look great if you attach everything into a protoboard and connect your sensors with those 2.54mm white board-to-wire connectors (like those ones: http://uk.farnell.com/productimages/standard/en_GB/CN09580-40.jpg).

        Cheers,
        Mike M.

        micahM Offline
        micahM Offline
        micah
        wrote on last edited by
        #3

        @Mike-Musskopf

        Thanks for the feedback Mike.

        The PIR is a good idea, but I've converted my basement into an apartment and have a tenant, so I don't want to mess with his lights, I just want to know if he leaves them on all the time ;)

        Great tip on replacing the breadboard. Learning to solder is the next thing on my list.

        I've also just placed a big order from AliExpress for more toys... lol... including some Arduino Pros.

        This hobby is addicting and quickly spirals out of control... I initially only wanted to make 1 sensor, and now I've already got a list of 8 projects I want to make :)

        1 Reply Last reply
        0
        • micahM Offline
          micahM Offline
          micah
          wrote on last edited by
          #4

          I figure I should add a wiring diagram

          0_1459962491785_mb_BasementMonitor.jpg

          TheoLT 1 Reply Last reply
          0
          • micahM micah

            I figure I should add a wiring diagram

            0_1459962491785_mb_BasementMonitor.jpg

            TheoLT Online
            TheoLT Online
            TheoL
            Contest Winner
            wrote on last edited by
            #5

            @micah Looks good. I didn't know you could power a Nano with to AA's. Very curious how long they'll last. Would be great if you keep us informed.

            micahM 1 Reply Last reply
            0
            • TheoLT TheoL

              @micah Looks good. I didn't know you could power a Nano with to AA's. Very curious how long they'll last. Would be great if you keep us informed.

              micahM Offline
              micahM Offline
              micah
              wrote on last edited by
              #6

              @TheoL The nano is only temporary while I wait for AliExpress to deliver my 6 Pro Minis I ordered last week.... so hopefully the AAs will last 4 to 5 weeks... lol

              Mike MusskopfM 1 Reply Last reply
              0
              • micahM micah

                @TheoL The nano is only temporary while I wait for AliExpress to deliver my 6 Pro Minis I ordered last week.... so hopefully the AAs will last 4 to 5 weeks... lol

                Mike MusskopfM Offline
                Mike MusskopfM Offline
                Mike Musskopf
                wrote on last edited by
                #7

                @micah
                Just need to be careful with those Gas sensors, they normally have a heater which needs to be ON well before you take any measurement, and it might draw some current. There are other solutions for Carbon Monoxide, like those ones: http://www.figarosensor.com/feature/tgs5042_tgs5342.html, but they are very expensive. Maybe there are other manufactures using the same electrochemical, but never stop to searched for it.

                All other sensors you should be able to put it to sleep and only read very quickly.

                About the battery supply, I've posted some comments on another topic: http://forum.mysensors.org/topic/3460/cheap-ldo-for-battery-usage/17 which might interest you.

                Cheers!

                http://talk2.wisen.com.au

                micahM 1 Reply Last reply
                1
                • Mike MusskopfM Mike Musskopf

                  @micah
                  Just need to be careful with those Gas sensors, they normally have a heater which needs to be ON well before you take any measurement, and it might draw some current. There are other solutions for Carbon Monoxide, like those ones: http://www.figarosensor.com/feature/tgs5042_tgs5342.html, but they are very expensive. Maybe there are other manufactures using the same electrochemical, but never stop to searched for it.

                  All other sensors you should be able to put it to sleep and only read very quickly.

                  About the battery supply, I've posted some comments on another topic: http://forum.mysensors.org/topic/3460/cheap-ldo-for-battery-usage/17 which might interest you.

                  Cheers!

                  micahM Offline
                  micahM Offline
                  micah
                  wrote on last edited by
                  #8

                  @Mike-Musskopf thanks for all the great tips... I'm sure I'll be coming back to this post all frustrated in a week or so once my batteries are dead ;)

                  There is just so much to learn with this Arduino MySensors stuff... I'm loving it, but there is just so much!

                  1 Reply Last reply
                  0
                  • alexsh1A Offline
                    alexsh1A Offline
                    alexsh1
                    wrote on last edited by
                    #9

                    I hate to disappoint you @micah but @Mike-Musskopf has got a point:

                    1. MQ* sensors are power hungry. You may want to connect everything up to 240V via a small PSU. There is a big thread on mysensors about air quality detection.

                    2. DHT is not the best sensor for a battery application. Please check BME280 (pressure, temp and hum) or Si7021 (temp and hum) - these would be my favourite sensors for low power consumption.

                    Small tip - your Arduino Pros must be 3.3V and not 5V for the battery usage.

                    1 Reply Last reply
                    1
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    18

                    Online

                    11.7k

                    Users

                    11.2k

                    Topics

                    113.1k

                    Posts


                    Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • MySensors
                    • OpenHardware.io
                    • Categories
                    • Recent
                    • Tags
                    • Popular