Ultrasonic distance HC-SR04 with TinkerPie
Bat-style sonar. Use the 3.3 V HC-SR04P, or a divider on ECHO for the 5 V version.
| Type | Timing sensors |
|---|---|
| Connect to | TRIG and ECHO on two pins (or one pin for 3-pin modules) |
| Gives | cm (2-400), -1 = no echo |
| Simulator | Yes: a control appears under the simulated board |
How to wire it
One or two signal pins on S1-S4 or P10-P13. Studio reads them with precise timing in the board firmware.
Code
In blocks: Accessories category in TinkerPie Studio. As code:
// JavaScript
sensors.ultrasonicCm(Pin.S1, Pin.S2)
// Arduino C++
sensors::ultrasonicCm(Pin::S1, Pin::S2)
Projects with the Ultrasonic distance HC-SR04
Ultrasonic rulerMeasures how far your hand is, in centimetres, with an HC-SR04 sonar.Sensor projectsSmart dustbin lidWave over the bin: a servo opens the lid for two seconds, then closes it.Sensor projects