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. Slim Node Si7021 sensor example

Slim Node Si7021 sensor example

Scheduled Pinned Locked Moved My Project
137 Posts 18 Posters 64.8k Views 20 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.
  • m26872M m26872

    @ar91 Did you change baud rate in MySensors config too?

    A Offline
    A Offline
    ar91
    wrote on last edited by
    #13

    Thanks @m26872, I changed the baud rate on MyConfig.h and it started working.

    1 Reply Last reply
    1
    • m26872M m26872

      @carlierd What's your setup then? The DHT22 is for 3.3-5.5V.

      carlierdC Offline
      carlierdC Offline
      carlierd
      wrote on last edited by
      #14

      @m26872 My nodes are working correctly for the moment. Actually one is at 2.8v. Perhaps I will have problem when voltage will be lower !

      David.

      m26872M 1 Reply Last reply
      0
      • carlierdC carlierd

        @m26872 My nodes are working correctly for the moment. Actually one is at 2.8v. Perhaps I will have problem when voltage will be lower !

        David.

        m26872M Offline
        m26872M Offline
        m26872
        Hardware Contributor
        wrote on last edited by
        #15

        @carlierd Probably. That's why I ask what you use. DHT22 connected straight to 2AA will not utilize battery capacity. Higher battery voltage with step down regulator would be better - or maybe without, but with like 3AAs or so.

        carlierdC 1 Reply Last reply
        0
        • carlierdC carlierd

          @m26872 : I don't use booster. You think it's necessary ? 90uA is really important for battery operation.

          For the design off course I will make it open hardware :)

          David.

          A Offline
          A Offline
          ar91
          wrote on last edited by
          #16

          @carlierd With Slim Node running at 1Mhz even with or without booster i am having hardtime making DHT22 work. I even tried different libraries but none of them works at 1Mhz. How did you get it work?

          m26872M carlierdC 2 Replies Last reply
          0
          • A ar91

            @carlierd With Slim Node running at 1Mhz even with or without booster i am having hardtime making DHT22 work. I even tried different libraries but none of them works at 1Mhz. How did you get it work?

            m26872M Offline
            m26872M Offline
            m26872
            Hardware Contributor
            wrote on last edited by
            #17

            @ar91 I don't think there's a good reason to go below 8MHz if DHT22 doesn't work much below 3.3V ?

            1 Reply Last reply
            1
            • m26872M m26872

              @carlierd Probably. That's why I ask what you use. DHT22 connected straight to 2AA will not utilize battery capacity. Higher battery voltage with step down regulator would be better - or maybe without, but with like 3AAs or so.

              carlierdC Offline
              carlierdC Offline
              carlierd
              wrote on last edited by
              #18

              @m26872 Perhaps that with a caps I can go very low. I want to have at least one year on 2 AA. Wait and see !

              1 Reply Last reply
              0
              • A ar91

                @carlierd With Slim Node running at 1Mhz even with or without booster i am having hardtime making DHT22 work. I even tried different libraries but none of them works at 1Mhz. How did you get it work?

                carlierdC Offline
                carlierdC Offline
                carlierd
                wrote on last edited by
                #19

                @ar91 Hello. I am using the arduino playground lib. No issue with it ! I can post a sketch if necessary.

                David.

                A 1 Reply Last reply
                0
                • carlierdC carlierd

                  @ar91 Hello. I am using the arduino playground lib. No issue with it ! I can post a sketch if necessary.

                  David.

                  A Offline
                  A Offline
                  ar91
                  wrote on last edited by
                  #20

                  @carlierd If you could share your code that will be great.

                  carlierdC 1 Reply Last reply
                  0
                  • A ar91

                    @carlierd If you could share your code that will be great.

                    carlierdC Offline
                    carlierdC Offline
                    carlierd
                    wrote on last edited by
                    #21

                    @ar91 Please find the code I used in 3 different nodes. The good thing with the playground lib is that there is error message if dialog with DHT22 failed.

                    /**
                     * The MySensors Arduino library handles the wireless radio link and protocol
                     * between your home built sensors/actuators and HA controller of choice.
                     * The sensors forms a self healing radio network with optional repeaters. Each
                     * repeater and gateway builds a routing tables in EEPROM which keeps track of the
                     * network topology allowing messages to be routed to nodes.
                     *
                     * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
                     * Copyright (C) 2013-2015 Sensnology AB
                     * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
                     *
                     * Documentation: http://www.mysensors.org
                     * Support Forum: http://forum.mysensors.org
                     *
                     * This program is free software; you can redistribute it and/or
                     * modify it under the terms of the GNU General Public License
                     * version 2 as published by the Free Software Foundation.
                     *
                     */
                    
                    /**************************************************************************************/
                    /* Temperature, humidity and luminosity measurements.                                 */
                    /*                                                                                    */
                    /* Version     : 1.1.6                                                                */
                    /* Date        : 10/01/2016                                                           */
                    /* Modified by : David Carlier                                                        */
                    /**************************************************************************************/
                    /*                                ---------------                                     */
                    /*                            RST |             |  A5                                 */
                    /*                            RX  |             |  A4                                 */
                    /*                            TX  |   ARDUINO   |  A3                                 */
                    /*     RFM69 (DIO0) --------- D2  |     UNO     |  A2                                 */
                    /*            DHT22 --------- D3  |             |  A1                                 */
                    /*            Power --------- D4  | ATMEGA 328p |  A0 --------- Light dep. resistor   */
                    /*              +3v --------- VCC |             | GND --------- GND                   */
                    /*              GND --------- GND |  8MHz int.  | REF                                 */
                    /*                            OSC |             | VCC --------- +3v                   */
                    /*                            OSC |             | D13 --------- RFM69 (SCK)           */
                    /*                            D5  |             | D12 --------- RFM69 (MISO)          */
                    /*                            D6  |             | D11 --------- RFM69 (MOSI)          */
                    /*                            D7  |             | D10 --------- RFM69 (NSS)           */
                    /*                            D8  |             |  D9                                 */
                    /*                                ---------------                                     */
                    /*                                                                                    */
                    /* Power = Vcc for LDR.                                                               */
                    /* +3v = 2*AA                                                                         */
                    /*                                                                                    */
                    /**************************************************************************************/
                    
                    #include <SPI.h>
                    #include <MySensor.h>
                    #include <dht.h>
                    #include <MyTransportRFM69.h>
                    #include <MySigningAtsha204Soft.h>
                    
                    #define CHILD_ID_HUM 0
                    #define CHILD_ID_TEMP 1
                    #define CHILD_ID_LIGHT 2
                    #define CHILD_ID_VOLTAGE 3
                    #define LIGHT_SENSOR_ANALOG_PIN 0
                    #define HUMIDITY_SENSOR_DIGITAL_PIN 3
                    #define POWER_PIN 4
                    //unsigned long SLEEP_TIME = 850000; // Sleep time between reads (in milliseconds) (close to 15')
                    unsigned long SLEEP_TIME = 275000; // Sleep time between reads (in milliseconds) (close to 5')
                    
                    //Construct MySensors library
                    MySigningAtsha204Soft signer;
                    MyHwATMega328 hw;
                    MyTransportRFM69 transport;
                    MySensor gw(transport, hw, signer);
                    dht DHT;
                    MyMessage msgHum(CHILD_ID_HUM, V_HUM);
                    MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
                    MyMessage msgLum(CHILD_ID_LIGHT, V_LEVEL);
                    MyMessage msgVolt(CHILD_ID_VOLTAGE, V_VOLTAGE);
                    
                    /**************************************************************************************/
                    /* Initialization                                                                     */
                    /**************************************************************************************/
                    void setup()
                      {
                      //Get time (for setup duration)
                      #ifdef DEBUG
                        unsigned long startTime = millis();
                      #endif
                    
                      //Start MySensors
                      gw.begin();
                    
                      //Send the Sketch Version Information to the Gateway
                      gw.sendSketchInfo("GHAS sensor", "1.1.5");
                    
                      //Register all sensors to gw (they will be created as child devices)
                      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_VOLTAGE, S_MULTIMETER);
                    
                      //Delay for DHT22
                      delay(1500);
                    
                      //Print setup debug
                      #ifdef DEBUG
                        int duration = millis() - startTime;
                        Serial.print("[Setup duration: "); Serial.print(duration, DEC); Serial.println(" ms]");
                      #endif
                      }
                    
                    /**************************************************************************************/
                    /* Main loop                                                                          */
                    /**************************************************************************************/
                    void loop()
                      {
                      //Get time (for a complete loop)
                      #ifdef DEBUG
                        unsigned long startTime = millis();
                      #endif
                    
                      //Power on
                      powerOnPeripherals();
                    
                      //Get DHT22 data
                      int dht22Result = DHT.read22(HUMIDITY_SENSOR_DIGITAL_PIN);
                      switch (dht22Result)
                        {
                        case DHTLIB_OK:  
                                    //Serial.println("OK,\t");
                                    break;
                        case DHTLIB_ERROR_CHECKSUM:
                                    #ifdef DEBUG
                                      Serial.println("Checksum error,\t");
                                    #endif
                                    break;
                        case DHTLIB_ERROR_TIMEOUT:
                                    #ifdef DEBUG
                                      Serial.println("Time out error,\t");
                                    #endif
                                    break;
                        case DHTLIB_ERROR_CONNECT:
                                    #ifdef DEBUG
                                      Serial.println("Connect error,\t");
                                    #endif
                                    break;
                        case DHTLIB_ERROR_ACK_L:
                                    #ifdef DEBUG
                                      Serial.println("Ack Low error,\t");
                                    #endif
                                    break;
                        case DHTLIB_ERROR_ACK_H:
                                    #ifdef DEBUG
                                      Serial.println("Ack High error,\t");
                                    #endif
                                    break;
                        default:
                                    #ifdef DEBUG
                                      Serial.println("Unknown error,\t");
                                    #endif
                                    break;
                        }
                    
                      //Get temperature and humidity
                      float temperature = 0;
                      float humidity = 0;
                      if (dht22Result == DHTLIB_OK)
                        {
                        temperature = DHT.temperature;
                        humidity = DHT.humidity;
                        }
                    
                      //Get power before luminosity to use real voltage
                      float realVoltage = getVoltage() / 100.0;
                      int batteryPcnt = realVoltage * 100 / 3.0;
                      if (batteryPcnt > 100) {batteryPcnt = 100;}
                      int lux = computeIlluminance(realVoltage);
                    
                      //Power off
                      powerOffPeripherals();
                    
                      //Send data to gateway
                      gw.send(msgHum.set(humidity, 1));
                      gw.send(msgTemp.set(temperature, 1));
                      gw.send(msgLum.set(lux));
                      gw.send(msgVolt.set(realVoltage, 2));
                      gw.sendBatteryLevel(batteryPcnt);
                    
                      //Print debug
                      #ifdef DEBUG
                        Serial.print(temperature, 1);
                        Serial.print(" degC");
                        Serial.print("   ");
                        Serial.print(humidity, 1);
                        Serial.print(" %");
                        Serial.print("   ");
                        Serial.print(lux);
                        Serial.print(" lx");
                        Serial.print("   ");
                        Serial.print(realVoltage);
                        Serial.print(" v");
                        int duration = millis() - startTime;
                        Serial.print("   ");
                        Serial.print("["); Serial.print(duration, DEC); Serial.println(" ms]");
                        Serial.flush();
                      #endif
                    
                      //Sleep
                      gw.sleep(SLEEP_TIME);
                      }
                    
                    /**************************************************************************************/
                    /* Allows to compute illuminance (in LUX) from LIGHT_SENSOR_ANALOG_PIN.               */
                    /**************************************************************************************/
                    int computeIlluminance(float realVoltage)
                      {
                      //Get luminosity
                      int luminosity = analogRead(LIGHT_SENSOR_ANALOG_PIN);
                      //Calculating the voltage in the input of the ADC
                      double voltage = realVoltage * ((double)luminosity / 1024.0);
                      //Calculating the resistance of the photoresistor in the voltage divider
                      double resistance = (10.0 * realVoltage) / voltage - 10.0;
                      //Calculating the intensity of light in lux and return it
                      int illuminance = 255.84 * pow(resistance, -10/9);
                      return illuminance;
                      }
                    
                    /**************************************************************************************/
                    /* Allows to get the real Vcc (return value * 100).                                   */
                    /**************************************************************************************/
                    int getVoltage()
                      {
                      const long InternalReferenceVoltage = 1056L;
                      ADMUX = (0<<REFS1) | (1<<REFS0) | (0<<ADLAR) | (1<<MUX3) | (1<<MUX2) | (1<<MUX1) | (0<<MUX0);
                      delay(50);  // Let mux settle a little to get a more stable A/D conversion
                      //Start a conversion  
                      ADCSRA |= _BV( ADSC );
                      //Wait for it to complete
                      while (((ADCSRA & (1<<ADSC)) != 0));
                      //Scale the value
                      int result = (((InternalReferenceVoltage * 1023L) / ADC) + 5L) / 10L;
                      return result;
                      }
                    
                    /**************************************************************************************/
                    /* Allows to power ON peripherals.                                                    */
                    /**************************************************************************************/
                    void powerOnPeripherals()
                      {
                      //Power-up
                      pinMode (POWER_PIN, OUTPUT);
                      digitalWrite (POWER_PIN, HIGH);
                      delay(1);
                      }
                    
                    /**************************************************************************************/
                    /* Allows to power OFF peripherals.                                                   */
                    /**************************************************************************************/
                    void powerOffPeripherals()
                      {
                      //Power off
                      digitalWrite (HUMIDITY_SENSOR_DIGITAL_PIN, LOW);
                      digitalWrite (POWER_PIN, LOW);
                      pinMode (HUMIDITY_SENSOR_DIGITAL_PIN, INPUT);
                      pinMode (POWER_PIN, INPUT);
                      }
                    

                    Hope it helps !

                    David.

                    A siodS 3 Replies Last reply
                    1
                    • carlierdC carlierd

                      @ar91 Please find the code I used in 3 different nodes. The good thing with the playground lib is that there is error message if dialog with DHT22 failed.

                      /**
                       * The MySensors Arduino library handles the wireless radio link and protocol
                       * between your home built sensors/actuators and HA controller of choice.
                       * The sensors forms a self healing radio network with optional repeaters. Each
                       * repeater and gateway builds a routing tables in EEPROM which keeps track of the
                       * network topology allowing messages to be routed to nodes.
                       *
                       * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
                       * Copyright (C) 2013-2015 Sensnology AB
                       * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
                       *
                       * Documentation: http://www.mysensors.org
                       * Support Forum: http://forum.mysensors.org
                       *
                       * This program is free software; you can redistribute it and/or
                       * modify it under the terms of the GNU General Public License
                       * version 2 as published by the Free Software Foundation.
                       *
                       */
                      
                      /**************************************************************************************/
                      /* Temperature, humidity and luminosity measurements.                                 */
                      /*                                                                                    */
                      /* Version     : 1.1.6                                                                */
                      /* Date        : 10/01/2016                                                           */
                      /* Modified by : David Carlier                                                        */
                      /**************************************************************************************/
                      /*                                ---------------                                     */
                      /*                            RST |             |  A5                                 */
                      /*                            RX  |             |  A4                                 */
                      /*                            TX  |   ARDUINO   |  A3                                 */
                      /*     RFM69 (DIO0) --------- D2  |     UNO     |  A2                                 */
                      /*            DHT22 --------- D3  |             |  A1                                 */
                      /*            Power --------- D4  | ATMEGA 328p |  A0 --------- Light dep. resistor   */
                      /*              +3v --------- VCC |             | GND --------- GND                   */
                      /*              GND --------- GND |  8MHz int.  | REF                                 */
                      /*                            OSC |             | VCC --------- +3v                   */
                      /*                            OSC |             | D13 --------- RFM69 (SCK)           */
                      /*                            D5  |             | D12 --------- RFM69 (MISO)          */
                      /*                            D6  |             | D11 --------- RFM69 (MOSI)          */
                      /*                            D7  |             | D10 --------- RFM69 (NSS)           */
                      /*                            D8  |             |  D9                                 */
                      /*                                ---------------                                     */
                      /*                                                                                    */
                      /* Power = Vcc for LDR.                                                               */
                      /* +3v = 2*AA                                                                         */
                      /*                                                                                    */
                      /**************************************************************************************/
                      
                      #include <SPI.h>
                      #include <MySensor.h>
                      #include <dht.h>
                      #include <MyTransportRFM69.h>
                      #include <MySigningAtsha204Soft.h>
                      
                      #define CHILD_ID_HUM 0
                      #define CHILD_ID_TEMP 1
                      #define CHILD_ID_LIGHT 2
                      #define CHILD_ID_VOLTAGE 3
                      #define LIGHT_SENSOR_ANALOG_PIN 0
                      #define HUMIDITY_SENSOR_DIGITAL_PIN 3
                      #define POWER_PIN 4
                      //unsigned long SLEEP_TIME = 850000; // Sleep time between reads (in milliseconds) (close to 15')
                      unsigned long SLEEP_TIME = 275000; // Sleep time between reads (in milliseconds) (close to 5')
                      
                      //Construct MySensors library
                      MySigningAtsha204Soft signer;
                      MyHwATMega328 hw;
                      MyTransportRFM69 transport;
                      MySensor gw(transport, hw, signer);
                      dht DHT;
                      MyMessage msgHum(CHILD_ID_HUM, V_HUM);
                      MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
                      MyMessage msgLum(CHILD_ID_LIGHT, V_LEVEL);
                      MyMessage msgVolt(CHILD_ID_VOLTAGE, V_VOLTAGE);
                      
                      /**************************************************************************************/
                      /* Initialization                                                                     */
                      /**************************************************************************************/
                      void setup()
                        {
                        //Get time (for setup duration)
                        #ifdef DEBUG
                          unsigned long startTime = millis();
                        #endif
                      
                        //Start MySensors
                        gw.begin();
                      
                        //Send the Sketch Version Information to the Gateway
                        gw.sendSketchInfo("GHAS sensor", "1.1.5");
                      
                        //Register all sensors to gw (they will be created as child devices)
                        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_VOLTAGE, S_MULTIMETER);
                      
                        //Delay for DHT22
                        delay(1500);
                      
                        //Print setup debug
                        #ifdef DEBUG
                          int duration = millis() - startTime;
                          Serial.print("[Setup duration: "); Serial.print(duration, DEC); Serial.println(" ms]");
                        #endif
                        }
                      
                      /**************************************************************************************/
                      /* Main loop                                                                          */
                      /**************************************************************************************/
                      void loop()
                        {
                        //Get time (for a complete loop)
                        #ifdef DEBUG
                          unsigned long startTime = millis();
                        #endif
                      
                        //Power on
                        powerOnPeripherals();
                      
                        //Get DHT22 data
                        int dht22Result = DHT.read22(HUMIDITY_SENSOR_DIGITAL_PIN);
                        switch (dht22Result)
                          {
                          case DHTLIB_OK:  
                                      //Serial.println("OK,\t");
                                      break;
                          case DHTLIB_ERROR_CHECKSUM:
                                      #ifdef DEBUG
                                        Serial.println("Checksum error,\t");
                                      #endif
                                      break;
                          case DHTLIB_ERROR_TIMEOUT:
                                      #ifdef DEBUG
                                        Serial.println("Time out error,\t");
                                      #endif
                                      break;
                          case DHTLIB_ERROR_CONNECT:
                                      #ifdef DEBUG
                                        Serial.println("Connect error,\t");
                                      #endif
                                      break;
                          case DHTLIB_ERROR_ACK_L:
                                      #ifdef DEBUG
                                        Serial.println("Ack Low error,\t");
                                      #endif
                                      break;
                          case DHTLIB_ERROR_ACK_H:
                                      #ifdef DEBUG
                                        Serial.println("Ack High error,\t");
                                      #endif
                                      break;
                          default:
                                      #ifdef DEBUG
                                        Serial.println("Unknown error,\t");
                                      #endif
                                      break;
                          }
                      
                        //Get temperature and humidity
                        float temperature = 0;
                        float humidity = 0;
                        if (dht22Result == DHTLIB_OK)
                          {
                          temperature = DHT.temperature;
                          humidity = DHT.humidity;
                          }
                      
                        //Get power before luminosity to use real voltage
                        float realVoltage = getVoltage() / 100.0;
                        int batteryPcnt = realVoltage * 100 / 3.0;
                        if (batteryPcnt > 100) {batteryPcnt = 100;}
                        int lux = computeIlluminance(realVoltage);
                      
                        //Power off
                        powerOffPeripherals();
                      
                        //Send data to gateway
                        gw.send(msgHum.set(humidity, 1));
                        gw.send(msgTemp.set(temperature, 1));
                        gw.send(msgLum.set(lux));
                        gw.send(msgVolt.set(realVoltage, 2));
                        gw.sendBatteryLevel(batteryPcnt);
                      
                        //Print debug
                        #ifdef DEBUG
                          Serial.print(temperature, 1);
                          Serial.print(" degC");
                          Serial.print("   ");
                          Serial.print(humidity, 1);
                          Serial.print(" %");
                          Serial.print("   ");
                          Serial.print(lux);
                          Serial.print(" lx");
                          Serial.print("   ");
                          Serial.print(realVoltage);
                          Serial.print(" v");
                          int duration = millis() - startTime;
                          Serial.print("   ");
                          Serial.print("["); Serial.print(duration, DEC); Serial.println(" ms]");
                          Serial.flush();
                        #endif
                      
                        //Sleep
                        gw.sleep(SLEEP_TIME);
                        }
                      
                      /**************************************************************************************/
                      /* Allows to compute illuminance (in LUX) from LIGHT_SENSOR_ANALOG_PIN.               */
                      /**************************************************************************************/
                      int computeIlluminance(float realVoltage)
                        {
                        //Get luminosity
                        int luminosity = analogRead(LIGHT_SENSOR_ANALOG_PIN);
                        //Calculating the voltage in the input of the ADC
                        double voltage = realVoltage * ((double)luminosity / 1024.0);
                        //Calculating the resistance of the photoresistor in the voltage divider
                        double resistance = (10.0 * realVoltage) / voltage - 10.0;
                        //Calculating the intensity of light in lux and return it
                        int illuminance = 255.84 * pow(resistance, -10/9);
                        return illuminance;
                        }
                      
                      /**************************************************************************************/
                      /* Allows to get the real Vcc (return value * 100).                                   */
                      /**************************************************************************************/
                      int getVoltage()
                        {
                        const long InternalReferenceVoltage = 1056L;
                        ADMUX = (0<<REFS1) | (1<<REFS0) | (0<<ADLAR) | (1<<MUX3) | (1<<MUX2) | (1<<MUX1) | (0<<MUX0);
                        delay(50);  // Let mux settle a little to get a more stable A/D conversion
                        //Start a conversion  
                        ADCSRA |= _BV( ADSC );
                        //Wait for it to complete
                        while (((ADCSRA & (1<<ADSC)) != 0));
                        //Scale the value
                        int result = (((InternalReferenceVoltage * 1023L) / ADC) + 5L) / 10L;
                        return result;
                        }
                      
                      /**************************************************************************************/
                      /* Allows to power ON peripherals.                                                    */
                      /**************************************************************************************/
                      void powerOnPeripherals()
                        {
                        //Power-up
                        pinMode (POWER_PIN, OUTPUT);
                        digitalWrite (POWER_PIN, HIGH);
                        delay(1);
                        }
                      
                      /**************************************************************************************/
                      /* Allows to power OFF peripherals.                                                   */
                      /**************************************************************************************/
                      void powerOffPeripherals()
                        {
                        //Power off
                        digitalWrite (HUMIDITY_SENSOR_DIGITAL_PIN, LOW);
                        digitalWrite (POWER_PIN, LOW);
                        pinMode (HUMIDITY_SENSOR_DIGITAL_PIN, INPUT);
                        pinMode (POWER_PIN, INPUT);
                        }
                      

                      Hope it helps !

                      David.

                      A Offline
                      A Offline
                      ar91
                      wrote on last edited by
                      #22

                      @carlierd Thank you very much. I really like your comment on the top :+1:

                      1 Reply Last reply
                      0
                      • rsachocR Offline
                        rsachocR Offline
                        rsachoc
                        wrote on last edited by
                        #23

                        Progress!

                        http://imgur.com/zRvXvrN
                        http://imgur.com/KpB7daz

                        A question though. To get to this point, I copied the pictures posted above, but where do I now add these resistors?

                        http://imgur.com/6mKJcgE

                        Also, if I want to add a 2AA battery cage, where do I connect the red and black wires to?

                        Thanks! And sorry for the newb questions!

                        m26872M 1 Reply Last reply
                        0
                        • GertSandersG Offline
                          GertSandersG Offline
                          GertSanders
                          Hardware Contributor
                          wrote on last edited by
                          #24

                          @rsachoc What you show are not resistors, they look like capacitors. 104 means 100nF (I think). Can you measure their value ?

                          1 Reply Last reply
                          0
                          • carlierdC carlierd

                            @ar91 Please find the code I used in 3 different nodes. The good thing with the playground lib is that there is error message if dialog with DHT22 failed.

                            /**
                             * The MySensors Arduino library handles the wireless radio link and protocol
                             * between your home built sensors/actuators and HA controller of choice.
                             * The sensors forms a self healing radio network with optional repeaters. Each
                             * repeater and gateway builds a routing tables in EEPROM which keeps track of the
                             * network topology allowing messages to be routed to nodes.
                             *
                             * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
                             * Copyright (C) 2013-2015 Sensnology AB
                             * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
                             *
                             * Documentation: http://www.mysensors.org
                             * Support Forum: http://forum.mysensors.org
                             *
                             * This program is free software; you can redistribute it and/or
                             * modify it under the terms of the GNU General Public License
                             * version 2 as published by the Free Software Foundation.
                             *
                             */
                            
                            /**************************************************************************************/
                            /* Temperature, humidity and luminosity measurements.                                 */
                            /*                                                                                    */
                            /* Version     : 1.1.6                                                                */
                            /* Date        : 10/01/2016                                                           */
                            /* Modified by : David Carlier                                                        */
                            /**************************************************************************************/
                            /*                                ---------------                                     */
                            /*                            RST |             |  A5                                 */
                            /*                            RX  |             |  A4                                 */
                            /*                            TX  |   ARDUINO   |  A3                                 */
                            /*     RFM69 (DIO0) --------- D2  |     UNO     |  A2                                 */
                            /*            DHT22 --------- D3  |             |  A1                                 */
                            /*            Power --------- D4  | ATMEGA 328p |  A0 --------- Light dep. resistor   */
                            /*              +3v --------- VCC |             | GND --------- GND                   */
                            /*              GND --------- GND |  8MHz int.  | REF                                 */
                            /*                            OSC |             | VCC --------- +3v                   */
                            /*                            OSC |             | D13 --------- RFM69 (SCK)           */
                            /*                            D5  |             | D12 --------- RFM69 (MISO)          */
                            /*                            D6  |             | D11 --------- RFM69 (MOSI)          */
                            /*                            D7  |             | D10 --------- RFM69 (NSS)           */
                            /*                            D8  |             |  D9                                 */
                            /*                                ---------------                                     */
                            /*                                                                                    */
                            /* Power = Vcc for LDR.                                                               */
                            /* +3v = 2*AA                                                                         */
                            /*                                                                                    */
                            /**************************************************************************************/
                            
                            #include <SPI.h>
                            #include <MySensor.h>
                            #include <dht.h>
                            #include <MyTransportRFM69.h>
                            #include <MySigningAtsha204Soft.h>
                            
                            #define CHILD_ID_HUM 0
                            #define CHILD_ID_TEMP 1
                            #define CHILD_ID_LIGHT 2
                            #define CHILD_ID_VOLTAGE 3
                            #define LIGHT_SENSOR_ANALOG_PIN 0
                            #define HUMIDITY_SENSOR_DIGITAL_PIN 3
                            #define POWER_PIN 4
                            //unsigned long SLEEP_TIME = 850000; // Sleep time between reads (in milliseconds) (close to 15')
                            unsigned long SLEEP_TIME = 275000; // Sleep time between reads (in milliseconds) (close to 5')
                            
                            //Construct MySensors library
                            MySigningAtsha204Soft signer;
                            MyHwATMega328 hw;
                            MyTransportRFM69 transport;
                            MySensor gw(transport, hw, signer);
                            dht DHT;
                            MyMessage msgHum(CHILD_ID_HUM, V_HUM);
                            MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
                            MyMessage msgLum(CHILD_ID_LIGHT, V_LEVEL);
                            MyMessage msgVolt(CHILD_ID_VOLTAGE, V_VOLTAGE);
                            
                            /**************************************************************************************/
                            /* Initialization                                                                     */
                            /**************************************************************************************/
                            void setup()
                              {
                              //Get time (for setup duration)
                              #ifdef DEBUG
                                unsigned long startTime = millis();
                              #endif
                            
                              //Start MySensors
                              gw.begin();
                            
                              //Send the Sketch Version Information to the Gateway
                              gw.sendSketchInfo("GHAS sensor", "1.1.5");
                            
                              //Register all sensors to gw (they will be created as child devices)
                              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_VOLTAGE, S_MULTIMETER);
                            
                              //Delay for DHT22
                              delay(1500);
                            
                              //Print setup debug
                              #ifdef DEBUG
                                int duration = millis() - startTime;
                                Serial.print("[Setup duration: "); Serial.print(duration, DEC); Serial.println(" ms]");
                              #endif
                              }
                            
                            /**************************************************************************************/
                            /* Main loop                                                                          */
                            /**************************************************************************************/
                            void loop()
                              {
                              //Get time (for a complete loop)
                              #ifdef DEBUG
                                unsigned long startTime = millis();
                              #endif
                            
                              //Power on
                              powerOnPeripherals();
                            
                              //Get DHT22 data
                              int dht22Result = DHT.read22(HUMIDITY_SENSOR_DIGITAL_PIN);
                              switch (dht22Result)
                                {
                                case DHTLIB_OK:  
                                            //Serial.println("OK,\t");
                                            break;
                                case DHTLIB_ERROR_CHECKSUM:
                                            #ifdef DEBUG
                                              Serial.println("Checksum error,\t");
                                            #endif
                                            break;
                                case DHTLIB_ERROR_TIMEOUT:
                                            #ifdef DEBUG
                                              Serial.println("Time out error,\t");
                                            #endif
                                            break;
                                case DHTLIB_ERROR_CONNECT:
                                            #ifdef DEBUG
                                              Serial.println("Connect error,\t");
                                            #endif
                                            break;
                                case DHTLIB_ERROR_ACK_L:
                                            #ifdef DEBUG
                                              Serial.println("Ack Low error,\t");
                                            #endif
                                            break;
                                case DHTLIB_ERROR_ACK_H:
                                            #ifdef DEBUG
                                              Serial.println("Ack High error,\t");
                                            #endif
                                            break;
                                default:
                                            #ifdef DEBUG
                                              Serial.println("Unknown error,\t");
                                            #endif
                                            break;
                                }
                            
                              //Get temperature and humidity
                              float temperature = 0;
                              float humidity = 0;
                              if (dht22Result == DHTLIB_OK)
                                {
                                temperature = DHT.temperature;
                                humidity = DHT.humidity;
                                }
                            
                              //Get power before luminosity to use real voltage
                              float realVoltage = getVoltage() / 100.0;
                              int batteryPcnt = realVoltage * 100 / 3.0;
                              if (batteryPcnt > 100) {batteryPcnt = 100;}
                              int lux = computeIlluminance(realVoltage);
                            
                              //Power off
                              powerOffPeripherals();
                            
                              //Send data to gateway
                              gw.send(msgHum.set(humidity, 1));
                              gw.send(msgTemp.set(temperature, 1));
                              gw.send(msgLum.set(lux));
                              gw.send(msgVolt.set(realVoltage, 2));
                              gw.sendBatteryLevel(batteryPcnt);
                            
                              //Print debug
                              #ifdef DEBUG
                                Serial.print(temperature, 1);
                                Serial.print(" degC");
                                Serial.print("   ");
                                Serial.print(humidity, 1);
                                Serial.print(" %");
                                Serial.print("   ");
                                Serial.print(lux);
                                Serial.print(" lx");
                                Serial.print("   ");
                                Serial.print(realVoltage);
                                Serial.print(" v");
                                int duration = millis() - startTime;
                                Serial.print("   ");
                                Serial.print("["); Serial.print(duration, DEC); Serial.println(" ms]");
                                Serial.flush();
                              #endif
                            
                              //Sleep
                              gw.sleep(SLEEP_TIME);
                              }
                            
                            /**************************************************************************************/
                            /* Allows to compute illuminance (in LUX) from LIGHT_SENSOR_ANALOG_PIN.               */
                            /**************************************************************************************/
                            int computeIlluminance(float realVoltage)
                              {
                              //Get luminosity
                              int luminosity = analogRead(LIGHT_SENSOR_ANALOG_PIN);
                              //Calculating the voltage in the input of the ADC
                              double voltage = realVoltage * ((double)luminosity / 1024.0);
                              //Calculating the resistance of the photoresistor in the voltage divider
                              double resistance = (10.0 * realVoltage) / voltage - 10.0;
                              //Calculating the intensity of light in lux and return it
                              int illuminance = 255.84 * pow(resistance, -10/9);
                              return illuminance;
                              }
                            
                            /**************************************************************************************/
                            /* Allows to get the real Vcc (return value * 100).                                   */
                            /**************************************************************************************/
                            int getVoltage()
                              {
                              const long InternalReferenceVoltage = 1056L;
                              ADMUX = (0<<REFS1) | (1<<REFS0) | (0<<ADLAR) | (1<<MUX3) | (1<<MUX2) | (1<<MUX1) | (0<<MUX0);
                              delay(50);  // Let mux settle a little to get a more stable A/D conversion
                              //Start a conversion  
                              ADCSRA |= _BV( ADSC );
                              //Wait for it to complete
                              while (((ADCSRA & (1<<ADSC)) != 0));
                              //Scale the value
                              int result = (((InternalReferenceVoltage * 1023L) / ADC) + 5L) / 10L;
                              return result;
                              }
                            
                            /**************************************************************************************/
                            /* Allows to power ON peripherals.                                                    */
                            /**************************************************************************************/
                            void powerOnPeripherals()
                              {
                              //Power-up
                              pinMode (POWER_PIN, OUTPUT);
                              digitalWrite (POWER_PIN, HIGH);
                              delay(1);
                              }
                            
                            /**************************************************************************************/
                            /* Allows to power OFF peripherals.                                                   */
                            /**************************************************************************************/
                            void powerOffPeripherals()
                              {
                              //Power off
                              digitalWrite (HUMIDITY_SENSOR_DIGITAL_PIN, LOW);
                              digitalWrite (POWER_PIN, LOW);
                              pinMode (HUMIDITY_SENSOR_DIGITAL_PIN, INPUT);
                              pinMode (POWER_PIN, INPUT);
                              }
                            

                            Hope it helps !

                            David.

                            A Offline
                            A Offline
                            ar91
                            wrote on last edited by
                            #25

                            @carlierd Are you running your Atmega at 1Mhz, Because I tried to use your sketch and i am getting "Checksum Error".

                            carlierdC 1 Reply Last reply
                            0
                            • rsachocR Offline
                              rsachocR Offline
                              rsachoc
                              wrote on last edited by rsachoc
                              #26

                              @GertSanders indeed they are capacitors (silly me) - apparently they are 0.1uf - the black one I have already soldered is 4.7uf

                              1 Reply Last reply
                              0
                              • A ar91

                                @carlierd Are you running your Atmega at 1Mhz, Because I tried to use your sketch and i am getting "Checksum Error".

                                carlierdC Offline
                                carlierdC Offline
                                carlierd
                                wrote on last edited by
                                #27

                                @ar91 said:

                                @carlierd Are you running your Atmega at 1Mhz, Because I tried to use your sketch and i am getting "Checksum Error".

                                No, I am working at 8 MHz (internal). Perhaps your DHT is out of order ? You try with another one ?

                                David.

                                1 Reply Last reply
                                0
                                • rsachocR Offline
                                  rsachocR Offline
                                  rsachoc
                                  wrote on last edited by
                                  #28

                                  Bump, can anyone advise on how I got about finding out where I need to solder the resistors on? So far I've just soldered the 4.7uf capacitor, as can be seen from the pics. But I'm struggling to find out where I need to solder the other capacitor's I have (from the BOM).

                                  m26872M 1 Reply Last reply
                                  0
                                  • rsachocR rsachoc

                                    Bump, can anyone advise on how I got about finding out where I need to solder the resistors on? So far I've just soldered the 4.7uf capacitor, as can be seen from the pics. But I'm struggling to find out where I need to solder the other capacitor's I have (from the BOM).

                                    m26872M Offline
                                    m26872M Offline
                                    m26872
                                    Hardware Contributor
                                    wrote on last edited by
                                    #29

                                    @rsachoc C1,C2,C3 are clearly marked at top layer silkscreen. You'll see them in the middle of the uC socket if you look at your 2nd picture in you last post above. C5 is visible next to the 4.7u cap, in the 3rd picture of my first post in this thread.

                                    1 Reply Last reply
                                    0
                                    • rsachocR rsachoc

                                      Progress!

                                      http://imgur.com/zRvXvrN
                                      http://imgur.com/KpB7daz

                                      A question though. To get to this point, I copied the pictures posted above, but where do I now add these resistors?

                                      http://imgur.com/6mKJcgE

                                      Also, if I want to add a 2AA battery cage, where do I connect the red and black wires to?

                                      Thanks! And sorry for the newb questions!

                                      m26872M Offline
                                      m26872M Offline
                                      m26872
                                      Hardware Contributor
                                      wrote on last edited by
                                      #30

                                      @rsachoc said:

                                      Also, if I want to add a 2AA battery cage, where do I connect the red and black wires to?

                                      First picture in first post of this thread should be enough. Connect (+) to Vcc and (-) to Gnd.

                                      1 Reply Last reply
                                      0
                                      • rsachocR Offline
                                        rsachocR Offline
                                        rsachoc
                                        wrote on last edited by
                                        #31

                                        Thanks, apologies, I really should have looked at my board, I was searching for the answer in the main slim node thread and I think i was looking at older boards and couldn't for the life of me find where C3 is!

                                        m26872M 1 Reply Last reply
                                        0
                                        • rsachocR rsachoc

                                          Thanks, apologies, I really should have looked at my board, I was searching for the answer in the main slim node thread and I think i was looking at older boards and couldn't for the life of me find where C3 is!

                                          m26872M Offline
                                          m26872M Offline
                                          m26872
                                          Hardware Contributor
                                          wrote on last edited by
                                          #32

                                          @rsachoc I'm sorry, I know I need to update those old pictures.

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


                                          25

                                          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