This untrasonic range finder has serial, analog voltage and pulse width ouputs and I can't understand how to use any of them properly.
The serial output apparently gives data in RS232 format (what is that?) and when I just send the data to my computer I get lots of -1 and a few other numbers occasionally.
The analog output is apparently (vcc/512) per inch about 9.8mV per inch for 5v but how can I code fot this?
The pulse width output is 147uS per inch but I would also have no idea of how to code this.
This thread is half a year old... still, I wanted to share the info here. At first, I had thought about using one inverter and MAX232 to go from the EZ3 to RS232 levels and another MAX232 to go back to Arduino levels, but then I decided to try what AWOL suggested and modify some code from SoftwareSerial. They work great now! The code is here:
Got it working first try, but that's got to be beginner's luck.
the hardware interface is extremely simple:
gnd, 5v and wire the PW pin on the EZ-1 to digital pin 5 on the Arduino.
Here's the code:
/*
MaxSonar_EZ1 Test
SummitBid Technologies 2010
*/
const int sonarSensorPin = 5;
const int ledPin = 13;
long value = 0;
int cm = 0;
int inches = 0;
void setup()
{
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
}
void loop()
{
// Read the value from the sensor pin
value = pulseIn(sonarSensorPin, HIGH);
cm = value / 58; // pulse width is 58 microsecs per cm
inches = value / 147; // which is 147 microeconds per inch
Serial.print("cm : inches = ");
Serial.print(cm);
Serial.print(':');
Serial.println(inches);
digitalWrite(ledPin, HIGH);
delay(cm * 10);
digitalWrite(ledPin, LOW);
delay (cm * 10 );
delay(20);
}
So far the only issue I have is with some false positives. Working on it.