Basement Monitor

  • 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>  
    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);
      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: ");
        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: ");
      // 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: ");
        if (lightLevel != lastLightLevel) {
          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: ");
        if (flameLevel != lastFlameLevel) {
          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: ");
        if (waterLevel != lastWaterLevel) {
          lastWaterLevel = waterLevel;
      // Check gas
      if (currentMillis - pMillis_GS >= sCheck_GS){
        pMillis_GS = currentMillis;
        int gasLevel = analogRead(GAS_SENSOR_ANALOG_PIN);
        Serial.print("G: ");
        if (gasLevel != lastGasLevel) {
          lastGasLevel = gasLevel;

  • 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:

    Mike M.

  • @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 🙂

  • I figure I should add a wiring diagram


  • Contest Winner

    @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.

  • @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

  • @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:, 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: which might interest you.


  • @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!

  • 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.

Suggested Topics