Skip to content

Instantly share code, notes, and snippets.

@arduinothai
Created May 18, 2018 17:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arduinothai/d638092ccdf6145cf9dd164df81f64e8 to your computer and use it in GitHub Desktop.
Save arduinothai/d638092ccdf6145cf9dd164df81f64e8 to your computer and use it in GitHub Desktop.
#include <Arduino.h>
#include <Wire.h>
#include "Adafruit_SHT31.h"
Adafruit_SHT31 sht31 = Adafruit_SHT31();
void setup() {
Serial.begin(9600);
while (!Serial)
delay(10); // will pause Zero, Leonardo, etc until serial console opens
Serial.println("SHT31 test");
if (! sht31.begin(0x44)) { // Set to 0x45 for alternate i2c addr
Serial.println("Couldn't find SHT31");
while (1) delay(1);
}
}
void loop() {
float t = sht31.readTemperature();
float h = sht31.readHumidity();
if (! isnan(t)) { // check if 'is not a number'
Serial.print("Temp *C = "); Serial.println(t);
} else {
Serial.println("Failed to read temperature");
}
if (! isnan(h)) { // check if 'is not a number'
Serial.print("Hum. % = "); Serial.println(h);
} else {
Serial.println("Failed to read humidity");
}
Serial.println();
delay(1000);
}
// ที่มา https://github.com/adafruit/Adafruit_SHT31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment