Project Overview
This project creates a smart feeding reminder for your aquarium. When you approach the fish tank, the system checks if it is time to feed and plays a voice reminder if needed. It also tracks the last feeding time and prevents overfeeding.
Difficulty: Beginner
Estimated time: 1-2 hours
Estimated cost: $20-30
How It Works
A PIR sensor detects when someone approaches the fish tank. The ESP32 checks the current time against a feeding schedule. If it is within the feeding window and the last feeding was more than 8 hours ago, it plays a voice reminder. A button can be pressed to mark feeding as done.
Materials Needed
- ESP32 (1)
- HC-SR501 PIR sensor (1)
- DFPlayer Mini MP3 module (1)
- MicroSD card with feeding reminder audio
- Small speaker (3W)
- Push button to mark feeding done
- LEDs for status (optional)
- 220Ω resistors
- Jumper wires
- Power supply (5V 1A)
Circuit Diagram
Connection Table
| Component |
Pin |
ESP32 Pin |
PIR Sensor |
OUT
GPIO 4
DFPlayer Mini TX |
–
GPIO 16
DFPlayer Mini RX |
–
GPIO 17
Push Button |
One side
GPIO 5
Green LED |
Anode
GPIO 2
Red LED |
Anode
GPIO 15
表
Arduino Code
// Fish Tank Feeding Reminder
#include <WiFi.h>
#include <SoftwareSerial.h>
#include <DFRobotDFPlayerMini.h>
#include <time.h>
SoftwareSerial mySoftwareSerial(16, 17);
DFRobotDFPlayerMini myDFPlayer;
const int pirPin = 4;
const int buttonPin = 5;
const int greenLedPin = 2;
const int redLedPin = 15;
const char* ntpServer = "pool.ntp.org";
const long gmtOffset = 0;
const int daylightOffset = 0;
struct FeedingTime {
int hour;
int minute;
};
FeedingTime feedTimes[] = {{8, 0}, {18, 0}};
const int numFeedTimes = 2;
unsigned long lastFeedTime = 0;
bool fedToday[2] = {false, false};
unsigned long lastReminderTime = 0;
const unsigned long reminderCooldown = 3600000;
void setup() {
Serial.begin(115200);
pinMode(pirPin, INPUT);
pinMode(buttonPin, INPUT_PULLUP);
pinMode(greenLedPin, OUTPUT);
pinMode(redLedPin, OUTPUT);
digitalWrite(greenLedPin, LOW);
digitalWrite(redLedPin, LOW);
WiFi.begin("YourSSID", "YourPassword");
while (WiFi.status() != WL_CONNECTED) delay(500);
configTime(gmtOffset, daylightOffset, ntpServer);
mySoftwareSerial.begin(9600);
myDFPlayer.begin(mySoftwareSerial);
myDFPlayer.volume(20);
delay(30000);
}
bool isTimeToFeed(int currentHour, int currentMinute, int feedHour, int feedMinute) {
int currentMinutes = currentHour * 60 + currentMinute;
int feedMinutes = feedHour * 60 + feedMinute;
return (currentMinutes >= feedMinutes && currentMinutes < feedMinutes + 30);
}
void markFed(int feedIndex) {
fedToday[feedIndex] = true;
lastFeedTime = millis();
digitalWrite(greenLedPin, HIGH);
myDFPlayer.play(3);
delay(2000);
digitalWrite(greenLedPin, LOW);
}
void playReminder(int feedIndex) {
myDFPlayer.play(feedIndex == 0 ? 1 : 2);
digitalWrite(redLedPin, HIGH);
delay(2000);
digitalWrite(redLedPin, LOW);
}
void resetDaily() {
struct tm timeinfo;
if (getLocalTime(&timeinfo)) {
if (timeinfo.tm_hour == 0 && timeinfo.tm_min == 0) {
for (int i = 0; i < numFeedTimes; i++) fedToday[i] = false;
}
}
}
void loop() {
struct tm timeinfo;
if (!getLocalTime(&timeinfo)) return;
resetDaily();
bool motion = digitalRead(pirPin) == HIGH;
bool buttonPressed = digitalRead(buttonPin) == LOW;
if (buttonPressed) {
delay(50);
if (digitalRead(buttonPin) == LOW) {
for (int i = 0; i < numFeedTimes; i++) {
if (isTimeToFeed(timeinfo.tm_hour, timeinfo.tm_min, feedTimes[i].hour, feedTimes[i].minute)) {
markFed(i);
break;
}
}
while (digitalRead(buttonPin) == LOW) delay(10);
}
}
if (motion && (millis() - lastReminderTime > reminderCooldown)) {
for (int i = 0; i < numFeedTimes; i++) {
if (isTimeToFeed(timeinfo.tm_hour, timeinfo.tm_min, feedTimes[i].hour, feedTimes[i].minute) && !fedToday[i]) {
lastReminderTime = millis();
playReminder(i);
break;
}
}
}
delay(100);
}
Installation Steps
- Mount PIR sensor near fish tank
- Position speaker where reminder can be heard clearly
- Mount button near fish tank for easy access after feeding
- Assemble electronics in small box
- Adjust feeding times in code to match your schedule
- Approach tank at feeding time to test reminder
Project Extensions
- Add servo to dispense food automatically
- Add Wi-Fi dashboard to view feeding history
- Add mobile notifications when feeding is missed
- Add DS18B20 to monitor tank temperature
- Add LED strip to simulate sunrise/sunset
Conclusion
This fish tank feeding reminder ensures your aquatic pets are fed on schedule with voice reminders.