Maxbotix Ultrasonic Transducer as Rangefinder

I have been attempting to build a robot on a VERY limited budget. Rangefinding was a requirement for the robot to identify objects around itself. I ordered the Maxbotix UT from sparkfun (Ultrasonic Transducer - Maxbotix UT - SEN-08505 - SparkFun Electronics). It was my understanding that a transducer could both send and receive the ~40kHz signal. I tried to fire off a ping from the sensor by grounding one of the two pins and then toggling the other pin from low to high with a 2 microsecond interval. Then I switch the non-grounded pin to an input look for some voltage spike through the analog input. I can't seem to get any response at all and I really have no idea if the sensor is even creating the ultrasonic sound as I cant hear it. I could really use some suggestions here. Am I doing something wrong? Thanks in advance.

Well, that's the transducer used on the Maxbotics EZ1 but you will have to include more parts to make it work as a ranger. Google 'ultrasonic rangefinder circuit' for more info.

I read around more and found several circuits including the one on the Maxbotix EZx modules. From what I can tell, the circuits use some kind of a PIC to drive the 40kHz transducer at the appropriate frequency and then some transistor trigger that activates when the echo is heard. I was hoping to do all of this with the arduino as it has the capability of PWM for driving the transducer and analog inputs to view the return echo. I am trying to opt for a software approach rather than hardware. Am I missing something or would this be possible?

Here is the code I am currently trying to use. I calculated that to get 40kHz I need to pulse on for 13 microseconds and then off for 12 microseconds for a period of 25 microseconds. Then I am setting a threshold value of 10 to allow the transducer to settle down before listening for the return echo. I have observed that when just sending all data from the transducer across the serial channel there is definitely a change when having the sensor open to the air and ambient sound and when I cover it up, so I think that part is working. Thoughts, suggestions, help?

int ultraSoundR = 14; // Ultrasound signal pin right
int ultraSoundL = 15; // Ultrasound signal pin left
int valL;
int valR;
int timecount;

void setup() {
  beginSerial(9600);                  // Sets the baud rate to 9600
  pinMode(ultraSoundR, INPUT);        // Sets the analog pin as input
  pinMode(ultraSoundL, INPUT);        // Sets the analog pin as input
}


void loop() {
  
  pinMode(ultraSoundR, OUTPUT);        // Sets the analog pin as output
  pinMode(ultraSoundL, OUTPUT);        // Sets the analog pin as output
  digitalWrite(ultraSoundL, LOW);      // Set left pin as ground
  
  for (int i=0; i <= 0; i++){
    digitalWrite(ultraSoundR, LOW); // Send low pulse
    delayMicroseconds(12); // Wait for 12 microseconds
    digitalWrite(ultraSoundR, HIGH); // Send high pulse
    delayMicroseconds(13); // Wait for 13 microseconds
    digitalWrite(ultraSoundR, LOW); // Holdoff
  }
  
  /* Listening for echo pulse
   * -------------------------------------------------------------------
   */
  valR = 20;
  timecount = 0;
  
  pinMode(ultraSoundR, INPUT);        // Sets the analog pin as input
  pinMode(ultraSoundL, INPUT);        // Sets the analog pin as input
  
  while(valR > 10) {
    valR = analogRead(ultraSoundR);    // Append signal value to valR
    valL = analogRead(ultraSoundL);    // Append signal value to valL
  }
  
  while(valR < 10) {
    valR = analogRead(ultraSoundR);    // Append signal value to valR
    valL = analogRead(ultraSoundL);    // Append signal value to valL
    
    timecount = timecount + 1;
  }
  
  Serial.println(timecount);
  
  delay(100);
  
}

I worked on this over the weekend and still can't get it to work. Any ideas? I think the pwm timings are correct but I just can't get any response when viewing the analog input over the serial connection :-/

