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

ตั้งค่าเกณฑ์แสง

กำหนดว่าค่าที่อ่านได้มืดเพียงพอให้เริ่มทำงานหรือไม่

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

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

Raw Numbers Need Meaning

An analog reading like 312 means nothing on its own. A threshold turns that number into a clear decision: dark or bright.

What a Threshold Is

A threshold is a cutoff value. Readings on one side count as dark, and readings on the other count as bright.

Store It in a Variable

Keep your cutoff in a named variable so it is easy to find and adjust later in one place.

int threshold = 400;

Compare With if

Use an if statement to compare the live reading against your threshold and branch your logic from there.

if (light < threshold) {
  // it is dark
}

Direction Depends on Wiring

Whether dark means a higher or lower number depends on how you wired the divider. Confirm it before you trust the test.

Find Your Number

Print readings in a bright room and a dark one, then pick a midpoint between them as your starting threshold.

Add else for Bright

Pair your if with an else so the bright case is handled too, instead of doing nothing when light is high.

else {
  // it is bright
}

One Cutoff Causes Flicker

Near the line, tiny changes can flip the result back and forth. This rapid flicker looks like a glitch.

Add Hysteresis

Hysteresis uses two cutoffs: one to switch on and a different one to switch off. The gap stops nervous flicker.

Make It Adjustable

Feed the threshold from a potentiometer so anyone can dial in dark without re-uploading code.

Thresholds Drive Decisions

This same threshold idea works for temperature, moisture, and distance. It is how sensors become decisions.

Quick Check

What problem does hysteresis solve at a light threshold?

Recap: Deciding on Light

You stored a threshold, compared readings with if and else, and added hysteresis so the decision stays steady.

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

บทเรียน “ตั้งค่าเกณฑ์แสง” ฟรีหรือไม่

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

คุณจะเรียนรู้อะไรในบทเรียน “ตั้งค่าเกณฑ์แสง”

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

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

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

บทเรียน “ตั้งค่าเกณฑ์แสง” ใช้เวลานานแค่ไหน

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

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

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

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

  1. อ่านเซนเซอร์ตรวจจับการเคลื่อนไหว PIR
  2. วัดแสงด้วย LDR
  3. ตั้งค่าเกณฑ์แสง
  4. ไฟกลางคืนอัตโนมัติ
← กลับไปที่ Arduino & IoT Academy