Connect the Sensor

The common HC-SR04 boards are designed for 5V TTL voltage levels. Since the advent of CMOS many circuits started using 3.3V levels including the CPX board, this can create compatibility problems. The guide to CPX Pinouts states:

All of the GPIO pads are 3.3V output level, and should not be used with 5V inputs. In general, most 5V devices are OK with 3.3V output though.

This creates a requirement to reduce the voltage from the Echo output of the HC-SR04 rather than simply directly connecting all of the sensor's pins to the CPX board. The easiest way to reduce a single voltage is to use two resistors as a potential divider. The example shown uses two equal resistors (10 K ohms, they come with the HC-SR04 that Adafruit sells) to halve the voltage. 2.5V is clearly lower than 3.3V but this is high enough to work. The sum of the two resistors should be above 1 kiloohm to keep the current within the limits of the sensor's output.

The slightly more complicated alternative to converting the voltages is to use a semiconductor solution like the unidirectional 74LVC245 or 74AHCT125 or the bidirectional TXB0104.

The diagram below shows how to connect the components together. The HC-SR04 can be plugged directly into the breadboard without the four wires shown in the diagram.

The picture below shows how it looks implemented on a breadboard. The only differences are: the sensor is plugged into the breadboard; the use of double-ended alligator (crocodile) clip leads with header pins aiding connection to the breadboard. The alligator clip to male jumper wire is an easier alternative.

The connections are:

 

  • Black: Gnd to GND via bus strip. Row 1 is also connected to ground.
  • Red: Vcc to VOUT via bus strip.
  • Green: Echo to potential divider (a pair of 10k resistors across).
  • White: divided voltage (row 6) to A1.
  • Yellow: Trig to A2.

 

Note: Pictures show two 2.2K resistors, Adafruit supplies two 10K resistors, both configurations function the same).

The A0 input can be used as an output for the sensor's Trig pin if you want the surprise of hearing the trigger pulses. The CPX board has A0 hard wired up to its small speaker.

For comparison: the Raspberry Pi has the same 3.3V limitation on GPIO inputs; many of the Arduino boards like the Uno are 5V tolerant for inputs, allowing direct connection of this sensor.

The standard HC-SR04 will appear to work at 3.3V but apparently is far less accurate. There are versions of it sold as 3.3V tolerant. There's a detailed discussion on some of the variations of this sensor on David Pilling's HC-SR04 page.

This guide was first published on Sep 17, 2018. It was last updated on Sep 17, 2018. This page (Connect the Sensor) was last updated on May 25, 2019.