Hardware Reference
In-Depth Information
Solution
To make this recipe, you will need:
▪ Breadboard and jumper wires (see
“Prototyping Equipment”
)
▪ LV-MaxSonar-EZ1 Sonar Range Finder (see
“Miscellaneous”
)
All you have to do is wire the EZ1 to one of the Bone's
analog-in
pins, as shown in
Fig-
WARNING
Make sure not to apply more than 1.8 V to the Bone's
analog-in
pins, or you will likely dam-
age them. In practice, this circuit should follow that rule.
Figure 2-11. Wiring the LV-MaxSonar-EZ1 Sonar Range Finder to the
P9_33
analog-in port
Example 2-6
shows the code that reads the sensor at a fixed interval.
Example 2-6. Reading an analog voltage (ultrasonicRange.js)
#!/usr/bin/env node
var
b
=
require
(
'bonescript'
);
var
ms
=
250
;
// Time in milliseconds
setInterval
(
readRange
,
ms
);