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

This project is really simple and I hope you will enjoy it! This is an RGB/atmosphere light that will automatically turn on when you turn off the light of your room!

You have to do these connections:

Connect one leg of the photoresistor to 5V (positive). Connect the other leg of the photoresistor to one leg of a 1 Megaohm or 100kohm resistor. The junction between the photoresistor and the resistor connects to Arduino's A0 pin. Connect the other leg of the resistor to GND (negative).

Connect the LED (in series with a current-limiting resistor) to Arduino's digital pin 10. The other leg of the LED connects to GND (negative). *Important: Observe LED polarity! The short leg connects to negative.*


🛠️ Deep Dive / Technical Analysis

The Automatic Night Light is a classic first-step into environmental robotics. It teaches the fundamental principle of taking an analog input (environmental state) to trigger a digital threshold (actuation), acting as a basic dawn-to-dusk sensor.

Analog-to-Digital Conversion (ADC)

The Arduino "sees" light through an LDR (Light Dependent Resistor).

  1. The Voltage Divider: You must pair the LDR with a fixed resistor (e.g., 10k-ohm) in a circuit. As light changes, the resistance of the LDR changes, which alters the voltage hitting Arduino pin A0.
  2. The Read: The analogRead(A0) function takes that 0-5V voltage and converts it into a number between 0 and 1023.
    • Bright light = 900
    • Pitch black = 150

The Control Threshold

Instead of a complex equation, you create a simple logical threshold boundary:

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
}

Adding Smooth Fades

For a premium touch, instead of instantly snapping the light on (digitalWrite), you can use the map() function. You link the darkness level directly to an analogWrite(PWM) pin. As the sun slowly sets, the LED will slowly fade brighter and brighter in a perfectly smooth transition!

Basic Hardware Requirements

  • Arduino Uno/Nano: The logic gate.
  • LDR (Photoresistor).
  • 10k-ohm Resistor: Essential for the voltage divider.
  • LED or 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: "en"