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. Trying to build a wireless DHT22 sensor that logs data to PLX-DAQ

Trying to build a wireless DHT22 sensor that logs data to PLX-DAQ

Scheduled Pinned Locked Moved My Project
1 Posts 1 Posters 2.5k Views 1 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.
  • J Offline
    J Offline
    jpaulwhite
    wrote on last edited by jpaulwhite
    #1

    I have a DHT22 Temperature/Humidity sensor. I can connect it wirelessly (And give it power), and read Temp and Humidity off it if I load some code from MySensors.org and use their version of the DHT library.

    If I flash my sensor with some code from Adafruit and use their DHT library, I can connect the sensor via usb, run PLC-DAQ on the computer it is connected to, and the Temp and Humidity values are passed into an Excel spreadheet.

    I am looking for some code to allow my sensor to connect wirelessly, then pass the data to PLC-DAQ.

    I got the code below to compile by copying and pasting the relevant parts of the Setup and Void functions (Again, terminology may be off) from the Mysensors.org and Adafruit code, then renaming all instances of the Adafruit DHT to DHTP. If you look in the code below, all the lines that end with // are the ones I edited. Except the ones where it's obviously a comment from the developer.

    I also had to rename one of the classes (Adafruit version of DHT.h, may be using the wrong terminology) to DHTP.h and DHTP.cpp.

    I have included the code I reworked below. Here is a link to the working Adafruit code http://108.51.175.78:8069/shelli-rae/sensor_plx_daq.ino , and here is a link to the working Mysensors.org code http://108.51.175.78:8069/shelli-rae/sensor_humidity_vera.ino

    If I flash my Arduino with either one and use their version of the DHT.h library either respective function works fine.

    Thank you for any help/suggestions.

    #include <Sleep_n0m1.h>
    #include <SPI.h>
    #include <EEPROM.h>
    #include <RF24.h>
    #include <Sensor.h>
    #include <DHT.h>
    #include <DHTP.h>//

    #define CHILD_ID_HUM 0
    #define CHILD_ID_TEMP 1
    #define HUMIDITY_SENSOR_DIGITAL_PIN 3
    unsigned long SLEEP_TIME = 30; // Sleep time between reads (in seconds)

    #define DHTPIN 3//
    #define DHTTYPE DHT22//

    Sensor gw;
    DHT dht;
    Sleep sleep;
    float lastTemp;
    float lastHum;
    boolean metric = true;

    DHTP dhtp(DHTPIN, DHTTYPE);//

    void setup()
    {
    gw.begin();
    dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN);

    // Send the Sketch Version Information to the Gateway
    gw.sendSketchInfo("Humidity", "1.0");

    // Register all sensors to gw (they will be created as child devices)
    gw.sendSensorPresentation(CHILD_ID_HUM, S_HUM);
    gw.sendSensorPresentation(CHILD_ID_TEMP, S_TEMP);

    metric = gw.isMetricSystem();{

    Serial.begin(38400);//
    Serial.println("LABEL,Time,Temperature (F), Humidity (%)"); //

    dhtp.begin();//
    }
    }

    void loop()
    {
    delay(dht.getMinimumSamplingPeriod());

    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.sendVariable(CHILD_ID_TEMP, V_TEMP, 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.sendVariable(CHILD_ID_HUM, V_HUM, humidity, 1);
    Serial.print("H: ");
    Serial.println(humidity);
    }

    {//
    // Reading temperature or humidity takes about 250 milliseconds!
    // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
    float h = dhtp.readHumidity();//
    float t = dhtp.readTemperature();//
    t = ((t*1.8)+32);//Converted from Celsius to Farenheit
    delay(60000);//

    // check if returns are valid, if they are NaN (not a number) then something went wrong!
    if (isnan(t) || isnan(h)) {//
    Serial.println("Failed to read from DHT");//
    } else {
    Serial.print("DATA,TIME,"); Serial.print(t); Serial.print(","); Serial.println(h);
    }//
    }//

    // Power down the radio. Note that the radio will get powered back up
    // on the next write() call.
    delay(1000); //delay to allow serial to fully print before sleep
    gw.powerDown();
    sleep.pwrDownMode(); //set sleep mode
    sleep.sleepDelay(SLEEP_TIME * 1000); //sleep for: sleepTime
    }

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


    22

    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