Last active
March 1, 2020 20:19
-
-
Save cynthiahenaff/00d0ab9a380ea8cc26b4b575ded6f076 to your computer and use it in GitHub Desktop.
Temperature Sensor
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" | |
#include <Adafruit_SSD1306.h> | |
Adafruit_SSD1306 display(-1); | |
Adafruit_SHT31 sht30 = Adafruit_SHT31(); | |
void setup() { | |
Serial.begin(9600); | |
if (! sht30.begin(0x45)) { | |
Serial.println("Couldn't find SHT30"); | |
while (1) delay(1); | |
} | |
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C (for the 64x48) | |
// init done | |
// set the text size and color | |
display.setTextSize(2); | |
display.setTextColor(WHITE); | |
display.clearDisplay(); | |
} | |
void loop() { | |
float t = sht30.readTemperature(); | |
float h = sht30.readHumidity(); | |
display.setCursor(0,0); | |
display.sprintf("%.1fC", t); | |
display.setCursor(0,25); | |
display.printf("%.0f%%\n", h); | |
display.display(); | |
delay(5000); | |
display.clearDisplay(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment