analogRead Retorna 0–1023
Converta uma tensão em um número que você possa usar.
analogRead Retorna 0–1023 é uma aula grátis de Arduino & IoT Academy no CoddyKit. Esta é a aula 2 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de Arduino & IoT Academy, e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de Arduino & IoT Academy inclui 4 aulas no total.
Partes desta aula ainda não foram traduzidas e aparecem em inglês.
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.
Perguntas Frequentes
A aula “analogRead Retorna 0–1023” é grátis?
Sim — o texto completo de “analogRead Retorna 0–1023” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de Arduino & IoT Academy, atualize para CoddyKit PRO. O curso de Arduino & IoT Academy inclui 4 aulas no total.
O que vou aprender em “analogRead Retorna 0–1023”?
Converta uma tensão em um número que você possa usar. Você pratica Arduino & IoT Academy com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.
Preciso ter experiência prévia para começar Arduino & IoT Academy?
Nenhuma experiência prévia é necessária. Arduino & IoT Academy no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 2 de 4.
Quanto tempo leva a aula “analogRead Retorna 0–1023”?
A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.
Posso escrever e executar código nesta aula de Arduino & IoT Academy?
Sim. Cada aula de Arduino & IoT Academy inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.
Todas as aulas deste curso
- Sinais Digitais versus Analógicos
- analogRead Retorna 0–1023
- Leia o Botão de um Potenciômetro
- Mapeie Valores para uma Nova Faixa