Use Arduino to detect temperature and humidity in the environment

Use Arduino to detect the temperature and humidity in the environment The temperature and humidity sensor
used is the SHT1X temperature and humidity sensor.

Its technical specifications are as follows:
fully calibrated, digital output;
simple interface (2-wire), fast response;
ultra-low power consumption, automatic sleep;
excellent long-term stability;
ultra-small size (surface mount);
humidity range 0— 100%RH, temperature range -40°C—128.8°C Humidity
measurement accuracy ±4.5%RH, temperature measurement accuracy ±0.5°C (25°C)
Module size: 32X17mm


sensor adopts 2-wire interface, digital output, so it needs to occupy two digits Port
Take an application example: (In the example, digital port 9 of Arduino (connected to SCK of SHT1x temperature and humidity sensor) and
digital port 10 (connected to DATA of SHT1x temperature and humidity sensor) are occupied.

code show as below:

#include <SHT1x.h>
#define dataPin 10
#define clockPin 9
//Define the object sht1x of the SHT1x class
SHT1x sht1x(dataPin, clockPin);
void setup()
{
Serial.begin(9600); // baud rate 9600 bps
}
void loop()
{
float temp_c; //Define the temperature value variable
float humidity; //Define the humidity value variable
// read temperature and humidity values
temp_c = sht1x.readTemperatureC();
humidity = sht1x.readHumidity();
//output temperature value through serial port
Serial.print("Temperature: ");
Serial.print(temp_c);
//Output the humidity value through the serial port
Serial.print(" Humidity: ");
Serial.print(humidity);
Serial.println("%");
//Sampling every 2 seconds
delay(2000);
}


Need to define a SHT1x object sht1x.
To get the temperature value use the function sht1x.readTemperatureC()
Get the humidity value using the function sht1x.readHumidity()
In addition, the Chinese temperature can also be obtained directly, using the function sht1x.readTemperatureF()


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324652676&siteId=291194637