Intel® Makers
Intel® Edison, Intel® Joule™, Intel® Curie™, Intel® Galileo
Welcome - This is a Peer-to-Peer Forum only. Intel has discontinued these products but you may find support from other customers on this Forum
9881 Discussions

Digital Temperature and Humidity Sensor - HTU21D



I've tried the new humidity/temperature sensor HTU21D from isweek and really like this little breakout board.


It is a much better replacement for the slow und sometimes unreliable DHTxx sensors. Because of the I2C interface wiring and programming is very easy.

Here is my adapted version of the humidity sketch (you need the HTU21D library from isweek):

# include  

# include


# include


# include



# define CHILD_ID_HUM 0


# define CHILD_ID_TEMP 1


unsigned long SLEEP_TIME = 60000; // Sleep time between reads (in milliseconds)



MySensor gw;



//Create an instance of the object


HTU21D myHumidity;



boolean metric = true;


MyMessage msgHum(CHILD_ID_HUM, V_HUM);


MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);



void setup()







// Send the Sketch Version Information to the Gateway


gw.sendSketchInfo("Humidity", "2.0");



// 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);



metric = gw.getConfig().isMetric;






void loop()




float temperature = myHumidity.readTemperature();


if (!metric) {


temperature = (temperature * 1.8) + 32.0;




gw.send(msgTemp.set(temperature, 1));



float humidity = myHumidity.readHumidity();


gw.send(msgHum.set(humidity, 1));



gw.sleep(SLEEP_TIME); //sleep a bit


0 Replies