From what I understand this loop doesn`t run at all

for (int i=0; i <= 0; i++){
    digitalWrite(ultraSoundR, LOW); // Send low pulse
    delayMicroseconds(12); // Wait for 12 microseconds
    digitalWrite(ultraSoundR, HIGH); // Send high pulse
    delayMicroseconds(13); // Wait for 13 microseconds
    digitalWrite(ultraSoundR, LOW); // Holdoff
  }

if you change it to i <=1 it should run once.

@webtek23
This code work for me. I get info in the serial monitor. I change the numbers of the pins. I'm using an arduino decimilia. I use the pin number 3 and 4 in the analog input. Did you calibrate the sonar and are you getting a correct value or only it is a reference?
Roberto

Hi webtek23,

I'm also very interested in making this sensor work with Arduino.

Did you manage to do it, in the end?

Adam

I've been playing a little with ultrasonic sensors too lately, and I was wondering about the same ting, IE if one can use the transducer as a receiver or vice versa. Btw I don't know. I got hold of a separate transducer and receiver, without any particular information about them at all. They seem simiilar to the maxbotix one. (links: http://www.electrokit.se/akustiska-element-ultraljud-ultrasonic-transducer-sandare_41000914 and http://www.electrokit.se/akustiska-element-ultraljud-ultrasonic-transducer-mottagare_41000915).

For the transtmitter I first made a 555 ccircuit at 40kHz, but eventually resorted to just excite it with one pulse of about 12 us, and a simple H-bridge at 5 V.

For the receiver I had to amplify the signal by quite a lot. I just made some 2-3 simple-as-possible stages of op-amps (TLC064) with about 100x amplification pr. stage( and scoping the outputs, until (kinda) satisfactory. Both 2 or 3 stages work, though I still gotta finetune it. 2 stages were good for about 30cm distance, 3 stages say 50cm but also very noisy. I'm guessing the reciever has a built-in filter of some kind for 40 kHz, because I did'nt make any. I can draw a circuit later if requested.

Anyway, anyone knows if its possible to use either one of the receiver/transmitter as both?

Well, if you have a receiver/transmitter, then I'm not sure. However, you can buy a "transducer" (also from Maxbotix), which does both:

Hope this helps.

raron,

Could you please draw or describe your circuit very briefly?

I'd like to try it out with Arduino, too. Thanks a lot!

Adam

Adam777:

I uploaded a schematic here:

Sorry for the crappy quality. I was hoping it would be a bit better, using .png format and all.. but the size got reduced.

The potentiometer was a trimpot, adjusted to about 32 k from ground to the viper, and about 17k from viper to + Vcc (50k pot, well, 49k). Its basically the last op-amp just used as a comparator, giving a pulse at the (hopefully) detected echo.

The R1-R2 divider value is not critical, as long as they are equal. BTW the op amp used was TL064 (not TLC 064, if that even exists).
The capacitors C1 and C2 are not critical either. My arduino clone has a 47uF for across its power, as well as 100nF, I just put it in the schematics. I did use an additional 100nF.

The simple H-bridge at the top must NOT have an input signal between say 0.7V and 4.3V (Vcc-0.7V), or else both/all transistors are on, and some will give in.. The input signal must be either below 0.7V, or above 4.3V. As in either 0 or 1 using 5V logic.
Also, as noted in the schematics, do not use more than 5V (actually, the logic level used on the digital output) at the emitters of the PNPs. I use a 5V arduino clone. I guess a simple addition of another inverter stage with an NPN could improve this, but I haven't tested that yet. The ultrasonic transmitter should work up to 20V according to specs, so it would probably improve range and sensitivity if done. But also add a bit complexity.

Suggestions are welcome for improvements. And I haven't really fine tuned it yet. But I just tested the circuit as-is, and using a mirror tile (flat glass surface about 30cm by 30cm) I was able to get a distance measurement up to 150-ish cm. I'd go further, except its getting hard to direct the flat surface with the correct angle when it is a longer distance away. Also, its kinda not easy to do that while reading the computer screen, also some distance away :stuck_out_tongue:

Oh yeah, here's my code. Kinda based on the Ping))) example, except I changed the method used a bit. It might not have been neccesary though. I just haven't tested it with the pulseIn method thats all.

/* Ultrasonic transmitter/receiver test
   2010.04.28 raron
 
*/

const int pingOutPin = 7;   // Connected to the simple H-bridge and the ultrasonic transmitter
const int pingInPin = 8;    // Connected to the ultrasonice receiver via op-amp circuit

const long timeout = 40000; // us, gives up listening after a distance of 6.89 meters one way

void setup()
{
  pinMode(pingInPin,INPUT);
  pinMode(pingOutPin, OUTPUT);
  digitalWrite(pingOutPin, LOW);
  digitalWrite(pingInPin, LOW); // no internal pullup

  Serial.begin(9600);
}

void loop()
{
  long pingStartTime, echoTime, inches, cm;
  boolean echo;
  digitalWrite(pingOutPin, HIGH);
  pingStartTime = micros();
  delayMicroseconds(12);
  digitalWrite(pingOutPin, LOW);

  do {
    echo = digitalRead(pingInPin);
    echoTime = micros() - pingStartTime;
  } while (echo == false && echoTime<timeout);

  // convert the time into a distance
  inches = microsecondsToInches(echoTime);
  cm = microsecondsToCentimeters(echoTime);
  
  Serial.print(inches);
  Serial.print("in, ");
  Serial.print(cm);
  Serial.print("cm");
  Serial.println();
  
  delay(100);
}

long microsecondsToInches(long microseconds)
{
  // According to Parallax's datasheet for the PING))), there are
  // 73.746 microseconds per inch (i.e. sound travels at 1130 feet per
  // second).  This gives the distance travelled by the ping, outbound
  // and return, so we divide by 2 to get the distance of the obstacle.
  // See: http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf
  return microseconds / 74 / 2;
}

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;
}

Kinda cool that it worked just like that. Almost like magic :stuck_out_tongue:

As for using the receiver as a transmitter and vice-versa, I guess I could just test and swap them, but I don't want to destroy them either...

Thanks raron,

Very cool! I cannot be online during the weekend, so will go thru it next week.

Thanks once more for the detailed description!
Adam

Hey Raron,
I will be building your sensor tonight, and I was comparing the data sheets for a bc558 & 557. I found the 557 can Handel more voltage. Being unable to find a 558 in my area is it possible to use a 557 in it's place?

Thanks,
Jeff

Oh and another thought, because the transmitter uses an h bridge could I use say a l293d. Iknow it's a motor driver but it is an hbridge.

is it possible to use a 557 in it's place?

Yes, I think they are pretty similar, except for the voltage limits as you noted. Beware, as noted for my circuit, do not use more than 5V!

Oh and another thought, because the transmitter uses an h bridge could I use say a l293d. Iknow it's a motor driver but it is an hbridge.

If it is a H-bridge it should work. Never used any before though :slight_smile: It depends on how it is controlled, you might have to change the sketch and connections slightly to swap the direction as needed. I don't have a pinout for the one you mention.

I was tidying up some components and stuff today (well, night actually), and I was about to dismantle my breadboard ultrasonic sensor. I haven't played with it since this thread basically.

Well I thought it was about time to simply switch the "transmitter" and "receiver", and see what happened. And it worked! Seemingly about the same. Not tested extensively though (And yeah, now I have dismantled it).

And the underside of the sensors (now I forgot which is which...):