กลับไปหน้ารวมไฟล์
automatic-night-light-arduino-0d9353.md

โปรเจกต์นี้ง่ายมากและหวังว่าคุณจะสนุกกับมัน! นี่คือไฟ RGB/บรรยากาศที่จะเปิดโดยอัตโนมัติเมื่อคุณปิดไฟในห้องของคุณ!

คุณต้องทำการเชื่อมต่อเหล่านี้:

เชื่อมต่อขาหนึ่งของ photoresistor เข้ากับ 5V (ขั้วบวก) เชื่อมต่อขาอีกข้างของ photoresistor เข้ากับขาหนึ่งของตัวต้านทาน 1 Megaohm หรือ 100kohm จุดเชื่อมต่อระหว่าง photoresistor และตัวต้านทานจะเชื่อมต่อกับขา A0 ของ Arduino เชื่อมต่อขาอีกข้างของตัวต้านทานเข้ากับ GND (ขั้วลบ)

เชื่อมต่อ LED (อนุกรมกับ current-limiting resistor) เข้ากับ digital pin 10 ของ Arduino ขาอีกข้างของ LED เชื่อมต่อกับ GND (ขั้วลบ) *สำคัญ: สังเกตขั้วของ LED! ขาสั้นเชื่อมต่อกับขั้วลบ*


🛠️ เจาะลึก / การวิเคราะห์ทางเทคนิค

โปรเจกต์ Automatic Night Light เป็นก้าวแรกที่คลาสสิกสู่ environmental robotics มันสอนหลักการพื้นฐานของการรับ analog input (สถานะสิ่งแวดล้อม) เพื่อเรียกใช้ digital threshold (การกระตุ้น) โดยทำหน้าที่เป็น dawn-to-dusk sensor พื้นฐาน

Analog-to-Digital Conversion (ADC)

Arduino "มองเห็น" แสงผ่าน LDR (Light Dependent Resistor)

  1. Voltage Divider: คุณต้องจับคู่ LDR กับ fixed resistor (เช่น 10k-ohm) ในวงจร เมื่อแสงเปลี่ยน ความต้านทานของ LDR ก็จะเปลี่ยน ซึ่งจะทำให้แรงดันไฟฟ้าที่เข้าสู่ขา A0 ของ Arduino เปลี่ยนแปลงไป
  2. การอ่านค่า: ฟังก์ชัน analogRead(A0) จะรับแรงดันไฟฟ้า 0-5V นั้นและแปลงเป็นตัวเลขระหว่าง 0 ถึง 1023
    • แสงสว่างจ้า = 900
    • มืดสนิท = 150

เกณฑ์การควบคุม

แทนที่จะใช้สมการที่ซับซ้อน คุณสามารถสร้างขอบเขต threshold แบบตรรกะที่เรียบง่ายได้:

int lightThreshold = 400; // Calibrate this number based on your room

if (analogRead(A0) < lightThreshold) {
  digitalWrite(ledPin, HIGH); // Turn lights ON in the dark
} else {
  digitalWrite(ledPin, LOW); // Turn lights OFF in the light
}

การเพิ่มการเฟดที่นุ่มนวล

เพื่อสัมผัสที่พิเศษยิ่งขึ้น แทนที่จะเปิดไฟทันที (digitalWrite) คุณสามารถใช้ฟังก์ชัน map() ได้ คุณเชื่อมโยงระดับความมืดเข้ากับขา analogWrite(PWM) โดยตรง เมื่อพระอาทิตย์ค่อยๆ ตกดิน LED ก็จะค่อยๆ สว่างขึ้นและสว่างขึ้นอย่างนุ่มนวลไร้รอยต่อ!

ข้อกำหนดฮาร์ดแวร์พื้นฐาน

  • Arduino Uno/Nano: ประตูตรรกะ (logic gate).
  • LDR (Photoresistor).
  • 10k-ohm Resistor: จำเป็นสำหรับ voltage divider.
  • LED หรือ small 5V Relay module.

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

title: "Automatic Night Light! Arduino"
description: "This will automatically make your room better!"
author: "hacky-tube13"
category: ""
tags:
  - "gaming light"
  - "automatic night light"
  - "night light"
views: 1849
likes: 0
price: 435
difficulty: "Intermediate"
components:
  - "1x LED (generic)"
  - "1x Resistor 1M ohm"
  - "1x Photo resistor"
  - "1x Breadboard (generic)"
  - "1x Arduino UNO"
  - "1x Resistor 220 ohm"
  - "1x Jumper wires (generic)"
tools: []
apps:
  - "1x Arduino IDE"
downloadableFiles: []
documentationLinks: []
passwordHash: "4046082aa776c0e61047dd580e8ec8e549a1405cbbab6efb57ec37c17f3f7836"
encryptedPayload: "U2FsdGVkX1+DSSGEgxo7pEZS2mNlZZHDp1CMa54RDpMScaWHVnEefYOwi1GeWhEycUhefaUzQ/l6j5+5FapYlZl5xQXlUpynXW8pVcugt9Y="
seoDescription: "Build an Automatic Night Light with Arduino to improve your room's atmosphere and convenience automatically."
videoLinks: []
heroImage: "https://cdn.jsdelivr.net/gh/bigboxthailand/arduino-assets@main/images/projects/automatic-night-light-arduino-0d9353_cover.jpg"
lang: "th"