The SHTxy series of digital humidity and temperature sensors from Sensirion are high quality and available for Arduino as integrated breakout boards from various producers.
Wiring
SHT1x modules have four wires: power or VCC (red), ground or GND (green), data or DI (blue) and SCK or clock (yellow). You need to put a 1 kOhm pull-up resistor between power and data (red and blue).
Sketch
The easiest way to get sketch your SHT1x sensor is by using the SHT1x.h library from GitHub. Download the GitHub fodler with library as a zip file. Unzip and rename the exploded directory to SHT1x (it probably arrived as SHT1x-master), and move it to the documents/arduino/libraries directory (if you installed Arduino using default setting this is under your personal folder “~”). Move the whole folder.
#include <SHT1x.h>
// Specify data and clock connections and instantiate SHT1x object
#define dataPin 10
#define clockPin 11
SHT1x sht1x(dataPin, clockPin);
void setup()
{
Serial.begin(9600); // Open serial connection to report values to host
Serial.println("Starting up");
}
void loop()
{
float temp_c;
float temp_f;
float humidity;
// Read values from the sensor
temp_c = sht1x.readTemperatureC();
temp_f = sht1x.readTemperatureF();
humidity = sht1x.readHumidity();
// Print the values to the serial port
Serial.print("Temperature: ");
Serial.print(temp_c, DEC);
Serial.print("C / ");
Serial.print(temp_f, DEC);
Serial.print("F. Humidity: ");
Serial.print(humidity);
Serial.println("%");
delay(2000);
}
Project with pin power
An alternative wiring is to put the power supply on a digital pin, allowing turning the power to the sensor on/off.
#include <SHT1x.h>
// Specify data and clock connections and instantiate SHT1x object
int probePowerPin = 7;
#define dataPin 2
#define clockPin 8
SHT1x sht1x(dataPin, clockPin);
void setup()
{
Serial.begin(9600); // Open serial connection to report values to host
Serial.print("Starting up sht mositure+temperature ");
pinMode (probePowerPin, OUTPUT); // define the digital output
}
void loop()
{
float temp_c;
float temp_f;
float humidity;
digitalWrite (probePowerPin, HIGH); // Turn sensor On
// Read values from the sensor
temp_c = sht1x.readTemperatureC();
temp_f = sht1x.readTemperatureF();
humidity = sht1x.readHumidity();
// Print the values to the serial port
Serial.print("Temperature: ");
Serial.print(temp_c, DEC);
Serial.print("C / ");
Serial.print(temp_f, DEC);
Serial.print("F. Humidity: ");
Serial.print(humidity);
Serial.println("%");
delay(2000);
}