Extension board · Sensors and inputs

Ultrasonic distance sensor

A carrier for the common HC-SR04 ultrasonic distance module. It powers the module from 5 V and brings its echo signal down to a level the controller accepts. Measuring distance means timing a pulse, which needs your own driver.

Top view of the ultrasonic sensor board: a ten-contact socket on the left and right edges and a four-way module socket near the bottom edge.
Top view, drawn from the board’s design files. This is a drawing, not a photograph.
2 cm to 4 mrange stated for the module
Trigger + echocontacts 3 and 4
3.38 Vecho at the controller for a 5.25 V module output
15 mAmodule current at 5 V
2 socketstype X input and chain
60 × 50millimetres, four M3 holes
Do not plug a module in or out while powered. This is not a safety or collision-protection sensor.

Tech specs

PurposeCoarse non-contact distance or presence sensing, for example a material or enclosure check
ModuleHC-SR04 with 5V, TRIG, ECHO, GND pins; bought separately
Module connectorsJ3: four-way 2.54 mm right-angle socket. J4: alternative four-way JST PH footprint, not fitted; use only one
SignalsTrigger through 220 Ω with 100 kΩ pull-down; echo through a 10 kΩ / 18 kΩ divider
Supply5 V from the socket
SocketsTwo 10-contact Gadgeteer type X sockets (Samtec SHF-105, 1.27 mm): input and chain
Size60 × 50 mm, four M3 holes on a 50 × 40 mm pattern; the module overhangs the edge
Works withSmoothieboard V2 Prime header GF electrically; no firmware driver
LicenceOpen hardware, CERN-OHL-S-2.0

Every figure with its basis is in the electrical specifications appendix; hole positions are in the mounting dimensions appendix.

Board tour

The numbers on the drawing match the list below it. The board is shown from the component side.

  1. 1
    Input socket X IN (J1) — Trigger on contact 3, echo on contact 4.
  2. 2
    Chain socket CHAIN (J2) — Passes the unused contacts on.
  3. 3
    Module socket (J3) — The module plugs in here, matching the printed order 5V, TRIG, ECHO, GND.
  4. 4
    Cable connector position (J4) — Alternative footprint for a module on a cable.
  5. 5
    Trigger parts (R1, R2) — Series resistor, and a pull-down that keeps the module idle while the pin floats.
  6. 6
    Echo divider (R3, R4) — Brings the 5 V echo down to about 3.3 V.
  7. 7
    Supply capacitors (C1, C2) — 100 nF and 10 µF on 5 V.
  8. 8
    Power light (D1, R5) — Green, lit when 5 V is present.
  9. 9
    LED link (JP9) — Closed as delivered.
  10. 10
    Chain links (JP3, JP4) — Open as delivered, keeping trigger and echo off the chain.
  11. 11
    Mounting hole — One of four M3 holes.
Point at a number, or tap it, to read what the part is; the same text is in the list. On a small screen, scroll the drawing sideways.

Pinout

Check contact numbering and the module’s pin order before applying power.

J1: input socket (X IN)

ContactSignalUsePrime header GF
13.3 VPassed to the chain3.3 V
25 VModule supply5 V
3TRIGOutput from controllerPB1
4ECHOInput to controllerPJ4
5 to 9Passed throughNot usedPA4, PG0, PJ3, PG1, PJ2
10GNDGroundGND

J3 and J4: module

PinSignal
15 V
2TRIG
3ECHO
4GND

What you need

An HC-SR04 moduleCheck the pin order and that it accepts a 3.3 V trigger; copies differ.
A ten-way cable1.27 mm Gadgeteer ribbon cable.
A supportThe module overhangs the board.
Your own driverIt must pulse the trigger and time the echo.

Get started

Minimum wiring: contact 2 to contact 2, 5 V; PB1, contact 3 to contact 3, trigger; PJ4, contact 4 to contact 4, echo; contact 10 to contact 10, ground. Prime header GF (J37) Ultrasonic J1 contact 2contact 25 V PB1, contact 3contact 3trigger PJ4, contact 4contact 4echo contact 10contact 10ground
Four connections.
  1. Plug in the module

    With the power off, match 5V, TRIG, ECHO and GND to the printing.

  2. Mount

    Point the module at a flat target and keep the beam clear of the machine frame.

  3. Connect and power

    Plug J1 into header GF.

    The green LED should light.

  4. Measure

    Pulse the trigger for at least 10 µs and time the echo pulse; wait 60 ms or more between measurements.

    By the module data sheet, the pulse width in microseconds divided by 58 gives the distance in centimetres.

Configuration

You wantModuleExample
Read distanceNoneNo SmoothieV2 module drives an HC-SR04

There is nothing to add to config.ini.

How it works

The controller triggers the module; the echo pulse returns through a divider. J1 contact 3trigger pulse R1 220 ohmprotect Modulesends burst Moduleecho 5 V 10 k / 18 kdivide J1 contact 4about 3.3 V
Trigger above, echo below.

The module sends an ultrasonic burst after each trigger and holds its echo output high for as long as the sound takes to return. The two resistors scale that 5 V signal by 18/28. Their effect on timing is small: the simulated rise time of 0.42 µs corresponds to well under a tenth of a millimetre.

Solder links

Leave JP3 and JP4 open while the module is in use.

