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. Hardware
  3. Mysensort mit DHT12 (i2C)

Mysensort mit DHT12 (i2C)

Scheduled Pinned Locked Moved Hardware
3 Posts 2 Posters 2.4k Views 2 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.
  • michlb1982M Offline
    michlb1982M Offline
    michlb1982
    wrote on last edited by
    #1

    Hello

    Does anyone built up an Mysenors Humidity Node with an DHT12 it is an I2C sensor...

    but I2C is needet for the NRF24+ or?

    Thanks

    mfalkviddM 1 Reply Last reply
    0
    • michlb1982M michlb1982

      Hello

      Does anyone built up an Mysenors Humidity Node with an DHT12 it is an I2C sensor...

      but I2C is needet for the NRF24+ or?

      Thanks

      mfalkviddM Offline
      mfalkviddM Offline
      mfalkvidd
      Mod
      wrote on last edited by
      #2

      @michlb1982 the nrf radio uses SPI, not I2C.

      I haven't seen anyone using the dht12, but there are examples that use other i2c sensors.
      https://www.mysensors.org/build/pressure
      https://www.mysensors.org/build/light-bh1750
      https://www.mysensors.org/build/rfid

      1 Reply Last reply
      0
      • michlb1982M Offline
        michlb1982M Offline
        michlb1982
        wrote on last edited by michlb1982
        #3

        Well i did it... i've got a working MYSENSOR with DHT12...
        here the Code ... its not nice but it works...

        // Enable debug prints
        #define MY_DEBUG
        
        // Define Node ID
        #define MY_NODE_ID 128
        //#define MY_REPEATER_FEATURE
        
        
        // Enable and select radio type attached 
        #define MY_RADIO_NRF24
        
        #include <SPI.h>
        #include <MySensors.h>  
        #include <DHT12.h>
        #include <Wire.h>
        DHT12 dht12;
        
        #define SENSOR_TEMP_OFFSET 0
        
        // Sleep time between sensor updates (in milliseconds)
        // Must be >1000ms for DHT22 and >2000ms for DHT11
        static const uint64_t UPDATE_INTERVAL = 30000;
        
        static const uint8_t FORCE_UPDATE_N_READS = 10;
        
        #define CHILD_ID_HUM 0
        #define CHILD_ID_TEMP 1
        
        float lastTemp;
        float lastHum;
        uint8_t nNoUpdatesTemp;
        uint8_t nNoUpdatesHum;
        bool metric = true;
        
        MyMessage msgHum(CHILD_ID_HUM, V_HUM);
        MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
        
        
        
        void presentation()  
        { 
          // Send the sketch version information to the gateway
          sendSketchInfo("DHT12", "1.1");
        
          // Register all sensors to gw (they will be created as child devices)
          present(CHILD_ID_HUM, S_HUM);
          present(CHILD_ID_TEMP, S_TEMP);
        
          //metric = getControllerConfig().isMetric;
        }
        
        
        void setup()
        {
          Wire.begin();
        }
        
        
        void loop()      
        {  
          // Force reading sensor, so it works also after sleep()
          //dht12.readSensor(true);
        
          // Get temperature from DHT library
          float temperature = dht12.readTemperature();
          if (isnan(temperature)) {
            Serial.println("Failed reading temperature from DHT!");
          } else if (temperature != lastTemp || nNoUpdatesTemp == FORCE_UPDATE_N_READS) {
            // Only send temperature if it changed since the last measurement or if we didn't send an update for n times
            lastTemp = temperature;
        
            // apply the offset before converting to something different than Celsius degrees
            temperature += SENSOR_TEMP_OFFSET;
        
            if (!metric) {
              temperature = dht12.readTemperature();
            }
            // Reset no updates counter
            nNoUpdatesTemp = 0;
            send(msgTemp.set(temperature, 1));
        
            #ifdef MY_DEBUG
            Serial.print("T: ");
            Serial.println(temperature);
            #endif
          } else {
            // Increase no update counter if the temperature stayed the same
            nNoUpdatesTemp++;
          }
        
          // Get humidity from DHT library
          float humidity = dht12.readHumidity();
          if (isnan(humidity)) {
            Serial.println("Failed reading humidity from DHT");
          } else if (humidity != lastHum || nNoUpdatesHum == FORCE_UPDATE_N_READS) {
            // Only send humidity if it changed since the last measurement or if we didn't send an update for n times
            lastHum = humidity;
            // Reset no updates counter
            nNoUpdatesHum = 0;
            send(msgHum.set(humidity, 1));
        
            #ifdef MY_DEBUG
            Serial.print("H: ");
            Serial.println(humidity);
            #endif
          } else {
            // Increase no update counter if the humidity stayed the same
            nNoUpdatesHum++;
          }
        
          // Sleep for a while to save energy
          sleep(UPDATE_INTERVAL); 
          //wait(UPDATE_INTERVAL); //for repeaters
        }
        

        i Used this library: https://github.com/Bobadas/DHT12_library_Arduino/blob/master/README.md

        here the datasheet of the dht12: http://www.robototehnika.ru/file/DHT12.pdf

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


        26

        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