You are here

Non-invasive measurement of distances with Arduino Yun [Part 3]

 

36-1a

The following illustrates alternative method of calculating the distance within the Arduino yun sketch for some ultrasonic sensors as hc-SR04 :

 

34-HC-SR04-2

 

http://www.micropik.com/PDF/HCSR04.pdf

http://www.elecfreaks.com/store/download/product/Sensor/HC-SR04/HC-SR04_Ultrasonic_Module_User_Guide.pdf

 

The method of calculation is similar to the calculation of the distance from themselves to thunder after seeing the lightning and hearing the thunder later.

35-images

Calculate the speed of sound in m/s. In formula of variable “v”, the value “25” is environment temperature. Follow this link :

http://www.sengpielaudio.com/calculator-speedsound.htm

The sound is a vibration through the air and sound travels faster with increasing temperature. So the calculation of the speed of sound is very different, for example if calculated in Norway or Congo. In dettail, the vibration and soundwave propagation would also depend on the air pressure, but this aspect was considered negligible. However, in some places of high mountain would be appropriate to consider a light sensor calibration because of this variable (air pressure/humidity):

http://www.sengpielaudio.com/calculator-airpressure.htm

Theformula in m/s is as follows ==> v= 331.3+0,606*T.

At 20°C thespeed is 343m/s and therefore moreof 1200Km/h.

float v = 331.5+0.6*25;

int pingPin=3;

Send thepulse sound. We uses the same pin for input and output (3). It initially sets the pin to LOW and then wait three microseconds to be sure that the value isset. Then we send a high signal (beep) for 5 micro seconds.

pinMode(pingPin, OUTPUT);

digitalWrite(pingPin,LOW);

delayMicroseconds(3);

digitalWrite(pingPin,HIGH);

delayMicroseconds(5);

digitalWrite(pingPin,LOW);

It calculates how much time has elapsed until the return of the pulse so that thesignal is returned low (pulseIn function): http://www.divilabs.com/2013/03/pulsein-function-of-arduino-programming.html

pinMode(pingPin, INPUT);

float t1=pulseIn(pingPin, HIGH);

Transformationin seconds, and division by two, since the trip includes round trip.

floatt2=t1/1000.0/1000.0/2;

Assuming a constant speed, the distance is time multiplied by the speed. It also multiplies by 100 in order to have a measure in cm.

float d = t2*v *100;

After, you can send with YunClient result onbrowser via json (key variable defined at will by the developer):

client.println(“Status: 200”);

client.println(“Content-type: application/json;charset=utf-8”);

client.println();

client.print(“{\””+key+”\”:\””+d+”\”}”);

Please remember to put at the end of the loop()function at least a delay of 200 ms in order to avoid overloading the powersupply and CPU processor.

lombamarc
I have over ten years experience in project management and software architect in complex and innovative projects for multinational ICT. I have a electronic engineer extraction with automatic specialization. For years I deal with innovation also as an active contributor to several open hardware community as Rfduino, Arduino Yun, etc ... I think that in every company there is a need to co-create ideas and innovation from every person with tools and working groups motivated and sharing and dissemination of culture at all levels. Technology and research are not enough, if there is no interaction and sharing there can be no innovation.

Leave a Reply

Top