4 ultrasinics Sr04 on one UNO - How would you involve them?

Hi guys I would like to connect 4 Ultrasonics to one arduino. Have someone code for ? How would you connect them?

Hi,

the simplest version: 2 pins, i.e. trigger and echo, per ultrasonic device. For example, use pin 2+3,4+5,6+7,8+9. I use this code for a single device:

void setupUltrasonic() {  
  pinMode(PIN_US_PWR, OUTPUT);
  pinMode(PIN_US_ECHO, INPUT);
  pinMode(PIN_US_TRIGGER, OUTPUT);
}
int getUltrasonic() {
  digitalWrite(PIN_US_PWR,HIGH);
  digitalWrite(PIN_US_TRIGGER,HIGH);
  delayMicroseconds(10);
  digitalWrite(PIN_US_TRIGGER,LOW);
  long duration = pulseIn(PIN_US_ECHO, HIGH);
  digitalWrite(PIN_US_PWR,LOW);

  return (duration/2) / 29.1;
}

Rewrite to pass the two pins into "getUltrasonic(uint8_t trigger, uint8_t echo)".

Update: Stumbled over this post. Looks like there is a library that simplifies all :slight_smile:

Does this help you? Maybe you can elaborate on what you want to do exactly.
Best