กลับหน้าหลัก
views
Reading Analog Signals on Arduino with analogRead()
Last updated on

Reading Analog Signals on Arduino with analogRead()


Reading Analog Signals on Arduino with analogRead()

Arduino can read continuous analog signals, unlike digital signals which only have two states (0 and 1). Many external devices such as potentiometers, light sensors, and temperature sensors output voltage levels that we can read through Arduino’s analog inputs.

How Analog Input Works on Arduino

Arduino boards contain a built-in Analog to Digital Converter (ADC) with 6 channels labeled A0-A5.

  • Accepts voltage range from 0 to 5 volts
  • Converts to 10-bit digital values from 0 to 1023
  • No unit attached (raw digital value from ADC)
Circuit diagram showing potentiometer connected to Arduino at pin A0 with wires labeled 5V, GND, and signal to A0

Using analogRead()

The function to read analog values is analogRead(pin) where pin is one of A0-A5.

// Define the pin connected to the analog device
const int sensorPin = A0;

void setup() {
  Serial.begin(9600);  // Open Serial Monitor to see values
}

void loop() {
  int value = analogRead(sensorPin);  // Read value 0-1023
  Serial.println(value);              // Print value to Serial
  delay(100);
}

Connect a potentiometer to A3 and use the read value to control how fast an LED on pin 13 blinks.

[image: Breadboard wiring showing potentiometer connected to Arduino with A3 and LED on pin 13 labeled]

// Define potentiometer pin and LED pin
const int sensorPin = A3;
const int ledPin = 13;

void setup() {
  pinMode(ledPin, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  // Read analog value from potentiometer
  int sensorValue = analogRead(sensorPin);
  Serial.println(sensorValue);

  // Pass value to Blinky function to control LED
  Blinky(sensorValue);
}

void Blinky(int timeMs) {
  digitalWrite(ledPin, HIGH);
  delay(timeMs);              // Delay equals the read value
  digitalWrite(ledPin, LOW);
  delay(timeMs);
}

Key Concepts to Understand

ADC Resolution

A 10-bit ADC divides the 0-5V range into 1024 steps (0-1023). If the voltage changes very slightly, the read value may not change at all. This is a hardware limitation of Arduino’s built-in converter.

Converting ADC Value to Voltage

If you need the actual voltage in volts, apply this formula:

volts = (read value / 1023) × 5

float voltage = (analogRead(A0) / 1023.0) * 5.0;
Serial.println(voltage);  // Shows voltage like 2.34

Do Not Use Digital Pins for Analog Input

Digital pins (D0-D13) only work with digital signals. To read analog input, you must use the analog pins A0-A5.

[image: Arduino UNO pinout diagram highlighting A0-A5 as analog input channels]

Reference Video

https://www.youtube.com/embed/7UDbvh5u2cI

อยากทำโปรเจคแบบนี้?

รับทำโปรเจค Arduino / IoT จบงานไว ส่งงานครบ พร้อมสอน

If you need Arduino project service or urgent IoT development, see full service details on the home page

จ้างทำโปรเจคเลย

ประเมินราคาอัตโนมัติ + Reference Code

ขอให้ AI ประเมินราคาโปรเจคนี้

กรอกข้อมูลให้ครบ ระบบจะสร้างรหัสอ้างอิงและประเมินราคา/ระยะเวลาคร่าว ๆ จากรายละเอียดงาน แล้วให้กด Add LINE พร้อมพิมพ์รหัสนี้เพื่อคุยต่อ

คำถามให้ AI ประเมินแม่นขึ้น

หลังส่งฟอร์ม ระบบจะโชว์ Reference Code ให้ copy แล้วกด Add LINE เพื่อคุยต่อ ข้อมูลส่วนตัวจะไม่ถูกส่งเข้า GA4

ความคิดเห็น

รีวิวจากคนใช้งานจริง

รีวิวจากลูกค้าและคนที่เคยใช้งาน

ถ้าเคยสั่งงาน เคยอ่านหน้านี้แล้วได้ประโยชน์ หรือมีข้อเสนอแนะ ฝากรีวิวไว้ได้เลย

กำลังโหลดรีวิว...