analogRead restituisce 0–1023
Convertire una tensione in un numero utilizzabile
analogRead restituisce 0–1023 è una lezione Arduino & IoT Academy gratuita su CoddyKit. Questa è la lezione 2 di 4. Puoi leggere la lezione completa qui gratuitamente — poi esercitati direttamente nel browser con un editor di codice integrato e un tutor IA disponibile 24/7. Fa parte del percorso di apprendimento Arduino & IoT Academy, e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso Arduino & IoT Academy include 4 lezioni in totale.
Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.
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.
Domande Frequenti
La lezione «analogRead restituisce 0–1023» è gratuita?
Sì — il testo completo di «analogRead restituisce 0–1023» è gratuito qui sul web. Per esercitarvi in modo interattivo (un editor di codice integrato e un tutor IA 24/7) e sbloccare il resto del corso Arduino & IoT Academy, passa a CoddyKit PRO. Il corso Arduino & IoT Academy include 4 lezioni in totale.
Cosa imparerò in «analogRead restituisce 0–1023»?
Convertire una tensione in un numero utilizzabile Eserciti Arduino & IoT Academy con codice pratico che esegui direttamente nel browser, e un tutor IA 24/7 risponde alle tue domande mentre lavori sulla lezione.
Ho bisogno di esperienza per iniziare Arduino & IoT Academy?
Non è richiesta alcuna esperienza precedente. Arduino & IoT Academy su CoddyKit è strutturato per principianti e studenti avanzati, quindi puoi iniziare da qui o dall'inizio e procedere al tuo ritmo. Questa è la lezione 2 di 4.
Quanto tempo richiede la lezione «analogRead restituisce 0–1023»?
La maggior parte delle lezioni CoddyKit richiede circa 5–10 minuti. Ogni lezione è breve e interattiva, quindi fai progressi costanti e riprendi esattamente da dove hai lasciato su web e app.
Posso scrivere ed eseguire codice in questa lezione Arduino & IoT Academy?
Sì. Ogni lezione Arduino & IoT Academy include un editor di codice integrato, quindi scrivi ed esegui codice reale direttamente nel tuo browser e ricevi feedback istantaneo dall'IA — nessuna configurazione locale necessaria.
Tutte le lezioni di questo corso
- Segnali digitali e analogici
- analogRead restituisce 0–1023
- Leggere la manopola di un potenziometro
- Rimappare i valori con map()