Distance measurement using ultrasonic transceiver

Discussion in 'The Projects Forum' started by Pratyay, Jul 4, 2019.

  1. Pratyay

    Thread Starter New Member

    Jul 4, 2019
    11
    0
    Hello, I am working on a project of finding distance using ultrasonic transceivers. I am going to use an arduino as a microcontroller. I will be designing the transmitter and receiver circuits, whose links I have given below. So i have two specific doubts and i will be very thankful if you can spare some time and answer them:
    1) For testing, I had given a burst of 40 kHz of square waveform using a function generator to the transducer and i also had connected the DSO probes in parallel with the transducer pins. But I didn't get a proper echo waveform. Is it because the echo cannot be detected directly and I first need to receive it through the receiver circuit. (The voltage through the Function generator was 9.5 V pk-pk)

    2) Is it possible to connect both the transmitter and receiver waveform in parallel with the transducer and switch the circuits using arduino after i get the echo properly?

    Links for:
    1) Transmitter circuit: https://www.gadgetronicx.com/ultrasonic-transmitter-circuit-ic555/
    2) Receiver circuit : https://www.gadgetronicx.com/ultrasonic-receiver-circuit/
    3) Datasheet of sensor that I am using : (attatched)
     
  2. AlbertHall

    AAC Fanatic!

    Jun 4, 2014
    7,902
    1,949
    1. I think you need the gain of the receiver circuit to be able to see the reflections.
    2. There are circuits which do this using only one transducer so it is possible.
     
    Pratyay likes this.
  3. Pratyay

    Thread Starter New Member

    Jul 4, 2019
    11
    0
    Thank you very much, Ill do the further experiments and keep this thread updated.....

    And one more thing, i have made a typing mistake, its 'transmitter and receiver circuits' not 'transmitter and receiver waveforms'. Extremely sorry for that though.
     
  4. ericgibbs

    Moderator

    Jan 29, 2010
    8,101
    1,642
    hi,
    With that TX circuit you will not be able to measure range, it is a Astable 40kHz osc, so the receiver will have no time of flight information.

    E
     
    JohnInTX likes this.
  5. BobTPH

    Senior Member

    Jun 5, 2013
    1,802
    471
    Sure ot can. You send a short burst then measure elapsed time before the echo.

    Bob
     
    JohnInTX and Pratyay like this.
  6. ericgibbs

    Moderator

    Jan 29, 2010
    8,101
    1,642
    The circuit diagram the TS has posted does not show any way of burst transmission, that's the point I am bringing to his attention.
    He needs to add additional circuitry.
     
    JohnInTX and Pratyay like this.
  7. MrChips

    Moderator

    Oct 2, 2009
    18,836
    6,024
    Is this a school course project?
     
  8. Ylli

    Active Member

    Nov 13, 2015
    686
    201
    Rather than sending a burst and seeing how long it takes to come back, you can use a continuous output frequency sweep method. Sweep the ultrasonic signal over a signal range, and compare the frequency of the echo with the frequency currently being transmitted. Knowing the sweep rate and the frequency difference it is a simple matter to determine the distance.
     
    Pratyay likes this.
  9. Pratyay

    Thread Starter New Member

    Jul 4, 2019
    11
    0
    I
    Yes this is exactly what I was going to do using an arduino. Thank you!
     
  10. Pratyay

    Thread Starter New Member

    Jul 4, 2019
    11
    0
    I am going to power the transmitter circuit ON and OFF using an arduino, so that will be acting as a burst signal. Thank you!
     
  11. Pratyay

    Thread Starter New Member

    Jul 4, 2019
    11
    0
    Hello, thank you for your suggestion, it is indeed a nice method, but i have to do it using burst - echo method. Nevertheless, please can you share a link or any file from where I can learn about the frequency sweep method?
    Thanks!
     
  12. ericgibbs

    Moderator

    Jan 29, 2010
    8,101
    1,642
    hi Pratyay,
    The transducer datasheet that you posted shows a resonant 40kHz transducer response, refer to page #3, using frequency sweeping will be a problem.

    E
     
    Last edited: Jul 5, 2019
  13. Alec_t

    AAC Fanatic!

    Sep 17, 2013
    9,927
    2,397
    So this is a school/college assignment?
     
  14. Pratyay

    Thread Starter New Member

    Jul 4, 2019
    11
    0
    Not exacty, its an internship project
     
  15. Pratyay

    Thread Starter New Member

    Jul 4, 2019
    11
    0
    okay so I did as follows:
    1) I connected the I/O pin of the sensor to the trigger pin (pin 3) of arduino from which i am giving a burst, also this pin is connected to the ground of receiving circuit.
    2) I connected the output of receiving circuit to arduino pin A0.
    3) I am giving 5 V to the receiving circuit through arduino pin 6.
    4) The ground is common.

    The arduino code is as follows:

    Code (C):
    1. int trig_pin = 3;
    2. int echo_pin = A0;
    3. int power_pin = 6;
    4.  
    5. unsigned long duration;
    6. unsigned long distance;
    7. int i;
    8.  
    9. void setup() {
    10.   // put your setup code here, to run once:
    11.   Serial.begin(9600);
    12.   pinMode(trig_pin, OUTPUT);
    13.   pinMode(echo_pin, INPUT);
    14.   pinMode(power_pin, OUTPUT);
    15. }
    16.  
    17. void loop() {
    18.   for(i=0; i<=7; i++){
    19.   digitalWrite(trig_pin, LOW);
    20.   delayMicroseconds(12.5);
    21.   digitalWrite(trig_pin, HIGH);
    22.   delayMicroseconds(12.5);
    23.   }
    24.  
    25.   digitalWrite(trig_pin, LOW);
    26. //Power ON the receiver circuit
    27. digitalWrite(power_pin, HIGH);
    28. //delayMicroseconds(5);
    29.  
    30.  
    31. //Measures the response from the echo_pin
    32. duration = pulseIn(echo_pin, HIGH);
    33.  
    34. //Calculating the distance
    35. distance = duration*0.000343/2;
    36.  
    37. Serial.print(duration);
    38. Serial.print(" Distance = ");
    39. Serial.println(distance);
    40.  
    41.   digitalWrite(power_pin, LOW);
    42.   delay(500);
    43.  
    44. }
    Mod edit: code tags

    Please can you go through it and see what is wrong as on the serial monitor i am getting just on value irrespective of the distance from the sensor. Is it because there is some problem with pulseIn received from analog pin? Or is it because i powered the receiving circuit with 5 V instead of 9 V? (Im afraid 9 V might damage my arduino)

    Please help. Any help is appreciated.

    Thanks
     
    Last edited by a moderator: Jul 12, 2019
  16. ericgibbs

    Moderator

    Jan 29, 2010
    8,101
    1,642
    hi P.
    I see that you are generating 8 pulses of 40kHz.?
    Do you have an oscilloscope to check the echo pulse back from a close target.?
    E
     
  17. AlbertHall

    AAC Fanatic!

    Jun 4, 2014
    7,902
    1,949
    The program expects the receiver to immediately functioning from power on. It includes a 100nF capacitor fed by two 4.7M resistors so that's about 0.25 second time constant. You need to check with an oscilloscope just what is being transmitted and what is received as a result.
     
    JohnInTX likes this.
  18. drc_567

    AAC Fanatic!

    Dec 29, 2008
    683
    102
    ... I realize that you are using an Arduino microcontroller. However, in the book listed here:
    "The Quintessential PIC Microcontroller"
    ... by Sid Katzen
    There is an example program that does exactly what you are trying to do. The program sends and receives pulses to an ultrasonic disc, and counts the echo return time from an object. (Towards the end of the book.)
    ... try a library or used book store.
     
  19. Pratyay

    Thread Starter New Member

    Jul 4, 2019
    11
    0
    Hello,
    So there was a problem in the previous receiver circuit, so i have changed the approach. I have found a receiver circuit on the following link: https://www.electronoobs.com/eng_arduino_tut36_sch1.php It has 3 opamps and it amplifies 60 mV sine wave to >3.3 V sine wave.

    And now I have incorporated 2 MOSFETS (IRF 630), one on the transmitter pin and another on the receiver pin so that the two circuits can be isolated whenever required. The circuit figures are attatched below.

    The arduino code is as follows:

    Code ( (Unknown Language)):
    1.  
    2.  
    3. int echo_pin = 2;
    4. int trig_pin = 3;
    5. int transmitter_power = 9; //to power ON the transmitter circuit
    6. int receiver_power = 10; //to power ON the receiver circuit
    7. long start_time, stop_time, dur, dist;
    8. int variable = 0;
    9.  
    10.  
    11. void setup() {
    12.   // put your setup code here, to run once:
    13. Serial.begin(9600);
    14. pinMode(echo_pin,INPUT_PULLUP);
    15. pinMode(trig_pin,OUTPUT);
    16. pinMode(transmitter_power,OUTPUT);
    17. pinMode(receiver_power, OUTPUT);
    18. attachInterrupt(digitalPinToInterrupt(echo_pin), ISR_function, RISING);
    19.  
    20. }
    21.  
    22. void loop() {
    23.   // put your main code here, to run repeatedly:
    24. //delayMicroseconds(100);
    25.  
    26. digitalWrite(transmitter_power, HIGH);
    27. //I've given 9 us delays instead of 12.5 beacause the square waveform eventually
    28. //becomes of 25us because of internal delays of arduino
    29. for(int i=0; i<8; i++){
    30.   digitalWrite(trig_pin, LOW);
    31.   delayMicroseconds(9);
    32.   digitalWrite(trig_pin, HIGH);
    33.   delayMicroseconds(9);
    34. }
    35. digitalWrite(transmitter_power, LOW);
    36.  
    37. start_time=micros();
    38. //Serial.println(start_time);
    39.  
    40. digitalWrite(receiver_power, HIGH);
    41. while(variable == 0){
    42.   //empty
    43. }
    44. if (variable == 1){
    45.   stop_time = micros();
    46.   Serial.print(" ");
    47.   //Serial.print(stop_time);
    48.   //variable = LOW;
    49. }
    50. dur =stop_time-start_time;
    51. Serial.println(dur);
    52.  
    53. digitalWrite(receiver_power, LOW);
    54. delayMicroseconds(1000);
    55. //for(;;){};
    56. }
    57.  
    58. void ISR_function(){
    59. variable = 1;
    60. }
    61.  
    62.  
    I have also attached the output waveforms observed on a DSO. (Green- connected to 'Echo-in' pin of receiver circuit, Yellow- connected to the sensor pins)

    Im still not getting the output properly ( Its showing the 'dur' as 8 and 12 irrespective of the distance from object)

    Please can you try to point out the mistake?
    Are the receiver and transmitter powering circuits using MOSFETs whose images i have attached correct?
    Thank you for sparing your valuable time and helping me!
     
    Last edited: Jul 29, 2019
  20. Alec_t

    AAC Fanatic!

    Sep 17, 2013
    9,927
    2,397
    I'm no programmer, but it seems to me that switching on the receiver power could somehow be causing an immediate interrupt, which then sets variable to 1 and stops the timer.
    The receiver circuit in the link has no supply decoupling and has very high value input bias resistors, so is prone to interference pick-up. It is possible that it creates a spurious output pulse at switch-on.
     
Loading...