กลับไปหน้ารวมไฟล์
arduino-digital-pin-testing-with-serial-monitor-5d98be-en.md

Diagnostic Tech: Serial Pin Tester

Microcontrollers break. You accidentally short a 12V wire to a 5V pin, and suddenly your robot doesn't steer right anymore. Before you throw the whole Arduino away, you need to test the microcontroller. The Serial Pin Tester is a software tool used to manually diagnose whether the physical digital pins on an Arduino are alive or dead.

invisible_mess_glasses_relay_schema_1772681179521.png

The Diagnostic Code Structure

Instead of explicitly writing digitalWrite(13, HIGH), the code makes the pin number a variable that the user types in via the computer.

  1. The Setup: A for loop cycles from pin 2 to pin 13, setting them all to OUTPUT.
  2. The Command Interpreter: if (Serial.available()). The Arduino listens for the user to type something like "8 ON" or "8 1".
  3. The Extraction: The Serial.parseInt() command strips out the number 8 and saves it as the targetPin variable.
  4. The Execution: digitalWrite(targetPin, HIGH).

The Physical Test Setup

  • You connect a single LED and resistor to a ground pin.
  • You place the positive leg of the LED into Pin 2.
  • You type "2 ON" in the Serial Monitor. If the LED lights up, pin 2 is fine!
  • You pull the LED out, plug it into Pin 3, type "3 ON". You repeat this for the entire row of header pins.
  • If pin 6 doesn't light the LED, you know the internal micro-transistor is blown, and you must avoid using pin 6 in future projects!

System Requires:

  • Arduino Uno/Nano/Mega: The board being tested.
  • USB Cable: For typing commands.
  • 1 LED and 1 Resistor.

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

title: "Arduino digital pin testing with serial monitor"
description: "Diagnose your board! Write a utility sketch that actively listens to the Serial Monitor and toggles specific digital pins to verify if they are functional."
category: "Tools & Equipment"
difficulty: "Easy"