/*
Project: ESP32-C3 Aquarium Controller
Description: Monitors and controls water temp & level
Feeds the fish based on a schedule
Controls lighting
Author: AnonEngineering
Date: 9/23/26
License: Beerware
*/
#include <WiFi.h>
#include <TimeLib.h>
#include <Adafruit_ILI9341.h>
#include <Adafruit_GFX.h>
#include "secrets.h"
const int SCREEN_WIDTH = 128;
const int SCREEN_HEIGHT = 64;
const int OLED_RESET = -1;
const int MODE_SW_PIN = 20; // 12h / 24h switch pin
const int ONE_SECOND = 1000; // time interval
const int DL_OFFSET_SEC = 3600; // daylight savings offset
const long GMT_OFFSET_SEC = -(5 * 60) * 60; // GMT offset (EST is -5)
const char* NTP_ADDR = "pool.ntp.org";
unsigned long lastTime = 0;
#define TFT_DC 6
#define TFT_CS 5
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
void centerText(const char* text, int y) {
int16_t x1, y1;
uint16_t textWidth, textHeight;
//oled.getTextBounds(text, 0, y, &x1, &y1, &textWidth, &textHeight);
int16_t x = (SCREEN_WIDTH - textWidth) / 2;
//oled.setCursor(x, y);
//oled.print(text);
}
void connectWiFi() {
static bool symbol = false;
char buffer[24];
strncpy(buffer, "Connecting to", 24);
//centerText(buffer, 10);
Serial.print(buffer);
Serial.print(" ");
//centerText(ssid, 30);
Serial.println(ssid);
//oled.display();
WiFi.begin(ssid, pass, 6);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
//Serial.print(WiFi.status());
symbol = !symbol;
//oled.setCursor(63, 50);
//oled.print(symbol ? "X" : "+");
//oled.display();
}
Serial.println("");
//oled.clearDisplay();
strncpy(buffer, "WiFi connected.", 24);
//centerText(buffer, 32);
Serial.println(buffer);
//oled.display();
delay(1000);
//oled.clearDisplay();
}
void printLocalTime(bool mode24) {
char buffer[24];
time_t rawtime;
struct tm * timeinfo;
time (&rawtime);
timeinfo = localtime (&rawtime);
if (!getLocalTime(timeinfo)) {
Serial.println("Failed to obtain time");
return;
}
//oled.setTextSize(2);
if (mode24) {
strftime (buffer, 24, " %H:%M:%S ", timeinfo);
} else {
strftime (buffer, 24, "%I:%M:%S%p", timeinfo);
}
Serial.print(buffer);
//Serial.print(" ");
centerText(buffer, 25);
//oled.setTextSize(1);
strftime (buffer, 16, "%A", timeinfo);
centerText(buffer, 5);
Serial.print("\t");
Serial.print(buffer);
Serial.print(", ");
strftime (buffer, 24, "%B %d, %Y", timeinfo);
Serial.println(buffer);
centerText(buffer, 50);
//oled.display();
}
/*
void showSplash() {
oled.setTextSize(2);
centerText("NTP", 15);
centerText("Clock", 35);
oled.display();
delay(2000);
oled.setTextSize(1);
oled.clearDisplay();
oled.display();
}
*/
void setup() {
tft.begin();
tft.setCursor(26, 120);
tft.setTextColor(ILI9341_RED);
tft.setTextSize(3);
tft.println("Hello, TFT!");
tft.setCursor(20, 160);
tft.setTextColor(ILI9341_GREEN);
tft.setTextSize(2);
tft.println("I can has colors?");
Serial.begin(115200);
//if (!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
// Serial.println(F("SSD1306 allocation failed"));
// for (;;); // Don't proceed, loop forever
//}
pinMode(MODE_SW_PIN, INPUT_PULLUP);
//oled.setTextSize(1); // Normal 1:1 pixel scale
//oled.setTextColor(SSD1306_WHITE, SSD1306_BLACK);
// show Adafruit logo
//oled.display();
//delay(1000);
//oled.clearDisplay();
//oled.display();
// splash
//showSplash();
// Connect to Wi-Fi
connectWiFi();
//delay(500);
// Init and get the time
centerText("Awaiting time sync...", 15);
//oled.display();
configTime(GMT_OFFSET_SEC, DL_OFFSET_SEC, NTP_ADDR);
//delay(1000);
//oled.clearDisplay();
//lastTime = millis();
}
void loop() {
bool is24h = digitalRead(MODE_SW_PIN);
if (millis() - lastTime >= ONE_SECOND) {
lastTime = millis();
printLocalTime(is24h);
}
}
Loading
esp32-c3-devkitm-1
esp32-c3-devkitm-1
Heater
Pump
Feeder
Water level
Water temp