กลับไปหน้ารวมไฟล์
make-a-simple-led-flash-6bb3df.md

Make a simple LED flash!

Project Basics

โปรเจกต์ Make a Simple LED Flash เป็น "Hello, World!" อย่างเป็นทางการสำหรับแพลตฟอร์ม Arduino ซึ่งเน้นย้ำถึงความเชื่อมโยงพื้นฐานระหว่างฮาร์ดแวร์และซอฟต์แวร์ สอนให้เห็นว่าโค้ดบรรทัดเดียวสามารถปรากฏให้เห็นทางกายภาพในรูปของไฟกระพริบได้อย่างไร

Hardware Circuit

วงจรถูกออกแบบให้มีขนาดเล็กและเข้าใจง่ายโดยตั้งใจ:

  • LED Anode: เชื่อมต่อกับ Digital Pin (โดยปกติคือ Pin 13)
  • LED Cathode: เชื่อมต่อกับขา Ground (GND) ของ Arduino
  • Resistor: ใช้ 220-ohm resistor ต่ออนุกรมกับ LED เพื่อจำกัดกระแส ป้องกันความเสียหายต่อ LED และขา Arduino

Logic Flow: HIGH and LOW

Arduino ถูกตั้งโปรแกรมให้มีสองสถานะ:

  • HIGH: ส่ง 5V ไปยังขา (pin) ทำให้ LED สว่าง
  • LOW: ส่ง 0V ไปยังขา (pin) ทำให้ LED ดับ

เมื่อรวมสถานะเหล่านี้เข้ากับฟังก์ชัน delay() เราจะสร้างเอฟเฟกต์การกระพริบที่คุ้นเคย:

void loop() {
  digitalWrite(13, HIGH);
  delay(1000); // 1-second delay
  digitalWrite(13, LOW);
  delay(1000);
}

Key Learnings

  • void setup(): ใช้เพื่อบอก Arduino ว่า Pin 13 เป็น OUTPUT
  • void loop(): ใช้สำหรับบรรจุลอจิกที่จะทำงานต่อเนื่องไปเรื่อยๆ จนกว่าจะถอดแหล่งจ่ายไฟ
  • Timing: ด้วยการลดค่า delay คุณสามารถทำให้ LED กระพริบเร็วมากหรือช้ามากก็ได้

Next Steps

เมื่อคุณสามารถทำให้ LED กระพริบได้แล้ว คุณสามารถลองทำสิ่งต่อไปนี้:

  • Adding More LEDs: เชื่อมต่อ LED เพิ่มเติมเข้ากับขา (pin) ที่แตกต่างกัน และทำให้พวกมันกระพริบในรูปแบบที่ต่างกัน
  • Using PWM: ใช้คำสั่ง analogWrite() บนขา PWM เพื่อทำให้ LED ค่อยๆ สว่างขึ้นและหรี่ลงอย่างนุ่มนวล แทนที่จะเป็นการกระพริบ
  • Adding a Sensor: ใช้ปุ่มหรือ light sensor เพื่อกระตุ้นการกระพริบ

โปรเจกต์ง่ายๆ นี้เป็นก้าวแรกสู่การสร้างอุปกรณ์และหุ่นยนต์ที่ซับซ้อนยิ่งขึ้น

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

title: "Make a simple LED flash!"
description: "Simple LED blink/flash."
author: "shassandanish1"
category: "Lights & LEDs"
tags:
  - "blink"
  - "led"
  - "arduino"
views: 3154
likes: 0
price: 435
difficulty: "Easy"
components:
  - "1x LED (generic)"
  - "1x Resistor 220 ohm"
  - "1x Arduino UNO"
  - "10x Jumper wires (generic)"
tools: []
apps:
  - "1x Arduino IDE"
downloadableFiles: []
documentationLinks: []
passwordHash: "..."
encryptedPayload: "..."
seoDescription: "Simple and easy project to make an LED flash and blink with an Arduino."
heroImage: "https://cdn.jsdelivr.net/gh/bigboxthailand/arduino-assets@main/images/projects/make-a-simple-led-flash-6bb3df_cover.jpg"
lang: "th"