Detection that something is inside a cup

Hi at all,

I hope I will follow all of the rules for this forum.
First of all I am a complete beginner in working with Arduino. I worked through a few tutorials to get a level with which I am able to do my own projects. I am an experienced software developer, so writing the code will be the least problem (hopefully).
But now my question. I am trying to detect if a table tennis ball is inside a cup. This project should be in place in the game Beer Pong. Everytime the ball falls inside the cup two led stripes should be lightened up. So far I was able to do this with ultra sonic distance measurement (HC-SR04) and also with a photoresistor (removed the bottom of the cup). It also worked to light up the led. But so far I only tested it with one cup, but at the end I need to detect it for 10 cups (or 20 if it is possible with just 1 arduino).
My question is, will the Arduino Mega be able to handle 10/20 HC-SR04 and 2/4 led strips (I know I will need external power for the led)?
And also is this really the best way to detect if the ball is in the cup. I also thought about using an acceleration sensor or a piezo element. What do you think what is the best/easiest way for this kind of detection? The cost for one element should be less than 1$, otherwise it would be way to expensive.

Thanks in advance for your answers!

Did you test a leaf switch in the cup that would be pressed as the ball goes through the cup?

Paul

I suspect this would be much easier with multiple Light Dependent Resistors (LDRs) rather than with multiple ultrasonic detectors.

The LDRs can easily produce a signal that can be detected with digitalRead() with appropriate choice of the fixed resistor.

...R

Robin2:
I suspect this would be much easier with multiple Light Dependent Resistors (LDRs) rather than with multiple ultrasonic detectors.

The LDRs can easily produce a signal that can be detected with digitalRead() with appropriate choice of the fixed resistor.

...R

This is my first thought. I'm not even clear how one would approach this with ultrasonic sensors.

One advantage of the LDR approach is that one could implement a multiplexing scheme to reduce the number of IO pins required.

An example for a 2x2 matrix (which doesn't actually save pin count) is illustrated. The concept is the same as used for keyboard switch matrices, that is, one of the digital outputs connected the columns is set high while all others are low and the value of the LDR is read by an ADC input connected to the row. To read the state of all LDRs, the program sets each column in succession and reads the row value for each column state.

Component cost per node is probably on the order of $0.25 US.

MrMark:
one of the digital outputs connected the columns is set high while all others are low and the value of the LDR is read by an ADC input connected to the row

I presume that will also work with digitalRead() - since the OP only needs an ON/OFF indication

...R

"The cost for one element should be less than 1$, otherwise it would be way to expensive."

Probably a simple limit switch in the cup might fit that budget. You could experiment with something as simple as some aluminum foil and a wire.

A switch may be unreliable due to the very low mass of the ball. I would go for the simple led/detector for each cup.

If you run out of I/O pins, just add a port extender like a MCP23017.

SteveMann:
A switch may be unreliable due to the very low mass of the ball. I would go for the simple led/detector for each cup.

If you run out of I/O pins, just add a port extender like a MCP23017.

SteveMann:
A switch may be unreliable due to the very low mass of the ball. I would go for the simple led/detector for each cup.

If you run out of I/O pins, just add a port extender like a MCP23017.

The inertia of the ball, not the mass triggers the switch.

Paul

Robin2:
I presume that will also work with digitalRead() - since the OP only needs an ON/OFF indication

...R

Probably and under the right circumstances.

I'd envisioned this using ambient lighting that is (or isn't) shadowed by the ping pong ball. An ADC approach would allow for an adaptive threshold adjusting to changes in room lighting or lighting in each cup. digitalRead(), essentially a 1-bit ADC, would be more limited if that were the approach.

MrMark:
digitalRead(), essentially a 1-bit ADC, would be more limited if that were the approach.

I use LDRs and digitalRead() to detect the position of model trains and it works well for me in a wide range of ambient lighting. IIRC higher values of the fixed resistor make it more sensitive. I think my project uses 68k resistors.

...R

Paul_KD7HB:
The inertia of the ball, not the mass triggers the switch.

Paul

If there is little mass, you would need an awful lot of inertia.

SteveMann:
If there is little mass, you would need an awful lot of inertia.

Doesn't take much to move a properly mounted leaf switch. Even ping balls work.

Paul

Thanks for all your suggestions.
If I got the idea of the leaf switch right, it's like a scale? (Sorry I'm no native speaker, and google wasn't as useful as I thought for finding a lot about leaf switches) I liked this idea on the first sight, but then I thought about a possible issue. Every time somebody is touching one of the cups it would light up the leds. Also the cups need to be arranged at certain points in the game.
I also had the idea with the ldr. But when I had this idea I forgot to add a led inside the cup like mentioned here. Without this additional led, it could possibly lightened up when somebody is leaning over the cups.
I really like idea to kind of creating a closed environment inside the cup, so that outside the cup can somehow corrupt the measurement. Would this work with an IR led and an IR photoresistor? A great plus is the price, these two elements costs about nothing.

The inertia of the ball, not the mass triggers the switch.

Inertia is the resistance to movement, I think you all mean the moment here. As the momentum is the mass times the velocity then the ball would have to be going very fast to be able to trigger a switch.

If I got the idea of the leaf switch right, it's like a scale?

It is like a leaver with the switch close to the fulcrum. These do take a lot of weight to trigger, I had trouble detecting a golf ball with a lever micro switch.

The sort of switch you need is used as a limit switch in CD drives but I have never seen these as a component for sale in the distributors catalogues and I am not sure what they are called.

If you are the sort that likes making bits an pieces you could make an effective leaf switch with some thin brass strip (perhaps 10 thousandths of a inch) which is generally available from model engineering and model hobby stores and, almost certainly, on Ebay.

Brass is easy to solder wires to. Maybe put a big brass drawing pin in the bottom of the cup and glue most of the brass strip to the side of the cup with a small piece bent at right angles so it is not quite touching the head of the pin - say a 1mm gap. The weight of a ping pong ball should easily deflect the brass strip so it contacts the pin and completes the circuit.

...R

Robin2:
I use LDRs and digitalRead() to detect the position of model trains and it works well for me in a wide range of ambient lighting. IIRC higher values of the fixed resistor make it more sensitive. I think my project uses 68k resistors.

Or INPUT_PULLUP for an effective - approximate - 47k resistor for both digitalRead() and analogRead(). :grinning:

Paul__B:
Or INPUT_PULLUP for an effective - approximate - 47k resistor for both digitalRead() and analogRead(). :grinning:

IIRC I needed a higher value for my resistor - perhaps due to a low ambient light level.

...R

And that is fine for your case, but in general, INPUT_PULLUP is an alternative to an external resistor.