1 <?xml version="1.0" encoding="ISO-8859-1"?>
2 <?xml-stylesheet type="text/xsl" href="helma.xsl"?>
3 <xmlroot xmlns:hop="http://www.helma.org/docs/guide/features/database">
4 <hopobject id="2819" name="Ultrasonic_Sensor" prototype="Page" created="1372690591672" lastModified="1387489017908">
5 <hop:parent idref="2471" prototyperef="Page"/>
6 <is_xhtml type="boolean">true</is_xhtml>
7 <http_remotehost>192.94.94.105</http_remotehost>
8 <http_language>en-US,en;q=0.8,fr;q=0.6</http_language>
9 <uri>Ultrasonic_Sensor</uri>
10 <http_browser>Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36</http_browser>
11 <time type="date">19.12.2013 15:36:57 CST</time>
12 <hopsession>192.94.94.9otttzsp6btn</hopsession>
13 <body><script src="/static/bonescript-demo.js"></script>
\r
14 <div id='side-menu' class="t3_sidebar">
\r
15 <ul class="left-menu"><strong>Navigation</strong>
\r
16 <li><a href="/static/side-menu.html">Menu contents</a></li>
\r
19 <div class="t3_content_1"><div id='connect-status'></div><div id="content_child">
\r
20 <h1>Demo: Maxbotic Ultrasonic Sensor</h1>
\r
21 <p>The <a href="http://www.maxbotix.com/Ultrasonic_Sensors/MB1020.htm">LV-MaxSonar-EZ2 High Performance Sonar Range Finder</a> provides very short
\r
22 to long-range detection and ranging, in an incredibly small package. The sonar
\r
23 detects objects from 0-254 inches and provides sonar range information from 6-inches
\r
24 out to 254-inches with 1-inch resolution.
\r
26 <i>Note: Each time after the Sonar is powered up, it will calibrate
\r
27 during its first read cycle. The sensor uses this stored
\r
28 information to range a near object. It is important that objects
\r
29 not be close to the sensor during this calibration cycle. The
\r
30 best sensitivity is obtained when it is clear for fourteen
\r
31 inches, but good results are common when clear for at least
\r
32 seven inches. If an object is too bear the Sonar during the calibration
\r
33 cycle, the sensor may then ignore the objects at that distance.
\r
34 To calibrate the LV-MAX Sonar, cycle power then command a read
\r
35 cycle.</i><br><br>
\r
37 The AN pin outputs a voltage with a scaling factor of (V<sub>cc</sub>/512) per inch. Since the AIN pin has a maximum voltage capacity of 1.8V, we will set a voltage divider to account for that difference. With the voltage divider, a supply of 5V yields ~6.99mV/in. and 3.3V yields ~4.57mV/in.
\r
43 <button class="dynlink" onclick="demoRun('code')">run</button>
\r
44 <button class="dynlink" onclick="demoRestore('code')">restore</button>
\r
46 <pre id="code" class="use-editor" style="height:310px;">
\r
47 var b = require('bonescript');
\r
48 var analogVoltage = 0;
\r
50 /* Check the sensor values every 2 seconds*/
\r
51 setInterval(read, 2000);
\r
54 b.analogRead('P9_40', printStatus);
\r
57 function printStatus(x) {
\r
59 analogVoltage = x.value*1.8; // ADC Value converted to voltage
\r
60 console.log('x.value = ' + analogVoltage);
\r
61 distanceInches = analogVoltage / 0.00699;
\r
62 console.log("There is an object " +
\r
63 parseFloat(distanceInches).toFixed(3) + " inches away.");
\r
66 <div readonly id='console-output' style="height:100px;"></div>
\r
67 <br></br>
\r
68 <img align="right" width="60%" src="http://beagleboard.org/static/uploads/VD%20Ultrasonic%20Sensor.PNG"/>
\r
69 <br></br>
\r
70 <h2>Build and execute instructions</h2>
\r
72 <li>Connect the "GND" pin from the sensor to P9_1 of the board</li>
\r
73 <li>Connect the "+5" pin from the sensor to P9_3 of the board</li>
\r
74 <li>Connect the 1.2kohm resistor to the AN pin of the supersonic sensor.</li>
\r
75 <li>Connect the 3k ohm resistor in series with the 1.2k ohm resistor and tie the bottom to ground, as shown in the diagram.</li>
\r
76 <li>Connect P9_40 of BeagleBone in series with the 3k ohm and 1.k ohm resistor.</li>
\r
77 <li>Click "Run" on the code and it will output the distance, in inches, that the
\r
78 sensor is detecting... updating every 5 seconds</li>
\r
79 <li>Move the sensor nearer to or farther from an object to see the change in distance</li>
\r
82 <h2>See also</h2>
\r
83 <h3>Related functions</h3>
\r
85 <li><a href="/Support/BoneScript/#require">require</a></li>
\r
86 <li><a href="/Support/BoneScript/analogRead/">analogRead</a></li>
\r
87 <li><a href="http://beagleboard.org/Support/BoneScript/#timers">setInterval</a></li>
\r
90 <h3>Where to buy</h3>
\r
92 <li> <a href="http://elinux.org/CircuitCo:BeagleBone_Breadboard#Distributors">BreadBoard</a></li>
\r
93 <li><a href="https://www.sparkfun.com/products/11026">Jumper wires</a></li>
\r
94 <li> <a href="https://www.sparkfun.com/search/products?sort_by=relevance%7Casc&per_page=500&term=resistor">Resistors</a></li>
\r
95 <li><a href="http://www.adafruit.com/products/980">Ultrasonic sensor</a></li>
\r
98 <h2>See it in action</h2>
\r
99 <iframe width="560" height="315" src="//www.youtube.com/embed/SFdKIRi7T3s" frameborder="0" allowfullscreen></iframe></body>
100 <pseudoparent idref="2471" prototyperef="Page"/>
101 <http_referer>http://beagleboard.org/support/BoneScript/Ultrasonic_Sensor/edit</http_referer>
102 <http_host>beagleboard.org</http_host>
103 <user>jessica.lynne.callaway@gmail.com</user>