Ultrasonic Sensors connected Echo pins

Hi,
I am using three ultrasonic sensors in a project and want them all to output (echo) to the same pin. I have tried connecting all three echo pins together on a breadboard and then have a separate wire connect to the Arduino, but I get no output. When I connect each echo pin directly to the Arduino, I do get output so I know the sensors are functioning.

I have limited experience with Arduino and I am under a time restraints so I cannot purchase more equipment.

Can this method work or does sharing the input pin cause some sort of issue?
*More info on the project in the comments.

I am using the Adafruit V1 Motor Shield so I only have 6 analog pins available. I want to connect the three ultrasonic sensors, a bluetooth module and a GPS module as part of my project. I am making an object avoiding rover which can navigate to some GPS coordinates sent from a phone connected via Bluetooth.

At the moment I am using a shift register to control the trig pins of each ultrasonic sensor, which is working. I am praying that I can use this shift register to also do the serial transmit (or receiver?) pins for the bluetooth and GPS modules using the SoftSerial Library - This is a problem for later.

While directly connecting the echo pins to the motor shield I also tried debugging the circuit using a LED to see if I could power it while the echo pin output to know that the circuit was working. While I did see output on my serial monitor, the LED did not light up even though the LED was connected in series to the input pin (I used a resistor, so the LED should not have burned out).

Yes, if you do something like this:

not possible without a large amount of custom written code, maybe complete rewrite from scratch.

So you should figure that out now not later.

I'm curious as to why the circuit has a separate ground with a resistor rather than only connecting to the board.

Without R1, and considering the essentially infinite impedance of the uC pin, it would be an open circuit, so no current to forward bias a diode, and an indeterminate (floating) voltage on the pin.

I did this
you will need to connect the trigger pin to the last ones echo pin
the input will pulse once per ultrasound sensor


#define EchoInputCount 4
#define TriggerPin  2
// echo pin will be interrupt 1 on pin 3
#define DelayBetweenPings 50 // it works to about 5 milliseconds between pings

volatile  unsigned long PingTime[EchoInputCount];
volatile int Counter = EchoInputCount;
volatile  unsigned long edgeTime;
volatile  uint8_t PCintLast;
int PinMask = B1000; // pin 3
float Measurements[EchoInputCount];
void PintTimer( )
{
  uint8_t pin;
  static unsigned long cTime;
  cTime = micros();         // micros() return a uint32_t
  pin = PIND >> 3 & 1;      // Quickly get the state of  pin 3
  if (pin)edgeTime = cTime; //Pulse went HIGH store the start time
  else { // Pulse Went low calculate the duratoin
    PingTime[Counter % EchoInputCount] = cTime - edgeTime; // Calculate the change in time  NOTE: the "% EchoInputCount" prevents the count from overflowing the array look up % remainder calculation
    Counter++;
  }
}
void debug()
{
  char S[20];
  static unsigned long PingTimer;
  if ((unsigned long)(millis() - PingTimer) >= 1) {
    PingTimer = millis();
    for (int c = 0; c < EchoInputCount; c++) {
      Serial.print(dtostrf(Measurements[c], 6, 1, S));
    }
    Serial.println();
  }
}

float microsecondsToInches(long microseconds)
{
  return (float) microseconds / 74 / 2;
}

float microsecondsToCentimeters(long microseconds)
{
  return (float)microseconds / 29 / 2;
}

void PingTrigger(int Pin)
{

  digitalWrite(Pin, LOW);
  delayMicroseconds(1);
  digitalWrite(Pin, HIGH); // Trigger another pulse
  delayMicroseconds(10);
  digitalWrite(Pin, LOW);
}

void PingIt()
{
  unsigned long PT[EchoInputCount];
  static unsigned long PingTimer;
  if (Counter >= EchoInputCount) {
    if ( ((unsigned long)(millis() - PingTimer) >= DelayBetweenPings)) {
      PingTimer = millis();
      cli ();         // clear interrupts flag
      for (int c = 0; c < EchoInputCount; c++) {
        PT[c] = PingTime[c];
      }
      sei ();         // set interrupts flag
      for (int c = 0; c < EchoInputCount; c++) {
        if (PT[c] < 43200) Measurements[c] = (float) (microsecondsToCentimeters(PT[c]));
      }
      //      Measurements = (float) (microsecondsToInches(PT));
      debug();
      delay(10);
      PingTrigger(TriggerPin); // Send another ping
      Counter = 0;
     }
  }
}

void setup()
{
  Serial.begin(115200);
  Serial.println("Ping Test");
  pinMode(3, INPUT);
  pinMode(2, OUTPUT);
  attachInterrupt(1, PintTimer, CHANGE );

}

void loop()
{
  PingIt(); // Manage ping data

  if ( ((unsigned long)(millis() - edgeTime) >= 1000)) {
    PingTrigger(TriggerPin); // Send another ping
    Counter = 0;
    delay(100);
  }

}
z

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.