Smart Glass Counter - a Step-by-Step Arduino Hydration Tracking Project

by rohanbarnwal in Circuits > Arduino

267 Views, 4 Favorites, 0 Comments

Smart Glass Counter - a Step-by-Step Arduino Hydration Tracking Project

ChatGPT Image Aug 14, 2025, 09_12_33 AM.png
WhatsApp Image 2025-08-13 at 9.01.02 PM (1).jpeg
WhatsApp Image 2025-08-13 at 9.01.02 PM.jpeg
WhatsApp Image 2025-08-13 at 9.01.01 PM.jpeg

We all know water is essential for our health — but in the middle of 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 have 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.

Why This Project?

  1. Encourages Healthy Hydration: Drinking enough water daily supports digestion, energy levels, and skin health
  2. Automatic Tracking: No need to manually log your intake - the system does it for you.
  3. Reminders You Can't Ignore: A buzzer makes sure you get up and drink water.
  4. Motivational Goal: Reaching 6 glasses triggers a celebration sound, giving you a small dopamine boost.

Why 6 Glasses of Water

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:

  1. It helps maintain body temperature
  2. Aids digestion and nutrient absorption
  3. Improves skin health
  4. Keeps joints lubricated.
  5. Reduced fatigue and headaches caused by dehydration.

This project can be adapted for 8-10 glasses depending on your hydration goal.

What This Project Taught Me

Building 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 designing technology that's both functional and impactful.

  1. 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.
  2. Debouncing Isn't Just for Buttons - I discovered that even with sensors, you sometimes need a "setting time" to avoid false triggers - hence the 1 second wait after detecting a glass.
  3. 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.
  4. 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.
  5. Health Meets Tech - Most importantly, I realized how electronics can directly improve daily habits - this builds actually helped me drink more water and feel better throughout the day.

Social Impact

While the Smart Glass Counter is great for personal use, it also has potential to make a difference in communities:

  1. Elderly Care: Many seniors forget to drink enough water. This device could serve as a gentle, automated reminder to prevent dehydration.
  2. Office Wellness Programs: In workplaces, this can encourage employees to maintain hydration, improving productivity and reducing fatigue.
  3. Schools & Children: Teaching kids about hydration in a fun, interactive way can help build lifelong healthy habits.
  4. 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 lifestyle at both an individual and community level.





Supplies

download (33).jpeg
uno-ek-r4-wifi-top.jpg
download (21).jpeg
download (20).jpeg
download (16).jpeg

Here's what I used to build my Smart Glass Counter:

  1. Arduino UNO R4 Wi-Fi x1: Main microcontroller board to process sensor data and control buzzer.
  2. XKC-Y26-V Contactless Liquid Level Sensor x1: Detects the presence of water in the glass without physical contact.
  3. IR Sensor Module x1: Detects whether a glass is placed in the designated spot
  4. Buzzer x1: Produces reminder tones, count confirmation sounds, and victory tones.
  5. Jumper Wires (As Needed): For making connections between components


How It Works - Step-by-Step

Here's the full breakdown of the logic:

System Startup

Video 1

When powered on the Arduino plays a Power-On Tone to confirm it's working

Reminder Mode Activated

Vid2

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.

Glass Detection

Water glass detection

IR Sensor: Checks if a glass is present

If detected, the reminder stops temporarily.

Stability Check (1 Second)

After detecting a glass, the system waits 1 second to avoid false triggers from hand movement.

Water Check (3 Seconds)

XKC-Y26-V Sensor: Checks if water is present.

If no water is detected for 3 continuous seconds, it counts as one glass consumed.

Count & Feedback

Counting

Count Tone: Plays a short beep sequence when a glass is counted

The glassCount variable increases by 1

If water is still missing. reminder mode resumes.

Victory Condition

Victory

Once you reach 6 glasses the system plays a Victory Tone and resets the counter 0

Reset Logic

If the glass is removed or water is detected, the alreadyCounted flag resets, allowing for the next count cycle.

Circuit Diagram

connection.png.jpg

IR Sensor To Arduino Board

  1. VCC to 3v3
  2. GND to GND
  3. OUT to D3

XKC-Y26_V Sensor To Arduino Board

  1. Blue Wire To GND
  2. Brown Wire To 5v
  3. Yellow To D2

Buzzer To Arduino

  1. -ve Pin to GND
  2. +ve Pin to D8


Making It Look Professional - JUSTWAY to the Rescue

download (8).png


Most DIY electronics project look messy - but for me presentation matters. I wanted my Smart Glass Counter to look like a finished product.

That's why I used JUSTWAY's custom manufacturing services to design and print a compact enclosure for my project.

Why JUSTWAY?

  1. Instant Quotes: Upload CAD files and get pricing instantly.
  2. 3D Live Model Preview: Rotate, zoom, inspect every detail before production.
  3. Material Variety: SLA resin, Nylon PA-12, CNC aluminum, and more.
  4. Industrial-Level Finish: Smooth, precise, perfect fit.
  5. Expert Support: Engineers review your designs before production.

NEW for 2025 - Transparent 3D printing & Multicolor Printing

Transparent 3D Printing Materials it's great for showcasing internal electronics)

  1. High-clarity resins for seeing sensors, LEDs or inner mechanisms.
  2. Perfect for educational builds or prototypes where visibility matters.

Multicolor 3D Printing (Used for my black Arduino logo)

  1. Prints multiple colors in one part - no painting required.
  2. Adds branding, labels, or style directly into the enclosure.
  3. My enclosure features a crisp black Arduino logo for a polished, branded look.

JUSTWAY 15% Summer Cashback

Campaign Period: June 1 - August 31, 2025 (UTC)

Get 15% cashback on all qualifying orders.

  1. After order completion, email marketing03@justway.com with your order number.
  2. Cashback is credited to your JUSTWAY account for future orders.

How I Ordered My Custom 3D Printed Model from JUSTWAY


Upload Design

11.png

Go to the JUSTWAY site, upload STL/CAD files

Select Material & Finish

22.png

Chose sturdy plastic with black color logo

Preview Live Model

33.png

Verified fit an logo placement before production.

Place Order

44.png

Confirm knowing the part would look exactly designed

💡 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.

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);
}