The diagram below shows where to connect each 3-wire Ping))) sensor cable. If you’re looking at the color version, note that each black wire is connected to either GND on the breadboard, or the GND terminal in the servo header (labeled Black to the right of the header block). Each of those black wires should also be connected to a Ping))) sensor’s GND pin.
IMPORTANT: The power jumper between BOE Shield servo ports 11 and 12 should also be set to 5V.
WARNING: Wiring errors can damage the Ping))) sensors and/or your Arduino. Do not turn power back on until you have double-checked all the connections in this section’s checklist below.
The Terminal display after connecting the Ping))) sensors and running the example sketch will resemble this. If all the Ping))) sensors are connected correctly, the display should show the centimeter distances of obstacles placed in front of each one (within its 3 cm to 3 m range, and typically good to +/- 1 cm).
In the terminal, the right left Ping))) sensor does not see an obstacle, either because it’s beyond the 3 m limit, or the obstacle might be at an angle that’s reflecting the ultrasonic energy away from (instead of back to) the sensor. If you put your hand about 10 cm in front of the right sensor, that value should change to about 10. Make sure that each sensor correctly reports distances when you do that.
/* Arlo-Test-Ping-Sensors */ String directions[4] = {"Front: ", // Directions for display "Back: ", "Left: ", "Right: "}; int pingPin[4] = {11, 10, 9, 8}; // Ping pins int cmDist[4]; // Cm distances int i = 0; // Index, stat at 0 void setup() // Setup function { Serial.begin(9600); // Start terminal communication } void loop() // Main loop { cmDist[i] = pingCm(pingPin[i]); // Get distance Serial.print(directions[i]); // Display direction Serial.print("cmDist["); // Display variable name Serial.print(i); // Display variable index Serial.print("] = "); // Display ] & = Serial.println(cmDist[i]); // Display value i++; // Increase index by 1 if(i == 4) // If index is 4 { i = 0; // Reset index to 0 delay(1000); // Wait a second Serial.println(); // Print a blank line } } int pingCm(int pin) // Ping measurement function { digitalWrite(pin, LOW); // Pin to output-low pinMode(pin, OUTPUT); delayMicroseconds(200); // Required between successive digitalWrite(pin, HIGH); // Send high pulse delayMicroseconds(5); // Must be at least 2 us digitalWrite(pin, LOW); // End pulse to start ping pinMode(pin, INPUT); // Change to input long microseconds = pulseIn(pin, HIGH); // Wait for echo to reflect return microseconds / 29 / 2; // Convert us echo to cm }