DHT22 sensor with decimals

Discussion about Z-Uno product. Visit http://z-uno.z-wave.me for more details.
Post Reply
veuchez
Posts: 5
Joined: 25 Jan 2017 17:11

DHT22 sensor with decimals

Post by veuchez »

Hi everyone,
i can't figure out how to get decimals on the temperature and humidity readings from the DHT22 sensor.
Can anyone help me please?
Thank you!

veuchez
Posts: 5
Joined: 25 Jan 2017 17:11

Re: DHT22 sensor with decimals

Post by veuchez »

I think I have solved this, now I do some tests.

Code: Select all

// add library
#include "ZUNO_DHT.h"
// pin connection
#define DHTPIN 9  // first sensor

DHT dht(DHTPIN, DHT22);  

int temperatura; // here we will store the temperature
int umidita; // here we will store the humidity

// set up channel
ZUNO_SETUP_CHANNELS(
   ZUNO_SENSOR_MULTILEVEL(ZUNO_SENSOR_MULTILEVEL_TYPE_TEMPERATURE, 
                          SENSOR_MULTILEVEL_SCALE_CELSIUS, 
                          SENSOR_MULTILEVEL_SIZE_TWO_BYTES, 
                          SENSOR_MULTILEVEL_PRECISION_TWO_DECIMALS,
                          getterTemp),
                          
   ZUNO_SENSOR_MULTILEVEL(ZUNO_SENSOR_MULTILEVEL_TYPE_RELATIVE_HUMIDITY, 
                          SENSOR_MULTILEVEL_SCALE_PERCENTAGE_VALUE, 
                          SENSOR_MULTILEVEL_SIZE_TWO_BYTES, 
                          SENSOR_MULTILEVEL_PRECISION_TWO_DECIMALS,
                          getterUmid)                          
);

void setup() {
    Serial.begin();
    Serial.println("start");
}

void loop() {
    // obtaining readings from the sensor DHT22
    float temp = dht.readTemperature();
    // make scaled word value for report
    temperatura=int(temp*100);

    float umid = dht.readHumidity();
    // make scaled word value for report
    umidita=int(umid*100);
    
    // send data to channel
    zunoSendReport(1); 
    zunoSendReport(2);   
       
    // send every 20 second
    delay(20000);
}

word getterTemp() {
    return temperatura;
}

word getterUmid() {
    return umidita;
}

Post Reply