• Background: I am creating an automatic tea brewing machine using an Arduino and an electric water kettle from Amazon. My family and I drink lots of tea and we have many different sizes of glasses. I was going to use a peristaltic pump to transfer the water from the kettle to the tea glass (mainly because it's food safe and self-priming).
  • Task at hand: I need a way to know when to stop pumping the boiling water from the kettle as to not overflow the tea cup. I was thinking of 3D printing a bracket that will hang over the lip of the cup (like on the side) that will have two wires facing down towards the bottom of the cup. One wire would be connected to ground and one to an input on the Arduino. That way, as the water fills to the top and eventually touches the exposed ends of the wire, the Arduino would know to stop pumping because the wires are now conducting to Ground.

  • My question is: Is my method listed above safe to do in drinking water (exposing a path to ground in the water for a few seconds), or is there a better/safer/easier way to accomplish my task?

  • \$\begingroup\$ You could do what most hot beverage machines do: present buttons for a few different size cups, and fill them on a grating with an overflow tray underneath. That helps for the "user removes cup during filling" fault as well, and can accommodates users who may want a smaller serving despite presenting a larger cup. \$\endgroup\$ Jul 23, 2017 at 18:25
  • \$\begingroup\$ You could weigh it \$\endgroup\$ Jul 23, 2017 at 20:29
  • \$\begingroup\$ Take a look on how gas pumps detect when a tank is full. It is overcomplicating mechanically, but possibly worth looking at. \$\endgroup\$
    – Wesley Lee
    Jul 23, 2017 at 21:08
  • \$\begingroup\$ You have left out a number of requirements here that make deciding on the best solution difficult at best. In particular you have not indicated if the tea glass is a fixed size, especially height and diameter. IF it is, a number of solutions are possible. If it's simply a "must work for any of the 100 different mugs I have gathered over the years...." not so much. \$\endgroup\$
    – Trevor_G
    Jul 24, 2017 at 17:49

5 Answers 5


I was thinking of 3D printing a bracket that will hang over the lip of the cup (like on the side) that will have two wires facing down towards the bottom of the cup. One wire would be connected to ground and one to an input on the Arduino.

That technique should work for you. It is commonly used by visually impaired people for that task.

enter image description here

Figure 1. Liquid level sensor alarm for cup / mug.

Because you are feeding into a micro-controller GPIO you will need to make some test measurements.


simulate this circuit – Schematic created using CircuitLab

Figure 1. Probes and pull-up.

Without the micro-controller connected run some tests with a volt-meter connected between 'GPIO' and GND. Adjust R1 (a pot might be handy for this) until you can guarantee that GPIO gets reliably pulled down to about 1 V or so when the probes are covered to the required depth. 'GPIO' will read 5 V when probes are dry.


A peristaltic pump delivers a set volume per revolution so relate that volume to the size of cup and have a select button : size1 or size 2. Count the revolutions and you deliver the correct volume .

  • \$\begingroup\$ The only problem with this idea is that we have so many different sizes of cups, it would be hard to keep track of what is what. I think that it'd be easy for me to remember the volume of each cup, but not anyone else in my house... \$\endgroup\$
    – Owen
    Jul 23, 2017 at 16:50
  • 2
    \$\begingroup\$ If you want to automate then the easiest thing is to standardize. That means stopping the garage sale mix of cups and get one size. And then consider donating all the others to the next garage sale. \$\endgroup\$ Jul 23, 2017 at 16:54
  • \$\begingroup\$ You might think of a mechanical solution here. A simple float mechanism which starts to rise when the water reaches it, and activates a microswitch, optical sensor, etc. That way you've got no electrics in the water at all. A mechanism for water level selection would then be a refinement. And a safety interlock to ensure that the boiled water will not flow if the sensor is not in position, perhaps. \$\endgroup\$
    – Ian Bland
    Jul 23, 2017 at 17:00

You could use a rangefinder mounted above the cup to measure how much fluid you are adding to the cup, and have the cup set up to automatically add a specific "height" of fluid, eg. 4 cm. You would even adapt Solar Mikes suggestion and have presets (1 cm, 2 cm, etc.)

You could look into items like an ultrasonic sensor (Google arduino ultrasonic sensor, or https://www.sparkfun.com/products/9495), or an infrared rangefinder (https://www.sparkfun.com/products/8958). I've used the ultrasonic sensor before and it has a resolution of about 1 cm, which might be a bit low for this application. I believe the infrared sensor has a better resolution, but I've never used one.


After a bit of thought, one clever, but arduous and tedious solution would be to attach RFID tags to each cup bottom, and a reader on device, then program the desired amount manually.

  • 1
    \$\begingroup\$ Once one suggestion is made then lots come out - that's what is good about the site ! and i like your range finder idea. \$\endgroup\$
    – Solar Mike
    Jul 23, 2017 at 17:11
  • \$\begingroup\$ Yes, in general, though the common ones may not work well or last long in the steam plume of a cup of hot tea! The moisture sealed sensors for automotive parking applications are harder to interface, and have a very long minimum distance due to ringing perhaps from the shielding cover. \$\endgroup\$ Jul 23, 2017 at 18:23

I'd go a completely different route:

  1. have a device that identifies cups/glasses
  2. calibrate your containers

The second part is really easy. Have a mode in your firmware where you push a button until the cup is sufficiently full. Your firmware then memorizes that amount of pumping and applies it next time it encounters the same container automatically.

The first part might be harder, but on the other hand, cups sound relatively easy to tell apart when they're always placed on the very same spot in front of a camera. I'd recommend a webcam, a white LED to illuminate the observed site of the cup, and something like a raspberry pi.

Apply OpenCV's classical object classification, or experiment with the fancy deep neural networks (DNN) everyone and their mother plays with these days – tensorflow might be a good tool to start with, and they have a tutorial where they recognize digits that are horribly scrabbled; well-placed, optically precossed cups (edge detection?) should be easier.

  • \$\begingroup\$ Up vote for courage. Someone's going to take you seriously and down vote. I thought I should preempt. \$\endgroup\$
    – user128351
    Jul 24, 2017 at 19:00

Answering your actual question, instead of proposing alternatives: of course it would be safe. Why would it not be? @Transistor shows an off-the-shelf product that you could adapt for purpose. There are others, like water sensors to put on the floor near a water heater to sound an alarm if it starts leaking.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.