การต่อสาย Trigger และ Echo
เชื่อมต่อขาควบคุมสองขาของเซนเซอร์
การต่อสาย Trigger และ Echo เป็นบทเรียน Arduino & IoT Academy ฟรีบน CoddyKit นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน 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. ✅
คำถามที่พบบ่อย
บทเรียน “การต่อสาย Trigger และ Echo” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “การต่อสาย Trigger และ Echo” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Arduino & IoT Academy ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Arduino & IoT Academy มีบทเรียนทั้งหมด 4 บทเรียน
คุณจะเรียนรู้อะไรในบทเรียน “การต่อสาย Trigger และ Echo”
เชื่อมต่อขาควบคุมสองขาของเซนเซอร์ คุณปฏิบัติ Arduino & IoT Academy ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน
คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Arduino & IoT Academy หรือไม่
ไม่จำเป็นต้องมีประสบการณ์มาก่อน Arduino & IoT Academy บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน
บทเรียน “การต่อสาย Trigger และ Echo” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน Arduino & IoT Academy นี้ได้ไหม
ได้ บทเรียน Arduino & IoT Academy ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- การวัดระยะด้วยคลื่นอัลตราโซนิก
- การต่อสาย Trigger และ Echo
- ใช้ pulseIn จับเวลาเสียงสะท้อน
- สร้างสัญญาณเตือนระยะใกล้