Thomas_Seeed
Published

Caring Puppy 1.0

We want to care for the puppies who stay at home alone during the working day through temperature monitor to avoid a "hot dog".

IntermediateShowcase (no instructions)2 hours54
Caring Puppy 1.0

Things used in this project

Story

Read more

Code

caring puppy

C/C++
#include <Arduino.h>
#include <SensirionI2CSht4x.h>
#include <Wire.h>
#include"TFT_eSPI.h"
TFT_eSPI tft;
 
SensirionI2CSht4x sht4x;
 
void setup() {

  tft.begin();
  tft.setRotation(3);
  tft.fillScreen(0x0);
  tft.setTextColor(0xFF40);
  tft.setTextSize(4);
 
    Serial.begin(115200);
    while (!Serial) {
        delay(100);
    }
 
    Wire.begin();
 
    uint16_t error;
    char errorMessage[256];
 
    sht4x.begin(Wire);
 
    uint32_t serialNumber;
    error = sht4x.serialNumber(serialNumber);
    if (error) {
        Serial.print("Error trying to execute serialNumber(): ");
        errorToString(error, errorMessage, 256);
        Serial.println(errorMessage);
    } else {
        Serial.print("Serial Number: ");
        Serial.println(serialNumber);
    }
}
 
void loop() {
    uint16_t error;
    char errorMessage[256];
 
    delay(1000);
 
    float temperature;
    float humidity;
    error = sht4x.measureHighPrecision(temperature, humidity);
    if (error) {
        Serial.print("Error trying to execute measureHighPrecision(): ");
        errorToString(error, errorMessage, 256);
        Serial.println(errorMessage);
    } else {
        Serial.print("Temperature:");
        Serial.print(temperature);
        Serial.print("\t");
        Serial.print("Humidity:");
        Serial.println(humidity);
    }

      if ((temperature > 29)) {
     tft.fillScreen(0x0);
    tft.drawString((String)"hot dog", 100, 120);
    delay(1000);
  } else {
    tft.fillScreen(0x0);
    tft.drawString((String)"good", 100, 120);
    delay(1000);
  }
}

Credits

Sun Yufan

Posted by Thomas_Seeed
Thanks to Sun Yufan.

Comments