How many Ultrasonic sensors (HC SR04 ) can be connected to an Arduino Uno R3 board?

  • As many as you like, but at some point you run out of pins to connect them. – Gerben Dec 20 '16 at 9:53
  • You can make all your ECHO pins Open Drain by adding an N-channel MOSFET or NPN BJT, add a pullup to an input, and then have all your SR04's echoing to the same pin. Since you can really only trigger one at a time anyway you know which one the echo must be coming from even though they're all on the same pin. Note that this would invert the echo signal, so change your pulseIn() to compensate. – Majenko Dec 20 '16 at 10:52

If you look into any example sketch, like this from sparkfun:

 * HC-SR04 Demo
 * Demonstration of the HC-SR04 Ultrasonic Sensor
 * Date: August 3, 2016
 * Description:
 *  Connect the ultrasonic sensor to the Arduino as per the
 *  hardware connections below. Run the sketch and open a serial
 *  monitor. The distance read from the sensor will be displayed
 *  in centimeters and inches.
 * Hardware Connections:
 *  Arduino | HC-SR04 
 *  -------------------
 *    5V    |   VCC     
 *    7     |   Trig     
 *    8     |   Echo     
 *    GND   |   GND
 * License:
 *  Public Domain

// Pins
const int TRIG_PIN = 7;
const int ECHO_PIN = 8;

// Anything over 400 cm (23200 us pulse) is "out of range"
const unsigned int MAX_DIST = 23200;

void setup() {

  // The Trigger pin will tell the sensor to range find
  pinMode(TRIG_PIN, OUTPUT);
  digitalWrite(TRIG_PIN, LOW);

  // We'll use the serial monitor to view the sensor output

void loop() {

  unsigned long t1;
  unsigned long t2;
  unsigned long pulse_width;
  float cm;
  float inches;

  // Hold the trigger pin high for at least 10 us
  digitalWrite(TRIG_PIN, HIGH);
  digitalWrite(TRIG_PIN, LOW);

  // Wait for pulse on echo pin
  while ( digitalRead(ECHO_PIN) == 0 );

  // Measure how long the echo pin was held high (pulse width)
  // Note: the micros() counter will overflow after ~70 min
  t1 = micros();
  while ( digitalRead(ECHO_PIN) == 1);
  t2 = micros();
  pulse_width = t2 - t1;

  // Calculate distance in centimeters and inches. The constants
  // are found in the datasheet, and calculated from the assumed speed 
  //of sound in air at sea level (~340 m/s).
  cm = pulse_width / 58.0;
  inches = pulse_width / 148.0;

  // Print out results
  if ( pulse_width > MAX_DIST ) {
    Serial.println("Out of range");
  } else {
    Serial.print(" cm \t");
    Serial.println(" in");

  // Wait at least 60ms before next measurement

You can see it is used only two pins. So, as long as you can provide power to sensors and pins to it, you can have as much as you like. You can even expand with more IO pins using other electronics or go into some kind of multiplexing.


I am working on a project where I am using 6 sonar sensors in one Arduino Uno !

  • Who's flagging this as "not an answer"? It looks like an answer to me, the answer being "six". It might help to avoid down-votes if you give more details however. – Nick Gammon Mar 28 '17 at 22:35
  • 1
    Who can see an "answer" in this? It's a comment at most, with no information whatsoever. The fact that the answerer is using 6 sensors means nothing by itself and does not answers the OP question. Could 10, 15, 20, 30, 42 sensors be connected instead of 6? If so, how? If not, why? Why 6 answers the question? This answer is not just unhelpful, but also a non-answer. – Enric Blanco Mar 29 '17 at 7:58
  • 1
    Actually this is a precise answer to the exact question asked: how many sensors can be... Then: 6 sensors can be connected. I don't see why the answer would need to be refined, since the question does not ask for more. – jfpoilpret Mar 29 '17 at 17:20
  • Clarification might be needed why "6 sonar sensors" but otherwise, this indeed does answer the question to some extent, definitely an answer. – Avamander Apr 10 '17 at 23:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.