analogRead คืนค่า 0–1023
แปลงแรงดันไฟฟ้าเป็นตัวเลขที่นำไปใช้ได้
analogRead คืนค่า 0–1023 เป็นบทเรียน Arduino & IoT Academy ฟรีบน CoddyKit นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Arduino & IoT Academy และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Arduino & IoT Academy มีบทเรียนทั้งหมด 4 บทเรียน
บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ
Turning Voltage into Numbers
Code cannot use raw volts directly. The analogRead function measures a pin and hands you back a plain number you can work with.
The Range Is 0 to 1023
Every analogRead result lands between 0 and 1023. That is exactly 1024 possible steps, from the lowest voltage to the highest.
Why 1024 Steps
The Uno uses a 10-bit converter, and 2 to the power of 10 is 1024. More bits would simply give you finer resolution.
0 Means Zero Volts
A reading of 0 means the pin sees 0V, the very bottom of the range. Nothing lower can be measured here.
1023 Means Full Voltage
A reading of 1023 means the pin is at the reference voltage, normally 5V on an Uno. That is the top of the scale.
Halfway Is About 512
Around 2.5V the value sits near 512, the middle of the range. The mapping from voltage to number is wonderfully linear.
Call It on an Analog Pin
Pass an analog pin name to read it. analogRead(A0) samples pin A0 and returns its current value as an int.
int value = analogRead(A0);Store It in an int
The result fits easily in an int, since 1023 is small. Save it to a variable so you can use it later in your code.
int sensor = analogRead(A0);No pinMode Needed
Analog inputs are ready out of the box. You do not call pinMode for them, you simply call analogRead when you want a value.
Convert Back to Volts
To see actual voltage, scale the reading. Multiply by 5.0 and divide by 1023 to turn the number into volts.
float v = analogRead(A0) * 5.0 / 1023.0;Readings Wobble a Little
Tiny electrical noise makes values jiggle by a point or two. That is normal, and averaging a few reads smooths it out.
Quick Check
What does analogRead hand back to you?
Recap: The 0 to 1023 Scale
You learned analogRead turns a 0V to 5V signal into a number from 0 to 1023. Store it in an int, and scale it back to volts when needed.
คำถามที่พบบ่อย
บทเรียน “analogRead คืนค่า 0–1023” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “analogRead คืนค่า 0–1023” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Arduino & IoT Academy ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Arduino & IoT Academy มีบทเรียนทั้งหมด 4 บทเรียน
คุณจะเรียนรู้อะไรในบทเรียน “analogRead คืนค่า 0–1023”
แปลงแรงดันไฟฟ้าเป็นตัวเลขที่นำไปใช้ได้ คุณปฏิบัติ Arduino & IoT Academy ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน
คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Arduino & IoT Academy หรือไม่
ไม่จำเป็นต้องมีประสบการณ์มาก่อน Arduino & IoT Academy บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน
บทเรียน “analogRead คืนค่า 0–1023” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน Arduino & IoT Academy นี้ได้ไหม
ได้ บทเรียน Arduino & IoT Academy ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- สัญญาณดิจิทัลเทียบกับแอนะล็อก
- analogRead คืนค่า 0–1023
- อ่านปุ่มหมุนโพเทนชิโอมิเตอร์
- map() ค่าไปยังช่วงใหม่