Skip to content

Instantly share code, notes, and snippets.

@cynthiahenaff
Last active March 1, 2020 20:17
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/cccdfb44484ccabf12e552ac0fff5593 to your computer and use it in GitHub Desktop.
Save cynthiahenaff/cccdfb44484ccabf12e552ac0fff5593 to your computer and use it in GitHub Desktop.
Connected temperature sensor
#define BLYNK_PRINT Serial
#include "Adafruit_SHT31.h"
#include <Adafruit_SSD1306.h>
#include <BlynkSimpleEsp8266.h>
Adafruit_SSD1306 display(-1);
Adafruit_SHT31 sht30 = Adafruit_SHT31();
char auth[] = "BLYNK_API_KEY";
char ssid[] = "WIFI_NAME";
char pass[] = "WIFI_PASSWORD";
void setup() {
Serial.begin(9600);
Serial.println("Starting");
// connect to the WiFi
Blynk.begin(auth, ssid, pass);
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() {
// start blynk
Blynk.run();
float t = sht30.readTemperature();
float h = sht30.readHumidity();
display.setCursor(0,0);
display.printf("%.1fC", t);
// send the temp value on the virtual pin 1 (V1)
Blynk.virtualWrite(1, t);
display.setCursor(0,25);
display.printf("%.0f%%\n", h);
// send the humidity value on the virtual pin 2 (V2)
Blynk.virtualWrite(2, 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