Welcome to the GXHTC3 repository! This library allows you to easily interface with the GXHTC3 temperature and humidity sensor using I2C. Whether you are building a weather station, a smart home device, or any other project that requires accurate environmental data, this library simplifies the process of sensor communication and data management.
- I2C Communication: Communicate with the GXHTC3 sensor using the I2C protocol.
- Easy-to-Use Interface: Simple functions for reading temperature and humidity data.
- Power Management: Efficient power management to extend battery life in portable applications.
- Arduino Compatibility: Works seamlessly with Arduino boards.
To install the GXHTC3 library, follow these steps:
-
Download the Library: Visit the Releases section to download the latest version of the library.
-
Add to Arduino IDE:
- Open the Arduino IDE.
- Go to
Sketch
>Include Library
>Add .ZIP Library...
. - Select the downloaded ZIP file.
-
Verify Installation: After installation, you can check if the library is included by navigating to
Sketch
>Include Library
. You should seeGXHTC3
in the list.
To use the GXHTC3 library in your Arduino project, include it at the top of your sketch:
#include <GXHTC3.h>
Create an instance of the GXHTC3 class and initialize it in the setup()
function:
GXHTC3 sensor;
void setup() {
Serial.begin(9600);
if (!sensor.begin()) {
Serial.println("Sensor not found!");
while (1);
}
Serial.println("Sensor initialized successfully.");
}
You can read temperature and humidity data using the following functions:
void loop() {
float temperature = sensor.readTemperature();
float humidity = sensor.readHumidity();
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" °C");
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.println(" %");
delay(2000); // Wait for 2 seconds before the next reading
}
To help you get started, we have included example sketches in the examples
folder. Here are a couple of highlights:
This example shows how to read and display temperature and humidity data:
#include <GXHTC3.h>
GXHTC3 sensor;
void setup() {
Serial.begin(9600);
if (!sensor.begin()) {
Serial.println("Sensor not found!");
while (1);
}
}
void loop() {
float temperature = sensor.readTemperature();
float humidity = sensor.readHumidity();
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" °C");
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.println(" %");
delay(2000);
}
In this example, we will log the data to an SD card. Ensure you have an SD card module connected to your Arduino.
#include <GXHTC3.h>
#include <SD.h>
GXHTC3 sensor;
File dataFile;
void setup() {
Serial.begin(9600);
if (!sensor.begin()) {
Serial.println("Sensor not found!");
while (1);
}
if (!SD.begin()) {
Serial.println("SD card initialization failed!");
return;
}
Serial.println("SD card initialized.");
}
void loop() {
float temperature = sensor.readTemperature();
float humidity = sensor.readHumidity();
dataFile = SD.open("data.txt", FILE_WRITE);
if (dataFile) {
dataFile.print("Temperature: ");
dataFile.print(temperature);
dataFile.print(" °C, Humidity: ");
dataFile.print(humidity);
dataFile.println(" %");
dataFile.close();
} else {
Serial.println("Error opening file");
}
delay(2000);
}
We welcome contributions to improve the GXHTC3 library. If you have suggestions, bug reports, or feature requests, please open an issue or submit a pull request.
- Fork the repository.
- Create a new branch for your feature or bug fix.
- Make your changes and commit them.
- Push your branch to your fork.
- Open a pull request.
This project is licensed under the MIT License. See the LICENSE file for details.
For support, please check the Releases section for updates and documentation. You can also open an issue in the repository if you encounter any problems.
Thank you for using the GXHTC3 library! We hope it helps you in your projects. For more information, feel free to explore the code and examples provided in this repository. Happy coding!