Skip to content

Instantly share code, notes, and snippets.

@DiegoTc
Created August 11, 2014 03:06
Show Gist options
  • Save DiegoTc/29d78e16a14a33b32f07 to your computer and use it in GitHub Desktop.
Save DiegoTc/29d78e16a14a33b32f07 to your computer and use it in GitHub Desktop.
Bone101 Tutorial
<h1 style="font-size: 2em; font-family: Arial, Verdana, Helvetica, sans-serif; color: rgb(180, 162, 121); line-height: normal;">Demo: Maxbotic Ultrasonic Sensor</h1><p style="font-size: 1.1em; line-height: 1.3em; color: rgb(82, 82, 82); font-family: Arial, Helvetica, Verdana, sans-serif;">The&nbsp;<a href="http://www.maxbotix.com/Ultrasonic_Sensors/MB1020.htm" style="color: rgb(222, 114, 36);">LV-MaxSonar-EZ2 High Performance Sonar Range Finder</a>&nbsp;provides very short to long-range detection and ranging, in an incredibly small package. The sonar detects objects from 0-254 inches and provides sonar range information from 6-inches out to 254-inches with 1-inch resolution.</p><i style="color: rgb(82, 82, 82); font-family: Arial, Helvetica, Verdana, sans-serif; font-size: 12px;">Note: Each time after the Sonar is powered up, it will calibrate during its first read cycle. The sensor uses this stored information to range a near object. It is important that objects not be close to the sensor during this calibration cycle. The best sensitivity is obtained when it is clear for fourteen inches, but good results are common when clear for at least seven inches. If an object is too bear the Sonar during the calibration cycle, the sensor may then ignore the objects at that distance. To calibrate the LV-MAX Sonar, cycle power then command a read cycle.</i><br style="color: rgb(82, 82, 82); font-family: Arial, Helvetica, Verdana, sans-serif; font-size: 12px;"><br style="color: rgb(82, 82, 82); font-family: Arial, Helvetica, Verdana, sans-serif; font-size: 12px;"><span style="color: rgb(82, 82, 82); font-family: Arial, Helvetica, Verdana, sans-serif; font-size: 12px;">The AN pin outputs a voltage with a scaling factor of (V</span><sub style="color: rgb(82, 82, 82); font-family: Arial, Helvetica, Verdana, sans-serif; line-height: normal;">cc</sub><span style="color: rgb(82, 82, 82); font-family: Arial, Helvetica, Verdana, sans-serif; font-size: 12px;">/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.&nbsp;</span>
<br class="Apple-interchange-newline"><img align="right" width="60%" src="http://beagleboard.org/static/uploads/VD%20Ultrasonic%20Sensor.PNG" style="color: rgb(82, 82, 82); font-family: Arial, Helvetica, Verdana, sans-serif; font-size: 12px;"><br style="color: rgb(82, 82, 82); font-family: Arial, Helvetica, Verdana, sans-serif; font-size: 12px;"><br style="color: rgb(82, 82, 82); font-family: Arial, Helvetica, Verdana, sans-serif; font-size: 12px;"><h2 style="font-size: 1.5em; font-family: Arial, Verdana, Helvetica, sans-serif; color: rgb(180, 162, 121); margin: 5px 0px; line-height: normal;">Build and execute instructions</h2><ul style="color: rgb(82, 82, 82); font-family: Arial, Helvetica, Verdana, sans-serif; font-size: 12px;"><li>Connect the "GND" pin from the sensor to P9_1 of the board</li><li>Connect the "+5" pin from the sensor to P9_3 of the board</li><li>Connect the 1.2kohm resistor to the AN pin of the supersonic sensor.</li><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><li>Connect P9_40 of BeagleBone in series with the 3k ohm and 1.k ohm resistor.</li><li>Click "Run" on the code card and it will output the distance, in inches, that the sensor is detecting... updating every 5 seconds</li><li>Move the sensor nearer to or farther from an object to see the change in distance</li></ul>
var b = require('bonescript');
var analogVoltage = 0;
/* Check the sensor values every 2 seconds*/
setInterval(read, 2000);
function read(){
b.analogRead('P9_40', printStatus);
}
function printStatus(x) {
var distanceInches;
analogVoltage = x.value*1.8; // ADC Value converted to voltage
console.log('x.value = ' + analogVoltage);
distanceInches = analogVoltage / 0.00699;
console.log("There is an object " +
parseFloat(distanceInches).toFixed(3) + " inches away.");
}
<iframe src="//www.youtube.com/embed/SFdKIRi7T3s" width="640" height="360" frameborder="0"></iframe>
<span style="font-weight: bold;">Demo: Maxbotic Ultrasonic Sensor</span><div><br></div><div><span style="color: rgb(82, 82, 82); font-family: Arial, Helvetica, Verdana, sans-serif; font-size: 13px; line-height: 17.15999984741211px;">The&nbsp;</span><a href="http://www.maxbotix.com/Ultrasonic_Sensors/MB1020.htm" style="color: rgb(222, 114, 36); font-family: Arial, Helvetica, Verdana, sans-serif; font-size: 13px; line-height: 17.15999984741211px; background-color: rgb(255, 255, 255);">LV-MaxSonar-EZ2 High Performance Sonar Range Finder</a><span style="color: rgb(82, 82, 82); font-family: Arial, Helvetica, Verdana, sans-serif; font-size: 13px; line-height: 17.15999984741211px;">&nbsp;provides very short to long-range detection and ranging, in an incredibly small package.&nbsp;</span><br></div>
Maxbotic Ultrasonic Sensor
Demo Info
Build
Code
Video
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment