JComCamUserManual.pdf (213604Bytes)
XLSonarDatasheet.pdf (416170Bytes)
Ok, here's the deal. Today, I got my fantastically awesome order from sparkfun. It included:
The Maxibotics XL-EZ4 Rangefinder
I managed to soder some wires to three pins of the EZ4 without burning the house down. I got GND, +V, and pin 2 (Digital signal)
I even managed to get some programming on my Arduino to work with it (Modded the PING))) library). However, the debug terminal does not go to 0 cm, although the sensor supposedly detects 0-range obstacles. I have tried using the number it came with, 29, and the number reccomended for conversion of time to distance by Maxibotics, 58. 58 let it get closer to 0, but I fear it messed up the actual length of a centimeter, as interpreted by the Arduino. Here is the code, with the number I need help with in bold and italic.
This sketch reads a EZ4 ultrasonic rangefinder and returns the distance to the closest object in range. To do this, it sends a pulse to the sensor to initiate a reading, then listens for a pulse to return. The length of the returning pulse is proportional to
the distance of the object from the sensor.
The circuit:
* +V connection of the EZ4 attached to +5V
* GND connection of the Ez4 attached to ground
* SIG connection of the Ez4 attached to digital pin 10
http://www.arduino.cc/en/Tutorial/Ping
*/
const int sonarPin = 10;
void setup() {
// initialize serial communication:
Serial.begin(4800);
}
void loop()
{
// establish variables for duration of the ping,
// and the distance result in centimeters:
long duration,cm;
// Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
pinMode(sonarPin, OUTPUT);
digitalWrite(sonarPin, LOW);
delayMicroseconds(2);
digitalWrite(sonarPin, HIGH);
delayMicroseconds(5);
digitalWrite(sonarPin, LOW);
// The same pin is used to read the signal from the EZ4: a HIGH
// pulse whose duration is the time (in microseconds) from the sending
// of the ping to the reception of its echo off of an object.
pinMode(sonarPin, INPUT);
duration = pulseIn(sonarPin, HIGH);
// convert the time into a distance
cm = microsecondsToCentimeters(duration);
Serial.print(cm);
Serial.print("cm");
Serial.println();
delay(100);
}
long microsecondsToCentimeters(long microseconds)
{
// The speed of sound is 340 m/s or 29 microseconds per centimeter.
// The ping travels out and back, so to find the distance of the
// object we take half of the distance travelled.
return microseconds / 29 / 2;
}
(29 gives me a minimum centimeter reading of 19, while 58 drops it to 9. which number do I use?)
Also, I can't seem to get the hang of serial stuff that I need for control of the camera. Any Arduino fans out there that can give me some pointers?