Created
May 18, 2018 17:47
-
-
Save arduinothai/d638092ccdf6145cf9dd164df81f64e8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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