Hello,
I recently purchased two LV-Maxbotix EZ4 sensors maxbotix.com/uploads/MB1200- … asheet.pdf which I all ready had in possession. The sensors are used on an autonomous robot to avoid obstacles. The XL-EZ0 is used in the front of the robot while the two EZ4 sensors are used on the right and left side respectively.
I am hoping to run them sequentially to obtain range values as described by the following link from the Maxbotix website,
maxbotix.com/uploads/Chainin … oping_.pdf
I have connected the hardware as described in the schematic. The “pulling RX high” instructions however are unclear to me. According to my interpretation, I have connected the RX pin of the first/front Ultrasonic Sensor as a digital OUTPUT and turning it HIGH to pull RX pin High as you will see in my code posted below. After doing so, the front,right, left readings I get are very inconsistent. I am aware that a voltage scaling factor is required for analog readings. I will add those once i get readings that make sense.
int strobetime = 20; // in microseconds
int frontUSPin = 8; // front US pin value read through Analog 8
int rightUSPin = 9; // right US pin value read through Analog 9
int leftUSPin = 10; // left US pin value read through Analog 10
int frontUSswitch = 31 ;// power switch to "strobe" the RX pin of the first (front) US pin
int frontdistRead = 0;//defining variables to collect values
int rightdistRead = 0;
int leftdistRead = 0;
int frontdistVal = 0;
int rightdistVal = 0;
int leftdistVal = 0;
void setup() {
pinMode(frontUSswitch, OUTPUT);// define the front US pin as an OUTPUT
pinMode(frontUSPin, INPUT); // defining US signal pins as INPUT
pinMode(rightUSPin, INPUT);
pinMode(leftUSPin, INPUT);
digitalWrite(frontUSswitch, LOW); // start the program with the front Switch OFF
Serial.begin(9600); //This opens up a serial connection
}
void loop(){
digitalWrite (frontUSswitch, HIGH); // Pull RX pin HIGH
delayMicroseconds (strobetime);// for 20uS
frontdistRead= analogRead (frontUSPin);
frontdistVal = frontdistRead; // needs Voltage scaling factor
rightdistRead = analogRead (rightUSPin);
rightdistVal = rightdistRead; // needs Voltage scaling factor
leftdistRead= analogRead (leftUSPin);
leftdistVal = leftdistRead; // needs Voltage scaling factor
Serial.print("frontdistVal:");// prints values in serial COM window
Serial.print(frontdistVal);
Serial.print(" | rightdistVal:");
Serial.print(rightdistVal);
Serial.print(" | leftdistVal:");
Serial.print(leftdistVal);
Serial.println();
delay (1000);
}
Below are the readings I get from the Serial monitor. The front,right and left obstacles are 8 inches away from the sensors. As you can see there is a spike in readings from the front sensor, which I suspect is due to incorrect “strobing”
frontdistVal:752 | rightdistVal:11 | leftdistVal:11
frontdistVal:673 | rightdistVal:11 | leftdistVal:11
frontdistVal:20 | rightdistVal:11 | leftdistVal:11
frontdistVal:20 | rightdistVal:12 | leftdistVal:11
frontdistVal:751 | rightdistVal:11 | leftdistVal:11
frontdistVal:752 | rightdistVal:11 | leftdistVal:11
frontdistVal:752 | rightdistVal:11 | leftdistVal:11
frontdistVal:25 | rightdistVal:11 | leftdistVal:11
frontdistVal:20 | rightdistVal:11 | leftdistVal:11
frontdistVal:20 | rightdistVal:11 | leftdistVal:11
frontdistVal:752 | rightdistVal:11 | leftdistVal:11
frontdistVal:752 | rightdistVal:11 | leftdistVal:11
frontdistVal:24 | rightdistVal:11 | leftdistVal:11
frontdistVal:20 | rightdistVal:11 | leftdistVal:11
frontdistVal:20 | rightdistVal:11 | leftdistVal:11
frontdistVal:20 | rightdistVal:11 | leftdistVal:12
frontdistVal:752 | rightdistVal:11 | leftdistVal:11
frontdistVal:753 | rightdistVal:12 | leftdistVal:11
frontdistVal:61 | rightdistVal:11 | leftdistVal:11
frontdistVal:21 | rightdistVal:11 | leftdistVal:12
frontdistVal:20 | rightdistVal:11 | leftdistVal:11
frontdistVal:662 | rightdistVal:11 | leftdistVal:11
frontdistVal:751 | rightdistVal:11 | leftdistVal:11
frontdistVal:751 | rightdistVal:11 | leftdistVal:12
frontdistVal:22 | rightdistVal:11 | leftdistVal:12
frontdistVal:20 | rightdistVal:11 | leftdistVal:11
frontdistVal:20 | rightdistVal:11 | leftdistVal:11
Any help regarding the code would be greatly appreciated.
Sincerely,
suj10