Solder links as delivered: JP3 open; JP4 open; JP9 closed. JP3 · openchain contact 3 JP4 · openchain contact 4 JP9 · closedpower light
The links as delivered. Close one with a small blob of solder across both pads; open it by removing the solder or cutting the copper between the pads.
LinkWhat it doesAs delivered
JP3Joins contact 3 to the chain socketOpen
JP4Joins contact 4 to the chain socketOpen
JP9Powers the green LEDClosed

Chaining

A further board on CHAIN can use contacts 5 to 9.

The controller's ribbon cable goes to the connector X IN of the ultrasonic sensor board. Inside the board each of the ten pins runs through a solder link to the connector CHAIN, where a second ribbon cable continues to the next board. A closed link passes its pin on, an open link stops it. Controller one ten-pin port ultrasonic sensor board X IN CHAIN pin 3, trigger stops here pin 4, echo stops here pin 5, free passed on one solder link per pin Next board sees what is passed on
Chaining: one port of the controller serves two boards. Pin 1 of X IN leads to pin 1 of CHAIN, pin 2 to pin 2, and so on, each through its own solder link. The three lines stand for the ten pins and show the links as delivered. Two boards must never drive the same pin, and a pin that one board uses for a signal is not free for the next. Pins 3 and 4 stop here; pin 5 is wired straight through.
ContactSignalOn CHAIN
1, 2, 10Power and groundPassed on
3, 4Trigger, echoStopped by open links
5 to 9FreePassed on

Troubleshooting

SymptomLikely causeWhat to check
No echo at allNo 5 V, module plugged in wrongly, or trigger too shortLED, pin order, a 10 µs or longer pulse
Module ignores the triggerModule needs a 5 V trigger levelTry another module
Erratic distanceSoft or angled target, or measurements too close togetherUse a flat target and wait 60 ms
Distance slightly offAir temperature changes the speed of soundCalibrate in place
Light Meaning
Green (D1) 5 V present

Still stuck? Read how to ask for help or see the general troubleshooting guide.

Downloads

FileWhat it is
Schematic (PDF)The circuit diagram
Parts list (CSV)Every component with its value, footprint and part number where one is chosen
Board drawing (PNG)The top view used on this page
3D view, top (PNG)Rendered from the design files; the module itself is not shown
3D view, angled (PNG)Rendered from the design files; the module itself is not shown

Appendix: mounting dimensions

For drilling a mounting plate or designing an enclosure. Positions are hole centres, in millimetres, measured from the top-left corner with the board seen from the component side. Allow for the module overhanging the board edge.

Mounting drawing of the ultrasonic sensor board, component side: outline 60 by 50 millimetres with 4 mounting holes. Hole positions are listed in the table below. COMPONENT SIDE · millimetres 60 50 0, 0 X Y 1 5.00, 5.00 2 55.00, 5.00 3 5.00, 45.00 4 55.00, 45.00 Numbered rings are mounting holes. Positions are hole centres, X then Y, from the marked corner.
Board outline 60 × 50 mm, corners rounded to a 1 mm radius, board thickness 1.6 mm. Drawn from the design files, component side up, in the same orientation as the board tour.
HoleX (mm)Y (mm)DiameterUse
15.005.003.2 mm, not platedMounting, M3 screw
255.005.003.2 mm, not platedMounting, M3 screw
35.0045.003.2 mm, not platedMounting, M3 screw
455.0045.003.2 mm, not platedMounting, M3 screw

Appendix: electrical specifications

Every figure is a design value, a calculated or simulated value, or a manufacturer’s data sheet value, as the last column says. A dash means no figure is given.

ParameterApplies toLowerNominalUpperBasis
Module supply5 V—5 V—Design
Module current5 V—15 mA—Module data sheet
RangeModule2 cm—4 mModule data sheet
Trigger pulseContact 310 µs——Module data sheet
Measurement intervalModule60 ms——Module data sheet
Echo high at controllerContact 42.83 V—3.37 VSimulated for 4.4 to 5.25 V from the module
Echo rise timeContact 4—0.42 µs—Simulated

Component stress limits

PartLimitUse on this board
Echo dividerLimits current into the controller through 10 kΩ5 V module signal
Capacitors10 V and 16 V5 V

Appendix: simulation

The echo divider was simulated with ngspice at the highest and a low module output voltage.

Each simulated value (yellow mark) against its allowed range (green band). Host input high level at 5.25 V echo3.37 V Echo rise time (1 us equals 0.17 mm of range)424 ns Host input high level at 4.4 V echo2.83 V
Simulated value (yellow) against the limit used for it (green). Each bar has its own scale.
ResultSimulated valueLimitOutcome
Host input high level at 5.25 V echo3.37 V2.4 V to 3.45 VWithin
Echo rise time (1 us equals 0.17 mm of range)424 nsat most 1 µsWithin
Host input high level at 4.4 V echo2.83 Vat least 2.31 VWithin

Not simulated: the module itself, its acoustics and its timing.

Appendix: datasheet

The first page of the module data sheet. Click the page to open the PDF. It is a copy distributed by a reseller.

First page of the HC-SR04 ultrasonic ranging module datasheet
HC-SR04 ultrasonic ranging module — ElecFreaks, 3 pages.

See all boards on the extension boards page.

This is a wiki! If you'd like to improve this page, you can edit it on GitHub.