Home > Projects > Interfacing(USB – RS232 – I2c -ISP) Projects > HSM-20G Interface with Arduino Uno

HSM-20G Interface with Arduino Uno

Summary of HSM-20G Interface with Arduino Uno


The HSM-20G is an analog sensor used to measure relative humidity and temperature, suitable for applications like air conditioners and weather monitoring systems. The project involves interfacing this sensor with an Arduino Uno using specific resistors and a capacitor. The system reads voltage from the sensor's output pins, converts them to digital values, and applies mathematical equations derived from datasheet graphs to calculate precise humidity and temperature readings displayed via the serial monitor.

Parts used in the HSM-20G Interface Project:

  • Arduino uno
  • HSM-20G sensor
  • Resistors 100K and 10K
  • Capacitor 47uF/10V

The HSM-20G is an analog humidity and temperature sensor that outputs analog voltage respects to relative humidity and temperature. However from this sensor relative humidity is found along with temperature. Relative humidity is the percentage of moistures of airs for a particular temperature [1].
Feature:
1. Storage range: -20°C to 70°C
2. Operating range: 0°C to 50°CHSM-20G Interface with Arduino Uno

Application:

HSM-20g is considered as the most operating sensor compared to other similar products. This sensor is used in BTS (base transmission station) for weather forecasting. Also it is used in:
1. Air-conditioner
2. Automatic climate control system
3. Humidity data logger
4. Weather monitoring system

Parts Needed:

1. Arduino uno (1pc)
2. HSM-20G (1pc)
3. Resistors- 100K, 10K
4. Capacitor- 47uF/10V

Wiring:

Usually for arduino interfacing sensor data pins are directly feed to arduino I/O pin. However for this HSM-20G sensor a particular circuit connection needed to be followed for getting desired result.
1. Connects all resistors and capacitor

. Then Connect humidity output with arduino analog pin A0 and temperature outpin pin with arduino analog pin A1. In this article, I used A0 and A1 pins, but user can select any of analog pins for communication.
3. If circuit connection is set accurately then the hardware is ready, however we need to do arduino coding.

Code:

Arduino Coding is done in Arduino IDE.


void setup()
{
Serial.begin(9600); // Serial monitor baud rate
Serial.println("setup");
}
void loop()
{
int humValue = analogRead(A0); // read humidity value from A0 pin
// eqn
int voltage = ((humValue*5.0)/1023.0); // convert analog value to voltage
//equation for humidity
int humidity= (3.71*pow(voltage,3))-(20.65*pow(voltage,2))+(64.81*voltage)-27.44;

Serial.print("Humidity: "+humidity);
Serial.println(" %");
delay(1000);
int tempValue = analogRead(A1); // read temperature value from A1 pin
int voltage_temp = ((tempValue*5.0)/1023.0); // convert analog value to voltage
//equation for temperature
int temperature=(5.26*pow(voltage_temp,3))-(27.34*pow(voltage_temp,2))+(68.87*voltage_temp)-17.81;
Serial.print("Temperature: "+temperature);
Serial.println(" C");
}

HSM-20G Interface with Arduino Uno Schematic

Discussion:

The Arduino board has an analog-to-digital converter from A0-A5 pin that reads this changing voltage and converts it to a number between 0 and 1023. So from A0 and A1 pin at first the analog values are converted to voltage. Since the sensor uses a specific connection for wiring, for getting desired value for humidity and temperature two equations are derived from the graphs given in datasheet.
From the given data table for output voltage respect to relative humidity in datasheet, a graph is plotted in Microsoft excel and an equation was found:
RH% = 3.71????3?20.65????2+64.81?????27.44
Also in the datasheet another table is given for resistance respect to temperature. So another graph is plotted and an equation is found
????=5.26????3?27.34????2+68.87?????17.81

 

For more detail: HSM-20G Interface with Arduino Uno

Quick Solutions to Questions related to HSM-20G Interface Project:

  • What is the primary function of the HSM-20G sensor?
    The HSM-20G is an analog humidity and temperature sensor that outputs analog voltage corresponding to relative humidity and temperature.
  • Can I use any analog pin on the Arduino for this sensor?
    Yes, while the article uses A0 and A1, users can select any analog pins for communication if the circuit connection is accurate.
  • How does the Arduino board process the sensor data?
    The Arduino board uses its analog-to-digital converter on pins A0-A5 to read changing voltage and convert it to a number between 0 and 1023.
  • What equations are used to calculate humidity and temperature?
    Humidity is calculated using RH% = 3.71voltage^3 - 20.65voltage^2 + 64.81voltage - 27.44, and temperature uses temp = 5.26voltage^3 - 27.34voltage^2 + 68.87voltage - 17.81.
  • Where were these calculation equations derived from?
    The equations were found by plotting graphs in Microsoft Excel based on data tables provided in the sensor's datasheet.
  • What are some common applications for the HSM-20G sensor?
    Common applications include BTS weather forecasting, air-conditioners, automatic climate control systems, humidity data loggers, and weather monitoring systems.
  • What is the operating temperature range of the HSM-20G sensor?
    The operating range for the HSM-20G sensor is 0°C to 50°C.
  • How is the raw analog value converted to voltage in the code?
    The code converts the analog value to voltage by multiplying the reading by 5.0 and dividing by 1023.0.

About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter
Scroll to Top