触发端与回波端接线
连接传感器的两个控制引脚
触发端与回波端接线 是 CoddyKit 上的免费 Arduino & IoT Academy 课时。 这是第 2 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 Arduino & IoT Academy 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 Arduino & IoT Academy 课程共包含 4 节课。
本课时的部分内容尚未翻译,以英文显示。
Four Little Pins
The HC-SR04 has four pins in a row: VCC, Trig, Echo, and GND. Get these connected correctly and the sensor just works.
Power It Up
Connect VCC to the Arduino 5V pin. This sensor needs a full 5 volts to charge up and fire its sound pulses properly.
Share a Ground
Wire GND to an Arduino GND pin. Without a shared ground, the signals have no common reference and your readings turn to nonsense.
Trig Is the Speaker
The Trig pin is the sensor's input. When you pulse it HIGH for a moment, the sensor sends out its burst of ultrasonic sound.
Echo Is the Listener
The Echo pin is the sensor's output. It goes HIGH for exactly as long as the sound is travelling out and bouncing back.
Pick Two Digital Pins
Connect Trig and Echo to any two digital pins, for example pin 9 and pin 10. You will name these in code so the Arduino knows where to look.
Name Your Pins
At the top of your sketch, give each pin a clear name. Constants make the rest of your code far easier to read and edit later.
const int trigPin = 9;
const int echoPin = 10;Set the Directions
In setup, declare Trig as OUTPUT so you can drive it, and Echo as INPUT so the Arduino can read the returning pulse.
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);Mind the Echo Voltage
The Echo pin outputs 5V, which a standard Uno reads fine. On a 3.3V board like an ESP32, add a divider so you do not over-volt the pin. ⚠️
Use a Breadboard
Plug the sensor and jumper wires into a breadboard for solid, tidy connections. Loose wires are the top cause of flickering readings.
Double-Check Before Power
Never swap VCC and GND. Before powering on, trace each wire once more so you protect both the sensor and your board.
Quick Check
Think about which pin does what.
Wired and Ready
Power, ground, and two named digital pins, that is the whole hookup. With Trig driving and Echo listening, you are ready to time the pulse. ✅
常见问题解答
「触发端与回波端接线」课时是免费的吗?
是的 — 「触发端与回波端接线」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 Arduino & IoT Academy 课程的其余内容,请升级到 CoddyKit PRO。 Arduino & IoT Academy 课程共包含 4 节课。
「触发端与回波端接线」这节课中我会学到什么?
连接传感器的两个控制引脚 你通过在浏览器中直接运行的动手代码来练习 Arduino & IoT Academy,全天候 AI 导师会在你学习这节课的过程中回答你的问题。
学习 Arduino & IoT Academy 需要有经验吗?
无需任何先前经验。CoddyKit 上的 Arduino & IoT Academy 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 2 节课,共 4 节。
「触发端与回波端接线」课时需要多长时间?
大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。
我能在这节 Arduino & IoT Academy 课中编写并运行代码吗?
能。每节 Arduino & IoT Academy 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。
此课程中的所有课时
- 超声波测距原理
- 触发端与回波端接线
- 使用 pulseIn 测量回波时间
- 制作接近报警器