This is the new version of my old website. You can find the old website here: old.dl2sba.com. If you miss any information or you find bugs, please let me know by E-Mail

I've created a small I2C library to access the HYGROSENS HY321 module on the ARDUINO. I bought my sensor from REICHELT for about 12€.

You can find a usage sample here.

The library can be downloaded from here. Copy the library (*.c, *.cpp, *.txt) to your local libraries (taken from arduino.cc):

Open your Arduino sketchbook folder. If there is already a folder there called libraries, place the library folder in there. If not, create a folder called libraries in the sketchbook folder, and drop the library folder in there. Then re-start the Arduino programming environment, and you should see your new library in the Sketch > Import Library menu.

#ifndef _HYT321_H
#define _HYT321_H


class HYT321 {
   private:
      int rawTemp;
      int rawHum;
      int address;


   public:
      HYT321(int adr);
      uint8_t begin( void );
      uint8_t read( void );

      int getRawHumidity( void );
      int getRawTemperature( void ) ;
      double getHumidity( void ) ;
      double getTemperature( void );
};


extern HYT321 HYT;

#endif

You can access it via the class HYT321. The code sequence is pretty simple:

#include <Wire.h>
#include <HYT321.h>


HYT321 HYT = HYT321(0x28);

void setup() {
   // initialize I2C protocoll
   Wire.begin();


   // initialize the sensor
   HYT.begin();

}

void loop() {


   HYT.read();
   double h = HYT.getHumidity();
  
double t = HYT.getTemperature();

   for (;;);

}

(c) Dietmar Krause, DL2SBA 2026 Impressum Datenschutz
Cookies user preferences
We use cookies to ensure you to get the best experience on our website. If you decline the use of cookies, this website may not function as expected.
Accept all
Decline all
Marketing
Set of techniques which have for object the commercial strategy and in particular the market study.
Quantcast
Save