User Tools

Site Tools


en:distance

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

en:distance [2018/01/29 10:12] (current)
Line 1: Line 1:
 +===== Water level measuring =====
 +Measuring of distance can be useful if one want to have a survey of water level in reservoir. It can be easily done with aruino because there is a lot of moduls for measuring distance. ​
 +
 +
 +----
 +
 +==== Ultrasound distance sensor ====
 +Ultrasound distance sensors works on basic princip. It sends utrasound singnal and count the time before the reflected sound return. That time is proportional to the distance.
 +
 +
 +
 +=== HC-SR 04 ===
 +{{ wiki:​ultrasonic.png?​155}}
 +HC-SR 04 is modul for ultrasound distance measuring. It can be found in datasheet that it can measure in range from 2cm to 4m. Powering voltage is 5V and current 15mA. It is 4-pin connected. Two for powering. One for recieving pulses from microcontroler (Trig) and the second one for sending the pulses back to microcontroler (Echo). The measuring sequence is: Arduino sends short triggering impuls to sensor -> Sensor measure the distance and send impuls to arduino. Length of the impulse is convert to distance e.g. in cm. All this routine is include in NewPing library.
 +
 +
 +Code example from NewPing library examples- Print the distance in cm on screen
 +<file java NewPingExample.ino>​
 +// ---------------------------------------------------------------------------
 +// Example NewPing library sketch that does a ping about 20 times per second.
 +// ---------------------------------------------------------------------------
 +
 +#include <​NewPing.h>​
 +
 +#define TRIGGER_PIN ​ 12  // Arduino pin tied to trigger pin on the ultrasonic sensor.
 +#define ECHO_PIN ​    ​11 ​ // Arduino pin tied to echo pin on the ultrasonic sensor.
 +#define MAX_DISTANCE 200 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.
 +
 +NewPing sonar(TRIGGER_PIN,​ ECHO_PIN, MAX_DISTANCE);​ // NewPing setup of pins and maximum distance.
 +
 +void setup() {
 +  Serial.begin(9600);​ // Open serial monitor at 115200 baud to see ping results.
 +}
 +
 +void loop() {
 +  delay(50); ​                     // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.
 +  unsigned int uS = sonar.ping();​ // Send ping, get ping time in microseconds (uS).
 +  Serial.print("​Ping:​ ");
 +  Serial.print(uS / US_ROUNDTRIP_CM);​ // Convert ping time to distance in cm and print result (0 = outside set distance range)
 +  Serial.println("​cm"​);​
 +}
 +</​file>​
 +
 +
 +----
 +
  
en/distance.txt ยท Last modified: 2018/01/29 10:12 (external edit)