Go Down

Topic: How to determine ultrasonic sensor receive ping from R marked transducer (Read 218 times) previous topic - next topic

bsod666

Hi.
I currently involved in a project of navigation for my rover. I use arduino uno as microcontroller. If u all already seen a video, Self following luggage by Ben Heck Show. I managed to get the receiver code but i try to convert it from serial motor driver to AF_Motor. :smiley-confuse:

The video said, distance is not they wanted. The receiver will only determine which motor to move as it receive ping from transmitter build using the same HC-SR04 ultrasonic sensor. The idea is there will be 1 transmitter module and 1 receiver module with 2 sensors. All the respective transducer from sensors have been removed according to its own functionalities.

My big problem is, is there any indicator that will represent receiver transducer have receive ping from transmitter transducer other than echo duration ? I just want to display something when the receiver receive ultrasonic sound from transmitter. So it will determine whether receiver receive something of being passive waiting for echo. Thats all. With or without NewPing lib i wouldnt mind. Please help me :'(

Thanks

DaveEvans

You could try polling the output of the last op amp on the receive side (not the comparator).  Might get spurious signals.  Read this to understand how the HC SR04 works: https://uglyduck.ath.cx/ep/archive/2014/01/Making_a_better_HC_SR04_Echo_Locator.html  Beware: there are a number of different designs and your board might be identical to the schematic shown.

But if you're trying to duplicate the "self-following luggage," you could also use a radio in the transmit device to communicate with a radio in the receive device (to trigger the receive sensors).  That would have the advantage of eliminating or reducing spurious signal effects.

bsod666

I already tried using distance calc algorithm that i found in obstacle avoiding robot. It uses manual tirigger and pulseIn instead of using NewPing library. I divide those trugger and pulseIn to different board communicate using 433Mhz RF. At transmitter, i send an int value for receiver to start mock trigger eventhough transmitter transducer has been removed and after few microseconds, pulseIn will calculate distance.

Same as transmitter when it turn on, the same algorithm will executed. But the receiver side wont have correct distance measurement. All the values beyond 3000cm.

Do u mean on transmitter side will only do trigger part then receiver side will execute pulseIn?? And they will run in on command sent from transmitter via rf??

DaveEvans

Sorry, I'm having a hard time understanding your second post.

Let me tell you what I have done - it might be useful as a starting point or building block:

I had two Arduinos and called one the "master" and the other a "slave."  The master has a NRF24L01 radio and a HC-SR04.  The slave has a NRF24L01 radio and a modified HC-SR04.

I did not remove the receive transducers from the master HC-SR04.  The master's receive transducer isn't used but there's no point in removing it. 

I  removed the transmit transducer from the slave HC-SR04.  The slave's transmit transducer isn't used, but it might cause spurious signals, so it probably should be removed.

I used the NewPing library.

The system operates like this:

The "master" radio transmits a packet, triggers its HC-SR04 using sonar.ping(), waits "x" seconds, repeats.  The master does not use the value that sonar.ping() returns.

The "slave" waits for a radio packet from the master.  When the slave receives a packet, it triggers its HC-SR04 using sonar.cm(), reports the distance on an LCD (which will be half the distance between the master and slave), and then waits for another packet.



Once you get that simple system working, then add a second HC-SR04 to the slave.  One approach to try with two HC-SR04s:  The slave waits for a packet from the master.  When the slave receives a packet, it triggers both HC-SR04s "manually" (connect both trigger pins to the same output pin and hold HIGH for 10 uS), and then it polls both HC-SR04 echo pins (connected to different input pins), noting the time (in microseconds) that each one transitions from HIGH to LOW.  Or, instead of polling both pins, you could try using interrupts.

I don't think you can use pulseIn for timing two HC-SR04 "at the same time," since it is blocking.  Not sure about NewPing, but in its example with multiple sensors, I think it triggers them one at a time, so I doubt it is appropriate for your situation.



bsod666

Im really new with c programming. What do u meant by polling both input pins? And how is interrupt helps.

Currently i attached a keypad at master. So when certain key is pressed, it will send rf data to slave. As you just said slave will wait for rf data and triggers HC-SR04 using sonar.ping(). Ive tried sonar.cm() but got error. Only sonar.ping_cm() has no error.

Master will repeat the sonar.ping() at x seconds. Do i need to put the same delay value to slave?

DaveEvans

Im really new with c programming. What do u meant by polling both input pins? And how is interrupt helps.
To "poll" a pin is to read its state using digitalRead (as in your case) or analogRead (not your case).  Interrupts...probably best to put that off for a while.

Ive tried sonar.cm() but got error.
That's probably because sonar.cm() is not a valid method in NewPing.

Master will repeat the sonar.ping() at x seconds. Do i need to put the same delay value to slave?
No.  Why would you do that?   In my example and suggested approach, the slave just loops and does nothing except wait for its master's voice...upon hearing which, it pings its sensor(s).

DaveEvans

And how is interrupt helps.
If you want to see how interrupts can help, see post #2 in this topic https://forum.arduino.cc/index.php?topic=494594.0

But this...

Im really new with c programming...
...may make understanding that code rather...challenging.







bsod666

//------------------------------------------------------------------------------------------------------
int readPing1() { // read the ultrasonic sensor distance
  int timeout = 0;
  set = 0;
  digitalWrite(TRIG_PIN1, LOW);                   
  delayMicroseconds(2);
  digitalWrite(TRIG_PIN1, HIGH);
  delayMicroseconds(2);
  digitalWrite(TRIG_PIN1, LOW);
  delayMicroseconds(2);
 
  while ((digitalRead(ECHO_PIN1)) == LOW){
    if((digitalRead(ECHO_PIN1)) == HIGH)
      set = timeout;
    delayMicroseconds(1);
    timeout++;
    if (timeout > 19000)
      break;
  }
  return set;
}
//------------------------------------------------------------------------------------------------------
int readPing2() { // read the ultrasonic sensor distance
  int timeout = 0;
  set = 0;
  digitalWrite(TRIG_PIN2, LOW);                   
  delayMicroseconds(2);
  digitalWrite(TRIG_PIN2, HIGH);
  delayMicroseconds(2);
  digitalWrite(TRIG_PIN2, LOW);
  delayMicroseconds(2);
 
  while ((digitalRead(ECHO_PIN2)) == LOW){
    if((digitalRead(ECHO_PIN2)) == HIGH)
      set = timeout;
    delayMicroseconds(1);
    timeout++;
    if (timeout > 19000)
      break;
  }
  return set;
}



i tried using this and managed to get timer between 2 us reading but it kept giving read1(left side) higher reading than read2(right side) whenever i hover the transmitter left or right. I also tried merging these function in one but still the same. left got 47 and right got 46 something like that.

So how am i gonna make it to decide which direction to move closer??

Go Up