Last active
March 1, 2020 20:20
-
-
Save cynthiahenaff/f9d41cf712b401ae6adc471239d4c88f to your computer and use it in GitHub Desktop.
Simple example for the SHT30
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 "Adafruit_SHT31.h" | |
Adafruit_SHT31 sht30 = Adafruit_SHT31(); | |
void setup() { | |
Serial.begin(9600); | |
while (!Serial) | |
delay(10); // will pause until serial console opens | |
Serial.println("SHT30 test"); | |
if (! sht30.begin(0x45)) { | |
Serial.println("Couldn't find SHT30"); | |
while (1) delay(1); | |
} | |
} | |
void loop() { | |
float t = sht30.readTemperature(); | |
float h = sht30.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(4000); // wait 4 seconds before coming back into the loop | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment