# Is it possible to measure the distance between two particles or between a particle and the access point?

Im starting on a project and would like to know if I should use my particle. For my project to work, I would need to measure either the distance between two particles, the distance between my particle and a wireless access point or the distance between my spark and some other form of device that I’m not aware of

Thank you !

You could make a rough guesstimate using the signal strength I suppose. A distance sensor is out of the question I assume?

1 Like

I found this equation based on the signal strength:

Do you know how I would calculate the logarithm in particle ?

This should work: https://docs.particle.io/reference/firmware/photon/#math

1 Like

Managed to get it working in case anyone else might need it thanks for the help Moors

``````#include <math.h>

float K;
int frequency;

void setup() {

Serial.begin(9600);
K = 27.55;
frequency = 2414;

}

void loop() {

// calculating distance

double expOnent = (K - (20 * log10(frequency)) + signalStrength)/20;
float distance = pow(10,expOnent);

// The distance is in meters

Serial.println(distance);

}``````

Is it somewhat accurate :o?

One problem is that in WiFi, the transmit power is not constant. If your Photon is far from the access-point (AP), the AP might turn up the power used in the transmitter to reach it. This would look like a longer distance becoming a shorter distance without anything moving.

It is very hard to translate modern radio signals directly into distance using power alone. There are some system that use the time-of-flight of the radio signal to estimate distance, but I don’t know how you would do that on a Photon.

I’m also curious about this. I’m thinking of implementing a measurement using an RTC module and measuring ping response times to approximate distance. Before I put in the time to implement this, though do you think this would be a reasonable way to approximate distance? My thoughts were that because I’m only looking to measure the distance between two photons connected over the SoftAP, I wouldn’t run into much network delay and I would be able to get a nice reading.

Yes, ping times would be a better proxy for distance than RSSI, which basically does not work at all due to varying power levels.

I am sure the times will be short and there will be some minimum time for the software stack to do its work even when the nodes are right next to each other. With some experimentation, I think you could build a model of delay to distance function. I would try it and see.

I would likely be easier to use a different radio that you have more control over, rather than relying on WiFi radios.

Yeah I might look into IR or sound as well, but my reasoning for wanting to do WiFi are just that I’d rather not add new radios to the Photon if I don’t have to. Does Bluetooth provide more control than WiFi?

It depends on the chip and software used.

What kind of requirements are you trying to fulfill? Distance max/min? Accuracy? Purpose?

Maybe seeing the bigger picture would let people help you in out of the box ways.

I’m not entirely sure yet, My goal for the moment is to give my Photons some spatial awareness, or at least give them some way of detecting their position relative to each other. At the moment, my plan is to assign each Photon an RGB value and then have them display a combination of their own color and that of their closest respective neighbor. Ultimately I’d like to gather accurate-enough data that I can write a program to place each Photon in a 3D space based only on their respective distances from their neighbors.