0Pricing
Arduino & IoT Academy · บทเรียน

PWM ทำอะไรจริง ๆ

พัลส์เปิด/ปิดความเร็วสูงที่ทำหน้าที่คล้ายตัวหรี่ไฟ

PWM ทำอะไรจริง ๆ เป็นบทเรียน Arduino & IoT Academy ฟรีบน CoddyKit นี่คือบทเรียนที่ 1 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Arduino & IoT Academy และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Arduino & IoT Academy มีบทเรียนทั้งหมด 4 บทเรียน

บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ

A Pin That Only Knows On or Off

A digital pin can only output full voltage or none at all. So how do you get a dim LED instead of just bright or dark? 💡

The Trick: Switch Very Fast

The answer is PWM: turn the pin on and off so quickly that your eye blends the flickers into one steady, in-between brightness.

PWM Stands For This

PWM means Pulse Width Modulation. You keep flipping the pin, and you change how wide each on-pulse is to control the average power.

Meet the Duty Cycle

The duty cycle is the percent of each cycle the pin stays on. 50% on means roughly half power and a half-bright LED.

More On-Time, More Power

A wider pulse means more on-time, so the LED looks brighter or a motor spins faster. Narrow pulses give you dim and slow.

It Is Still Digital

PWM never outputs a true middle voltage. The pin is always fully HIGH or fully LOW, just switching fast enough to feel smooth.

Your Eyes Do the Blending

The LED really does flicker, but the switching is so fast that persistence of vision makes it look like one constant level.

Frequency Keeps It Smooth

The frequency is how many on-off cycles happen each second. Arduino runs PWM around 490 Hz, fast enough to hide the flicker.

Only Some Pins Can Do It

Not every pin supports PWM. On an Uno, look for pins marked with a tilde symbol next to numbers like 3, 5, 6, 9, 10, and 11.

Where You Will Use It

PWM powers real effects: dimming an LED, fading lights, controlling motor speed, and even shaping simple tones from a buzzer. 🔊

One Command Sets It Up

In code you do not toggle the pin yourself. One built-in analogWrite call sets the duty cycle and the chip pulses for you.

analogWrite(9, 128); // ~50% duty on a PWM pin

Quick Check

Let's lock in what PWM really controls.

Recap: PWM in a Nutshell

PWM fakes analog output by pulsing a digital pin fast. The duty cycle sets the power, and your eyes blend it into smooth brightness. 🎉

คำถามที่พบบ่อย

บทเรียน “PWM ทำอะไรจริง ๆ” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “PWM ทำอะไรจริง ๆ” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Arduino & IoT Academy ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Arduino & IoT Academy มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “PWM ทำอะไรจริง ๆ”

พัลส์เปิด/ปิดความเร็วสูงที่ทำหน้าที่คล้ายตัวหรี่ไฟ คุณปฏิบัติ Arduino & IoT Academy ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Arduino & IoT Academy หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน Arduino & IoT Academy บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 1 จากทั้งหมด 4 บทเรียน

บทเรียน “PWM ทำอะไรจริง ๆ” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน Arduino & IoT Academy นี้ได้ไหม

ได้ บทเรียน Arduino & IoT Academy ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. PWM ทำอะไรจริง ๆ
  2. analogWrite 0–255
  3. ค่อย ๆ เพิ่มและลดแสง LED
  4. ปุ่มหมุนควบคุมความสว่าง LED
← กลับไปที่ Arduino & IoT Academy