إرجاع analogRead للقيم 0–1023
تحويل الجهد إلى عدد يمكنكم استخدامه
إرجاع analogRead للقيم 0–1023 درس مجاني في Arduino & IoT Academy على CoddyKit. هذا هو الدرس 2 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 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» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Arduino & IoT Academy، انتقل إلى CoddyKit PRO. تتضمن دورة Arduino & IoT Academy 4 دروس في المجموع.
ماذا ستتعلم في «إرجاع analogRead للقيم 0–1023»؟
تحويل الجهد إلى عدد يمكنكم استخدامه تتمرن على Arduino & IoT Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ Arduino & IoT Academy؟
لا تُشترط خبرة سابقة. Arduino & IoT Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 2 من أصل 4.
كم من الوقت يستغرق درس «إرجاع analogRead للقيم 0–1023»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس Arduino & IoT Academy هذا؟
نعم. كل درس في Arduino & IoT Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- الإشارات الرقمية مقابل التناظرية
- إرجاع analogRead للقيم 0–1023
- قراءة مقبض مقياس الجهد
- تعيين قيم map() إلى نطاق جديد