0Pricing
Arduino & IoT Academy · レッスン

analogRead は 0~1023 を返す

電圧を利用できる数値に変換します

「analogRead は 0~1023 を返す」はCoddyKit上の無料Arduino & IoT Academyレッスンです。 これはレッスン2/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これは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時間対応のAIチューター)、Arduino & IoT Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Arduino & IoT Academyコースには全4レッスンが含まれています。

「analogRead は 0~1023 を返す」で何を学びますか?

電圧を利用できる数値に変換します ブラウザで直接実行するハンズオンコードでArduino & IoT Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

Arduino & IoT Academyを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのArduino & IoT Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン2/4です。

「analogRead は 0~1023 を返す」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このArduino & IoT Academyレッスンでコードを書いて実行できますか?

はい。すべてのArduino & IoT Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. デジタル信号とアナログ信号
  2. analogRead は 0~1023 を返す
  3. ポテンショメーターのつまみを読み取る
  4. map() で値を新しい範囲に変換する
← Arduino & IoT Academyに戻る