FUNITEM - How to make Thermo-hygrometer at home 온습도 센서 만들기



<How to  make Thermo-hygrometer at home>


Arduino Source Code


#include <Wire.h>             // for i2c
#include <Adafruit_GFX.h>     // for oled
#include <Adafruit_SSD1306.h> // for oled
#include "Adafruit_Si7021.h"  // for temp&humid
#include <Adafruit_SleepyDog.h>

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 32 // OLED display height, in pixels

// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET     4 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
Adafruit_Si7021 sensor = Adafruit_Si7021();

float temp = 0;
float humid = 0;

void setup() {
  Serial.begin(115200);

  if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3C for 128x32
    Serial.println(F("SSD1306 allocation failed"));
    for (;;); // Don't proceed, loop forever
  }

  if (!sensor.begin()) {
    Serial.println("Did not find Si7021 sensor!");
    for (;;); // Don't proceed, loop forever
  }

  Serial.print("Found model ");
  switch (sensor.getModel()) {
    case SI_Engineering_Samples:
      Serial.print("SI engineering samples"); break;
    case SI_7013:
      Serial.print("Si7013"); break;
    case SI_7020:
      Serial.print("Si7020"); break;
    case SI_7021:
      Serial.print("Si7021"); break;
    case SI_UNKNOWN:
    default:
      Serial.print("Unknown");
  }
  Serial.print(" Rev(");
  Serial.print(sensor.getRevision());
  Serial.print(")");
  Serial.print(" Serial #"); Serial.print(sensor.sernum_a, HEX); Serial.println(sensor.sernum_b, HEX);

  display.clearDisplay();
  display.display();
}

void loop() {
  temp = sensor.readTemperature();
  humid = sensor.readHumidity();

  Serial.print("Humidity:    ");
  Serial.print(humid, 2);
  Serial.print("\tTemperature: ");
  Serial.println(temp, 2);

  display.clearDisplay();
  display.setTextColor(WHITE);
  display.setCursor(0, 0);
  display.setTextSize(1);
  display.print(F("TEMP(C) : "));
  display.setTextSize(2);
  display.println(temp, 2);

  display.setTextSize(1);
  display.print(F("HUMID(%): "));
  display.setTextSize(2);
  display.println(humid, 2);

  display.display();

  delay(1000);
  Watchdog.sleep();

#ifdef USBCON
  USBDevice.attach();
#endif
}

댓글 쓰기

0 댓글