We all know water is essential for our health — but in the middle of a busy day, it's easy to forget to drink enough. The Smart Glass Counter is my solution to this problem. it uses sensors to detect when you've taken a glass of water, keeps count, and even reminds you with sound signals if you're falling behind.
The project is powered by the Arduino UNO R4 Wi-Fi, an IR Sensor, and an XKC-Y26_V Contactless water level sensor, along with a buzzer for sound notifications. once you've reached 6 glasses in a day, it plays a victory tone — motivating you to keep up the habit
Component Used
Here's what I used to build my Smart Glass Counter:
- ArduinoUNOR4Wi-Fi:Main microcontroller board to process sensor data and control buzzer.
- XKC-Y26-V Contactless Liquid Level Sensor:Detects the presence of water in the glass without physical contact.
- IR Sensor Module:Detects whether a glass is placed in the designated spot.
- Buzzer:Produces reminder tones, count confirmation sounds, and victory tones.
- Jumper Wires:For making connections between components.
- Encourages Healthy Hydration:Drinking enough water daily supports digestion, energy levels, and skin health.
- Automatic Tracking:No need to manually log you intake — the system does it for you.
- Reminders You Can't ignore:A buzzer makes sure you get up and drink water.
- Motivational goal: Reaching6 glasses triggers a celebration sound, giving you a small dopamine boost.
While exact hydration needs vary from person to person, 6 glasses (~1.5 liters) is often considered a minimum daily goal for most adults. According to health experts:
- It helps maintain body temperature
- Aids digestion and nutrient absorption
- Improves skin health
- Keeps joints lubricated
- Reduces fatigue and headaches caused by dehydration.
💡 This project can be adapted for 8–10 glasses depending on your hydration goal.
How It Works - Step by StepHere's the full breakdown of the logic:
Step 1: System StartupWhen powered on, the Arduino plays a Power-on Tone to confirm it's working.
Step 2: Reminder Mode Activated- The buzzer beeps every 3 seconds to remind you to place a glass on the spot
- This mode continues until the IR sensor detects a glass
- IR Sensor: Checks if a glass is present
- If detected, the reminder stops temporarily.
- After detecting a glass the system waits 1 second to avoid false triggers from hand movement.
- XKC-Y26-V Sensor: Check if water is present
- If no water is detected for continuous seconds, it counts as one glass consumed.
- Count Tine: Plays a short beep sequence when a glass is counted.
- The glassCount variable increases by 1.
- If water is still missing, reminder mode resumes.
- Once you reach 6 glasses, the system plays a Victory Tone and resets the counter 0.
- If the glass is removed or water is detected, the alreadyCounted flag resets, allowing for the next count cycle
IR Sensor To Arduino Board
- VCC to 3v3
- GND to GND
- OUT to D3
XKC-Y26_V Sensor To Arduino Board
- Blue Wire To GND
- Brown Wire To 5v
- Yellow To D2
Buzzer To Arduino
- -ve Pin to GND
- +ve Pin to D8
Arduino Code
This Arduino code controls a hydration reminder and tracking system using an IR sensor, a water sensor, and a buzzer. It plays periodic reminder beeps if no glass or water is detected, checks for an empty glass placed in position, and counts it as a “glass consumed” after a short verification period. The buzzer provides audio feedback for startup, reminders, counts, and milestones, resetting after six glasses.
// Pin assignments
const int waterSensorPin = 2;
const int irSensorPin = 3;
const int buzzerPin = 8;
// Variables
int glassCount = 0;
bool alreadyCounted = false; // Prevents double counting
unsigned long lastReminderTime = 0;
bool reminderActive = true;
void setup() {
pinMode(waterSensorPin, INPUT);
pinMode(irSensorPin, INPUT);
pinMode(buzzerPin, OUTPUT);
Serial.begin(9600);
// Step 1: Power-on tone
powerOnTone();
delay(300);
// Step 2: Activation tone
activationTone();
}
void loop() {
int waterState = digitalRead(waterSensorPin); // HIGH if water present
int irState = digitalRead(irSensorPin); // LOW if glass detected
Serial.print("Water: ");
Serial.print(waterState);
Serial.print(" | IR: ");
Serial.print(irState);
Serial.print(" | Count: ");
Serial.println(glassCount);
// Step 3: Reminder tone every 3s if active
if (reminderActive && millis() - lastReminderTime >= 3000) {
reminderTone();
lastReminderTime = millis();
}
// If glass detected, stop initial reminder
if (irState == LOW && !alreadyCounted) {
reminderActive = false;
Serial.println("Glass detected, waiting before check...");
delay(1000); // Settling time before starting the 3-second check
// Re-read sensors after settling
if (digitalRead(irSensorPin) == LOW) {
Serial.println("Starting 3-second empty check...");
bool cancelCount = false;
for (int i = 0; i < 3; i++) { // Check for 3 seconds
delay(1000);
if (digitalRead(waterSensorPin) == HIGH) {
Serial.println("Water detected — cancel count.");
cancelCount = true;
break;
}
}
if (!cancelCount && digitalRead(waterSensorPin) == LOW) {
glassCount++;
alreadyCounted = true;
Serial.print("✅ Glass counted! Total: ");
Serial.println(glassCount);
countTone();
// If water still not detected after counting, restart reminder
if (digitalRead(waterSensorPin) == LOW) {
reminderActive = true;
lastReminderTime = millis(); // Reset reminder timer
}
// Victory tone after 6 glasses
if (glassCount >= 6) {
victoryTone();
glassCount = 0; // Reset after victory
reminderActive = true; // Reactivate reminder after victory
}
}
}
}
// Reset counting permission when glass removed or water present
if (irState == HIGH || waterState == HIGH) {
alreadyCounted = false;
}
delay(100); // Small polling delay
}
// --------- Tone Functions ----------
void powerOnTone() {
tone(buzzerPin, 500, 200);
delay(250);
tone(buzzerPin, 700, 200);
delay(250);
noTone(buzzerPin);
}
void activationTone() {
tone(buzzerPin, 1000, 200);
delay(250);
tone(buzzerPin, 1500, 200);
delay(250);
noTone(buzzerPin);
}
void reminderTone() {
tone(buzzerPin, 400, 150);
delay(150);
noTone(buzzerPin);
}
void countTone() {
tone(buzzerPin, 800, 200);
delay(250);
noTone(buzzerPin);
}
void victoryTone() {
tone(buzzerPin, 800, 150);
delay(200);
tone(buzzerPin, 1000, 150);
delay(200);
tone(buzzerPin, 1200, 200);
delay(250);
noTone(buzzerPin);
}
Making It Look Professional - JUSTWAY to the RescueMost DIY electronics projects look messy - but for me, presentation matters. I wanted my Smart Glass Counter to look like a finished product.
That's why I used JUSTWAYS's custom manufacturing services to design and print a compact enclosure for my project.
Why JUSTWAY?
- Instant Quotes: Upload CAD files and get pricing instantly.
- Live 3D Preview: Inspect your design online before production.
- Material Variety: SLA resin, Nylon PAS-12, CNC aluminum, and more.
- Industrial Quality: Smooth finishes, sharp detailing perfect fitting parts.
- Expert Review: Engineers check you design for manufacturability.
Transparent 3D Printing Materials (its's great for showcasing internal electronics)
- High-clarity resins for seeing sensors, LEDs, or inner mechanisms.
- Perfect for educational builds or prototypes where visibility matters.
Multicolor 3D Printing (Used for my black Arduino logo)
- Prints multiple colors in one part - no painting required.
- Adds branding, labels, or style directly into the enclosure.
- My enclosure features a crisp black Arduino logo for polished, branded look.
- Campaign: June 1 - August 31, 2025 (UTC)
- Get 15% cashback on qualifying orders - just email marketing03@justway.com with your order number.
STL/CAD file to JUSTWAY site
Pick from heigh quality options
Rotate, zoom, and verify details.
Get a professional part delivered fast.
💡 Pro Tip: If you want your Arduino projects to look market-ready and branded, JUSTWAY’s multicolor printing is the way to go — and if you ever want to show off your electronics inside, their transparent printing is perfect.
What This Project Taught MeBuilding the Smart Glass Counter was more than just connecting wires and uploading code — it was a hands-on lesson in problem-solving, sensor calibration, and making tech both functional and user-friendly.
Here are the key things I learned:
- Sensor Synergy Matters – Using both the IR sensor and the XKC-Y26-V contactless liquid level sensor showed me how combining different types of sensors can give more reliable results than using just one.
- Debouncing Isn’t Just for Buttons – I discovered that even with sensors, you sometimes need a “settling time” to avoid false triggers — hence the 1-second wait after detecting a glass.
- User Feedback Is Everything – Adding reminder tones, count sounds, and victory tunes made the project feel more interactive and kept me motivated to actually use it.
- Design Aesthetics Count – Thanks to JUSTWAY’s multicolor printing, I learned how much a clean enclosure and branding can make a DIY project feel like a professional product.
- Health Meets Tech – Most importantly, I realized how electronics can directly improve daily habits — this build actually helped me drink more water and feel better throughout the day.
This project didn’t just teach me how to wire sensors and write code — it showed me how technology, when designed thoughtfully, can make small but meaningful changes in everyday life.
Social ImpactWhile the Smart Glass Counter is great for personal use, it also has potential to make a difference in communities:
- Elderly Care – Many seniors forget to drink enough water. This device could serve as a gentle, automated reminder to prevent dehydration.
- Office Wellness Programs – In workplaces, this can encourage employees to maintain hydration, improving productivity and reducing fatigue.
- Schools & Children – Teaching kids about hydration in a fun, interactive way can help build lifelong healthy habits.
- Medical Recovery Support – For patients recovering from illnesses or surgeries, staying hydrated is crucial — this device could help them keep on track.
By blending technology with wellness, this project has the power to promote healthier lifestyles at both an individual and community level.
Comments