Skip to content

Instantly share code, notes, and snippets.

@cynthiahenaff
Last active March 1, 2020 20:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cynthiahenaff/f9d41cf712b401ae6adc471239d4c88f to your computer and use it in GitHub Desktop.
Save cynthiahenaff/f9d41cf712b401ae6adc471239d4c88f to your computer and use it in GitHub Desktop.
Simple example for the SHT30
#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