Skip to content

Ultrasonic rangefinder

The HC-SR04 ultrasonic range finder is designed to work on 5V which is standard for the Arduino family of prototyping boards. However, the Particle Argon works on 3.3V and some care needs to be exercised when using the two together. There are actually two separate issues - the first is how to supply 5V to the HC-SR04, and the second is how to prevent the Argon being damaged if the HC-SR04 sends a 5V signal on the echo pin.

If your Argon is running connected to a computer or to a power outlet over USB, you can take 5V from the VBUS pin. To solve the second problem and protect the Argon, you can use a voltage divider to step the 5V signal down to 3.3V. Figure 1 shows how to set up the connections on the breadboard.

Note that the value of the resistor connected directly to the echo pin in the diagram is 1kΩ and the other one is 2kΩ. It is not vital to use exactly these values as long as one resistor is twice the rating of the other. Also, remember that you can connect resistors in series and their total resistance is the sum of the individual resistances.

Breadboard connections for an HC-SR04 ultrasonic range finder Figure 1: Breadboard connections for an HC-SR04 ultrasonic range finder

Next, go to the libraries tab in the Particle Web IDE and search for HC-SR04. You will find that there is some example code ready to go.

Particle consoleParticle console

HC-SR04 for ArduinoHC-SR04 for Arduino

HC-SR04 for Particle PhotonHC-SR04 for Particle Photon