Smart Cup Coaster

Overview

Smart cup coaster is a device which would detect the amount of water in a cup and let the user know how much is in there. When a cup is placed on the coaster, it detects the weight using a load cell inside the coaster and send it to a user friendly C# GUI which informs the user about the amount of water in the cup.

Parts Used

  • Mbed Microcontroler
  • Loadcell (FX1901)
  • Instrumentation Amplifier (INA125)
  • Resistor (220 Ohms)
  • C# GUI
  • Cup
  • 3D Printed Coaster

Pictures

Loadcell Connection Diagram

/media/uploads/akr7/untitled-2_copy.jpg

Wiring Information of the Loadcell

/media/uploads/akr7/wiring.jpg

Pin Configuration of INA125

/media/uploads/akr7/pin_confg.jpg

Coaster

/media/uploads/akr7/snapchat-4109961236895159780.jpg

/media/uploads/akr7/snapchat-7365629747466077540.jpg

Coaster Design

Solid works was used to design the cup coaster and was 3D printed. The coaster size was 3in X 3in X 0.4in for the bottom piece with a slot for the Loadcell, and 3in X 3in X 0.1in for the top piece.

Coaster Top

/media/uploads/akr7/coastertop.jpg

Coaster Bottom

/media/uploads/akr7/coasterbottom.jpg

Video

Pin Outs

/media/uploads/akr7/pinouts.jpg

  • 220 Ohm Resistor connected from pin 8 to 9 of INA125

Codes

Coaster code

#include "mbed.h"

Serial pc(USBTX,USBRX);

  AnalogIn senseLine(p20);

// Put two known loads on the sensor and take readings. Put those values
// here.
float aReading = 21.5;
float aLoad = 0.2205; // lbs.
float bReading = 25.0;
float bLoad = 0.5512; // lbs

int main() {    
    while(1) {
       float pinReading = 100*senseLine.read();
    //Base Pin Value needs to read 10.0
    
         float AvgReading = (std::ceil(pinReading)+std::floor(pinReading))/2;
         float Vol = 14.474*pinReading - 787.19;
         float AvgVol = (std::ceil(Vol)+std::floor(Vol))/2;
         float count = 0; 
         pc.printf("%.2f ", AvgReading);
         wait(1);
              
    }
}

C# GUI

/media/uploads/akr7/full.png /media/uploads/akr7/half.png /media/uploads/akr7/refill.png

  • Below is the C# code for our User Interface. The data is read in via the Serial port and the values received are averaged to determine the current weight of the cup. The weight of a full cup is measured upon startup of the connection, and is used to determine the amount of water currently in the cup. This value is used to show a picture that represents the water level in the cup and to determine when a refill is needed. When a refill is needed, a label pops up on the interface.

C# GUI code

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Smart_Coaster
{

    public partial class Form1 : Form
    {

        System.Threading.Thread t;
        float weight = 0;
        float fullCup;
        float waterWeight = 36; //empty is 53.5 & full is 79.5
        float emptyCup;
        float refillWarning; // 58.5
        Boolean refillNeeded = false;

        public Form1()
        {
            InitializeComponent();
        }

        public void CheckWeight()
        {
            while (true)
            {
                String w = serialPort1.ReadExisting();
                if (w.Length > 0)
                {
                    String[] values = w.Split(new char[0]);
                    float total = 0;
                    foreach (var val in values)
                    {
                        if (val.Length > 0)
                        {
                            float a = float.Parse(val);
                            total += a;
                        }
                    }

                    weight = total / (values.Length - 1);
                    MethodInvoker mi = delegate() { this.label1.Text = "Weight: " + weight; };
                    this.Invoke(mi);
                }
                if (!refillNeeded && weight > refillWarning && weight < (refillWarning + 10))
                {
                    MethodInvoker m = delegate() { this.pictureBox1.Image = Properties.Resources.half_full_glass; };
                    this.Invoke(m);
                }
                else if (!refillNeeded && weight > refillWarning && weight < fullCup)
                {
                    MethodInvoker m = delegate()
                    {
                        this.pictureBox1.Image = Properties.Resources.full_glass;
                    };
                    this.Invoke(m);
                }
                if (weight < refillWarning && weight > emptyCup)
                {
                    MethodInvoker mi = delegate() { this.label2.Visible = true; this.pictureBox1.Image = Properties.Resources.empty_glass; };
                    this.Invoke(mi);
                    refillNeeded = true;
                }

                else if (this.label2.Visible == true)
                {
                    MethodInvoker mi2 = delegate() { this.label2.Visible = false; this.pictureBox1.Image = Properties.Resources.full_glass; };
                    this.Invoke(mi2);
                    refillNeeded = false;
                }

                if (weight < emptyCup)
                {
                    MethodInvoker mi = delegate() { this.label2.Visible = false; };
                }
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                serialPort1.Open();
                String w = serialPort1.ReadExisting();
                if (w.Length > 0)
                {
                    String[] values = w.Split(new char[0]);
                    float total = 0;
                    foreach (var val in values)
                    {
                        if (val.Length > 0)
                        {
                            float a = float.Parse(val);
                            total += a;
                        }
                    }
                    fullCup = total / (values.Length - 1);
                }
                emptyCup = fullCup - waterWeight;
                refillWarning = emptyCup + 12;
            }

            catch (Exception com_open_except) { }
            t = new System.Threading.Thread(CheckWeight);
            t.Start();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            serialPort1.Close();
        }
    }
}


Please log in to post comments.