Добавила все файлы
This commit is contained in:
1 parent
1904868800
commit
f29fdd4ac4
44 files changed
+3632
-1
No files matched your search
@@ -0,0 +1,72 @@
|
||||
/***************************************************
|
||||
This is an example for the SHT31-D Humidity & Temp Sensor
|
||||
|
||||
Designed specifically to work with the SHT31-D sensor from Adafruit
|
||||
----> https://www.adafruit.com/products/2857
|
||||
|
||||
These sensors use I2C to communicate, 2 pins are required to
|
||||
interface
|
||||
****************************************************/
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <Wire.h>
|
||||
#include "Adafruit_SHT31.h"
|
||||
|
||||
bool enableHeater = false;
|
||||
uint8_t loopCnt = 0;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
Serial.print("Heater Enabled State: ");
|
||||
if (sht31.isHeaterEnabled())
|
||||
Serial.println("ENABLED");
|
||||
else
|
||||
Serial.println("DISABLED");
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
float t = sht31.readTemperature();
|
||||
float h = sht31.readHumidity();
|
||||
|
||||
if (! isnan(t)) { // check if 'is not a number'
|
||||
Serial.print("Temp *C = "); Serial.print(t); Serial.print("\t\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");
|
||||
}
|
||||
|
||||
delay(1000);
|
||||
|
||||
// Toggle heater enabled state every 30 seconds
|
||||
// An ~3.0 degC temperature increase can be noted when heater is enabled
|
||||
if (loopCnt >= 30) {
|
||||
enableHeater = !enableHeater;
|
||||
sht31.heater(enableHeater);
|
||||
Serial.print("Heater Enabled State: ");
|
||||
if (sht31.isHeaterEnabled())
|
||||
Serial.println("ENABLED");
|
||||
else
|
||||
Serial.println("DISABLED");
|
||||
|
||||
loopCnt = 0;
|
||||
}
|
||||
loopCnt++;
|
||||
}
|
||||
Reference in new issue
Block a user