กลับไปหน้ารวมไฟล์
analog-read-serial-fff5fa-en.md

The analog input is read and the result is printed in the Serial Monitor. When the shaft is turned all the way in one direction, there are 0 volts going to the pin, and the input value is 0. When the shaft is turned all the way in the opposite direction, there are 5 volts going to the pin and the input value is 1023. In between, analogRead() returns a number between 0 and 1023 that is proportional to the amount of voltage being applied to the pin.

Analog Read Serial

This process is the foundational Analog-to-Digital Converter (ADC) mechanism intrinsic to the Arduino's core silicon. While digital pins are binary (ON or OFF), the physical world is analog. By routing a dynamic voltage through a physical Potentiometer (Variable Resistor), the Arduino captures exactly how much voltage is present and serializes that information to the Serial Monitor as a continuous 10-bit integer sequence.

potentiometer_led_rgb_color_theory_1772681525046.png

Demystifying the 10-Bit ADC Array

When a raw voltage enters an analog pin like A0, the ATmega328P processor executes the ADC natively.

  1. The 10-bit ADC quantizes the 0-5V range into 1024 discrete mathematical steps.
  2. If the physical knob is at 0V (GND), it outputs 0.
  3. If turned to 2.5V (half-way), the ADC returns 512.
  4. If at the maximum 5.0V, the ADC returns 1023.
int sensorPin = A0;  // Explicitly defining the Analog-capable hardware pin!

void setup() {
  // Initiate the UART pipeline at 9600 Baud for Laptop communication
  Serial.begin(9600);
}

void loop() {
  // Execute the Analog-to-Digital reading cycle
  int sensorValue = analogRead(sensorPin);

  // Directly transmit the integer to the Serial Terminal
  Serial.println(sensorValue);

  delay(1); // 1 Millisecond stabilization buffer
}

Transforming Integers into Real Voltages

A raw serial number like "845" is not intuitive for measurement. To convert it back to a usable voltage, a simple mathematical transformation is applied:

  • float voltage = sensorValue * (5.0 / 1023.0);
  • This line multiplies the reading against the "Voltage per Step" ratio.
  • The Serial Monitor will then display exact decimal voltages like 4.13V.

Required Hardware

  • Arduino Uno/Nano (utilizing its 6 native Analog input pins A0-A5).
  • Rotary Potentiometer (10K-Ohm) (functioning as a dynamic voltage divider).
  • USB Data Cable (to sustain the continuous UART serial transmission stream).
  • Arduino IDE Serial Monitor / Serial Plotter Tool (The Serial Plotter transforms the integer list into a smooth graphical wave, visually representing the analog rotation).

ข้อมูล Frontmatter ดั้งเดิม

apps:
  - "1x Arduino IDE"
author: "SBR"
category: "Educational"
components:
  - "1x Breadboard (generic)"
  - "1x Jumper wires (generic)"
  - "1x Rotary potentiometer (generic)"
  - "1x Arduino UNO"
description: "Foundational analog-to-digital matrix! Instantiate continuous 10-bit sequential ADC polling loops directly against variable resistance traces, pushing heavily interpreted variable data back through the UART pipeline to the USB host terminal."
difficulty: "Beginner"
documentationLinks: []
downloadableFiles:
  - "https://projects.arduinocontent.cc/14740004-27bc-4108-b513-dba2a34892cb.ino"
encryptedPayload: "U2FsdGVkX18Q+g0ALgtdJ16XAcAyGgooM80AiMWn9UGJFy8Pmwwl+uIcQHvudME9P7HNsftBGDgCoqJr/djBHGoAnGj8WW3Kp+JXhn8O7LY="
heroImage: "https://cdn.jsdelivr.net/gh/bigboxthailand/arduino-assets@main/images/projects/analog-read-serial-fff5fa_cover.jpg"
lang: "en"
likes: 1
passwordHash: "9d59d695b840cf686d3820dfc3aa626023665830ccc0b76e0c572b55fd8d1e6f"
price: 199
seoDescription: "Learn to read Analog input from a Potentiometer using Arduino and Serial Monitor with this step-by-step Analog Read Serial guide."
tags:
  - "built-in example"
  - "analog read serial"
  - "basics"
title: "Analog Read Serial"
tools: []
videoLinks:
  - "https://www.youtube.com/embed/l7wo_Iqw7QY"
views: 9964