# Calculating location with 4 piezo's

I have a rectangle with the following size 40 cm * 50 cm. On each corner of this rectangle I placed a Piezo element (it's an electronic element which measures the vibration)

The rectangle is defined as followed: the left upper corner = A the left lower corner = B the right lower corner = C the right upper corner = D

I'm trowing a ball on the surface and I'd like to calculate it's X and Y axis. The outcome of the piezo elements are as followed:

A,B,C,D - 0 lowest vibration, 1023 highest vibration These values can be mapped to a number I can decide, so that means I can make it whatever we need it to be. Example: map 0,1023,0,100, meaning the new mapping will be 0 - 100.

I found a possible solution here: http://mathafou.free.fr/pbg_en/sol114.html The problem I got is that i don't know where the ball will be and therefor I don't know the angle it will fall on.

The thing I do now is:

Example: We trow the ball. The outcome could be ABC or what would be best ABCD results.

I thought Pythagoras could come in handy here. The thing I did was: A*A+B*B=C*C (to get the square calculation done) A+B = AB, B+C = BC, A+C= AC, (to get the sides of a triangle) AB*BC=AC (We don't know AC but we can square root the outcome of AB*BC)

But then i realised I just know how long the side is and I still don't know where the ball landed :(

The following I already implemented to scale it when it works (maybe not relevant now) A+B+C+D = Total outcome we can possibly get at that point (as we are relying on vibration) A,B,C,D/Total = the scale we need to calculate with

I call this A1,B1,C1,D1 so I can re-use this in the code The reason I do this, is the follow up I need it for. Im going to use a projector to project a video on the exact X/Y position. But that's not relevant I guess for now.

I'm programming this in Processing 2 : http://processing.org

• You'll need to do some trials to see the relationship between sensor value and distance from that corner/edge. Then you can get an equation where, given any sensor value, it will estimate distance. – sachleen May 10 '14 at 18:14
• Although I don't know how well this would work, but I'd try [average of top sensors - average of bottom sensors] to find a Y coordinate, and [average of right sensors - average of left sensors] to find the X coordinates. Note: the center would be the origin. Sample equation: `((A1+B1)/2)-((C1+D1)/2)` and `((A1+C1)/2)-((B1+D1)/2)`. Try that and see how it works. If it works, I'll post an answer explaining some of the mechanics behind it. (The input values are the readings of the sensors.) – Anonymous Penguin May 10 '14 at 20:02

You might want to look into how LORAN works, as I believe you can do something similar.

First premise: You want to look for the initial transient caused by the impact propagating to sensors in various places on the periphery. The signal in the material will end up bouncing around quite a bit before it dies out, but the leading edge of the initial transient should be unambiguous, so use that.

Second premise: You have no idea when the ball actually hits - you can also measure the difference in timing between when various sensors first detect it.

So take any two sensors, measure the time lag between when they detect the ball, and convert that via the speed of sound in your material. This yields the difference in the distance of the impact point from the two sensors. If you know the position of the two sensors, and plot the curves of points which satisfy the equation of the measured difference in distance from each of them you can a class of conic section called a `hyperbola`.

But so far you do not have an answer, but only a pair of curves along which the impact must lie. So now take at least one new sensor, and repeate the exercise generation a new equation.

Combine the equations and solve to find the intersection of the curves - this is your point of impact. It is possible to have more than one mathematical solution, but I think you will find that only one possible solution lies in the area between the sensors.

(Unfortunately, the ATmega328p A/D converter probably isn't fast enough to do a good job of this - at 10KSPS each sample is around 34mm in air, and around half a meter in typical solids - so you either need a much faster A/D, or else tune a comparator circuit to detect pulses and measure them with ATmega timer channels.)