Another wireless temperature and humidity sensor. Z-Wave Z-Uno + Sensirion SHT20 board

As it should be for a decent gig, I have a weather station, which I collected from DHT22, Raspberry Pi and Nokia screen, this is a continuous power solution that transmits data via Ethernet.



But now I needed a mobile weather station on the balcony, wireless and battery powered.

I used the Z-Uno Z-Wave motherboard as a radio module, and decided to try the Sensirion SHT20 I2C-powered as the temperature and humidity sensor.







Materials and prices:

No Material Score Price
one Z-Wave Z-Uno board 5smart.ru 3500 r
2 Sensirion SHT20 sensor voltmaster.ru 72 r
3 Gainta G517B case voltmaster.ru 160 r
four Battery compartment BH421 2xAAA voltmaster.ru 14 r




Z-Uno is constantly updated, adding support for new peripherals and libraries. At the moment, the current firmware version 2.0.9 and it has support for the following devices:











Sensor Sensirion SHT20, working on I2C bus in the list of supported was not there, so I had to write my implementation for Z-Uno. The sketch syntax for Z-Uno is most similar to Arduino, the whole sketch fits in 35 lines:







Sketch for Z-Uno to work with the sensor temperature and humidity Sensirion SHT20
#include <Wire.h> #include "SHT2x.h" int16_t temperature; uint8_t humidity; ZUNO_SETUP_SLEEPING_MODE(ZUNO_SLEEPING_MODE_SLEEPING); #define ZUNO_CHANNEL_TEMPERATURE 1 #define ZUNO_CHANNEL_HUMIDITY 2 ZUNO_SETUP_CHANNELS( ZUNO_SENSOR_MULTILEVEL_TEMPERATURE(getterTemp), ZUNO_SENSOR_MULTILEVEL_HUMIDITY(getterHumid) ); void setup() { Wire.begin(); } void loop() { temperature = SHT2x.GetTemperature(); zunoSendReport(ZUNO_CHANNEL_TEMPERATURE); humidity = SHT2x.GetHumidity(); zunoSendReport(ZUNO_CHANNEL_HUMIDITY); zunoSendDeviceToSleep(); } byte getterTemp(void) { return temperature; } byte getterHumid(void) { return humidity; }
      
      







SHT2x.cpp modified for Z-Uno
 /* SHT2x - A Humidity Library for Arduino. Supported Sensor modules: SHT21-Breakout Module - http://www.moderndevice.com/products/sht21-humidity-sensor SHT2x-Breakout Module - http://www.misenso.com/products/001 Created by Christopher Ladden at Modern Device on December 2009. Modified by Paul Badger March 2010 Modified by www.misenso.com on October 2011: - code optimisation - compatibility with Arduino 1.0 This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ //#include <inttypes.h> #include <Wire.h> #include "Arduino.h" #include "SHT2x.h" /****************************************************************************** * Global Functions ******************************************************************************/ /********************************************************** * GetHumidity * Gets the current humidity from the sensor. * * @return float - The relative humidity in %RH **********************************************************/ float SHT2xClass::GetHumidity(void) { return (-6.0 + 125.0 / 65536.0 * (float)(readSensor(eRHumidityNoHoldCmd))); } /********************************************************** * GetTemperature * Gets the current temperature from the sensor. * * @return float - The temperature in Deg C **********************************************************/ float SHT2xClass::GetTemperature(void) { return (-46.85 + 175.72 / 65536.0 * (float)(readSensor(eTempNoHoldCmd))); } /****************************************************************************** * Private Functions ******************************************************************************/ uint16_t SHT2xClass::readSensor(uint8_t command) { uint16_t result = 0 ; uint8_t data[2]; // Sending request to sensor Wire.beginTransmission(eSHT2xAddress); // We have to read some registers from sensor Wire.write(command); // Command Wire.endTransmission(); delay(100); Wire.requestFrom(eSHT2xAddress, 3); //Get 3 bytes byte i = 0; while(Wire.available()) { data[i++] = Wire.read(); } result = data[0] << 8; result += data[1]; result &= ~0x0003; // clear two low bits (status bits) return result; } SHT2xClass SHT2x;
      
      







SHT2x.h
 /* SHT2x - A Humidity Library for Arduino. Supported Sensor modules: SHT21-Breakout Module - http://www.moderndevice.com/products/sht21-humidity-sensor SHT2x-Breakout Module - http://www.misenso.com/products/001 Created by Christopher Ladden at Modern Device on December 2009. Modified by www.misenso.com on October 2011: - code optimisation - compatibility with Arduino 1.0 This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef SHT2X_H #define SHT2X_H //#include <inttypes.h> typedef enum { eSHT2xAddress = 0x40, } HUM_SENSOR_T; typedef enum { eTempHoldCmd = 0xE3, eRHumidityHoldCmd = 0xE5, eTempNoHoldCmd = 0xF3, eRHumidityNoHoldCmd = 0xF5, } HUM_MEASUREMENT_CMD_T; class SHT2xClass { private: uint16_t readSensor(uint8_t command); uint8_t _data; public: SHT2xClass(){}; float GetHumidity(void); float GetTemperature(void); }; extern SHT2xClass SHT2x; #endif
      
      







Of the special things, in the sketch there is only a line that translates Z-Uno into sleep mode:



 ZUNO_SETUP_SLEEPING_MODE(ZUNO_SLEEPING_MODE_SLEEPING);
      
      





And setting which channel to send temperature to, and to which humidity:



 ZUNO_SETUP_CHANNELS( ZUNO_SENSOR_MULTILEVEL_TEMPERATURE(getterTemp), ZUNO_SENSOR_MULTILEVEL_HUMIDITY(getterHumid) );
      
      





Otherwise, the usual Arduino code.



Sensirion SHT20 works on I2C and is connected by 2 wires. By default, pins 9 and 10 are defined for I2C in the Wire.h library.



image






Information from the sensor can be viewed on the phone and it is used in automation, to control the humidifier and air conditioning.









Data is updated every 12 minutes; in this mode, the sensor should work more than 2 years from one set of batteries.







Gain's body G517B 90 x 60 x 20 cm was specially chosen with a place for the battery compartment, everything fits perfectly.



The development of a Z-Wave temperature and humidity sensor took about 2 hours and 3746 r. You can also add an E-Ink screen and hang it on the wall!



All Articles