I signed up just for this.
You want two receivers, not one. Maybe three or even five. You can't determine how the fob's signal strength will appear at any moment, but you can determine the differential of two signals. Because strength from a point source is related to the cube of the distance, you can use the ratio of signal strength between antennas to determine relative distance. No matter the initial signal strength, this ratio will be an effective trigger.
Please note, this is how many detectors work for listening devices; it's old, reliable, solid-state thinking. Calibrated signal inputs to an Arduino should be even easier.
Edit: For more helpful commentary:
Bottom line up front:
This code is untested, please see the annotated pseudocode and explanation below!
bool isRange(float In1,float In2,float Trigger)
{
if((In1/In2) >Trigger)
{
return true;
}
else if((In2/In1) > Trigger )
{
return true;
}
else
{
return false;
}
}
Explanation:
When you drop a pebble in a still pond, ripples expand from the center. As they get further and further away, the peaks and valleys get smaller and smaller. This is because the larger the rings, the larger the circumference that needs energy. RF is basically the same in three dimensions, so bear with me and I’ll tell you how it changes later.
The circumference of a circle is pir2. We can estimate the amplitude as a constant K and an initial energy I spread across that circumference. => A=KI/pir^2
If the peaks are a quarter inch high at one inch in radius, then => .25 = KI/pi12, or .2512 = KI/pi
Since K and Pi are constants that we don’t care about, we can estimate I as .25. From there you can determine any amplitude through A = 1/r2, so at .5 inches we expect a peak at 1/.25, or four inches, and at two inches 1/4 or, of course, .25”
As we’ve noted, we can’t actually use the amplitude to find the range, K actually isn’t constant, as it contains attenuation factors from the environment. However, we solve for it anyway => r=sqrt(A*pi/(KI))
There are too many unknowns, but if we add a second microphone, we get another way to eliminate the unknowns. By definition, K, pi, and I are all now constant between the two equations. Playing with the equation again, we can define it as A/r^2 = KI/pi.
We place the first radio, as A1 and R1, and the second as A2 and R2. So => A1/R12 = A2/R22
Then we modify the equation to => A1/A2 = R12/R22
From here you can look at the simplest example: a linear array. If you have two sensors a foot apart and want a trigger at 10 feet, you can use R1=11 and R2=10, then A1/A2 = 1.21.
Two problems: first, we’re still looking at a pond. The surface of a sphere is 4/3pir^3. But those are all constants except for radius. We switch to A1/A2 = R13/R23 and call the new ratio 1.331
Second, this only detects a wave from one direction. We can solve that by setting up a trigger with the reciprocal as well.
So, let’s pseudocode this, because I haven’t touched Arduino in too long.
T = (Trigger Level)
main(){
In1 = (Amplitude from unit 1)
In2 = (Amplitude from unit 2)
isTriggered = (a boolean that is true if the level has been surpassed)
if ([In1/In2] > T)
isTriggered = True
elif ([1/[In1/In2]] > T) // (or In2/In1)
isTriggered = True
else
isTriggered = False
}
What’s happening here is you’re defining a trigger level that takes into account your desired distance, hardware configuration, amplifiers, etc. Then the radios are polled, and if the ratio or the reciprocal (needed to see if the object is within the radius in the other direction) exceeds the threshold then it sets the trigger state. Roll this into a function with a return and you’re good to go.
Now, hardware wise, this is very linear in its detection. At 90 degrees off axis the system will likely never trigger. If set up as a three antenna system, this directionality would be removed, but I’ll leave the coding response and trigger level development up to you. An elephant cage system, with an inner and outer antenna array, is another alternative, but a waste of resources in your case, as you’d need a receiver for each antenna in both arrays. Feel free to look up the sites in question, they’re fascinating relics of long-wave communications during the Cold War, but I imagine they still have uses.
I’ve been working on the electronic side of this for a while, but haven’t gotten around to building one yet: do so at your own risk.
Also, if you get radios that output in dB, remember that these are logarithmic units and the trigger ratios will be very different, but with good signal/noise, you can handle large ranges or small array sizes. In any case, it’s important to know your hardware.
Let me know if I made a mistake you need further help.