Tortoise Monitor

About This Project

This project is a secondary monitor to ensure my tortoise has appropriate temperatures during the winter. It will alert me when temperatures drop below a set limit. I plan on replacing the ESP board with a true PCB milled with a CNC at some point and adding more photos. My tortoise was taking a nap when I was finishing up so I didn’t disturb her.

What’s Connected

Customized ESP-12e with 3d printed case.

Triggers & Alerts

There is a trigger set up that will alert me when temperatures drop below a set limit.

Dashboard Screenshots

Photos of the Project


Here is the Arduino sketch, but I recommend reading this post for an explanation of how everything works in more detail.

// This example shows how to connect to Cayenne using an ESP8266 and send/receive sample data.
// Make sure you install the ESP8266 Board Package via the Arduino IDE Board Manager and select the correct ESP8266 board before compiling. 

//#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial
#define DHTTYPE DHT11
#define DHTPIN  14

#include <CayenneMQTTESP8266.h>
#include <DHT.h>

// WiFi network info.
char ssid[] = "";
char wifiPassword[] = "";

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "";
char password[] = "";
char clientID[] = "";

//Variables for DHT11 values
float h, t, hif;
//Time to sleep - 10 minutes - delete a zero to set to 1 minute
int SleepTime = 600000000;
//Values sent/error booleans
bool CayenneSent = false;
bool ReadError = false;

DHT dht(DHTPIN, DHTTYPE);

void setup() {
	Serial.begin(9600);
  Serial.println("Setup");
	Cayenne.begin(username, password, clientID, ssid, wifiPassword);

  CayenneSent = false;
  ReadError = true;
}

void loop() {
  //Run Cayenne Functions
	Cayenne.loop();

  //Only check values if there is a ReadError 
  if (ReadError){
    ReadError = false;
    //Check if read failed and try until success
    int WhileLoops = 0;
    do {
      WhileLoops++;
      //We can't go too long without calling Cayenne.loop() so exit this loop after 2 seconds and set an error flag
      if (WhileLoops >= 4){
        Serial.println("Sensor Read Error");
        ReadError = true;
        break;
      }
      //Read temperature as Fahrenheit
      t = dht.readTemperature(true);
      //Read humidity (percent)
      h = dht.readHumidity();
      //Read temperature as Fahrenheit
      t = dht.readTemperature(true);
      //Calculate Heat Index as Fahrenheit
      hif = dht.computeHeatIndex(t, h);
  
      delay(500);
    } while  (isnan(t) || isnan(h));

    Serial.print("Humidity: ");
    Serial.println(h);
    Serial.print("Temperature (f): ");
    Serial.println(t);
    Serial.print("Heat Index (f): ");
    Serial.println(hif);
  }
  else {
    //Check if we sent all values and sleep for 10 minutes if we did
    if (CayenneSent){
      Serial.println("Sent all values - sleeping");
      delay(100);
      ESP.deepSleep(SleepTime, WAKE_RF_DEFAULT);
      delay(100);
    }
  }
}

// Default function for sending sensor data at intervals to Cayenne.
// You can also use functions for specific channels, e.g CAYENNE_OUT(1) for sending channel 1 data.
CAYENNE_OUT_DEFAULT()
{
  //Check if there was a read error and skip sending values if there is
  if (!ReadError){
    //Send Values
    Cayenne.virtualWrite(0, h, "rel_hum", "p");
    Cayenne.virtualWrite(1, t, "temp", "f");
    Cayenne.virtualWrite(2, hif, "temp", "f");
    
    //Set CayenneSent to true so we know when to sleep
    CayenneSent = true;
  }
}
3 Likes

nice @adam. i hope your tortoise does not destroys this one also :hammer:

:rofl: They are a destructive beast!

1 Like

you have to show it to us, it must look like Terminator image ?