กลับไปหน้ารวมไฟล์
interface-a-photoresistor-91b736-en.md

Ambient Math: Interfacing the Photoresistor

The Photoresistor (LDR - Light Dependent Resistor) is fundamentally the second most important component in embedded hardware (after the LED). It teaches the core engineering concept of the "Voltage Divider," which is required to measure almost every single analog sensor in existence from thermistors to flex-sensors.

photoresistor_basic_circuit_1772704138840.png

The Problem With Raw Resistance

The Arduino analog pin (e.g., A0) measures Voltage (from 0 to 5V). It does NOT measure Resistance.

  1. An LDR changes its resistance based on light. In total darkness, its resistance is massive (1 MegOhm). In bright sunlight, its resistance drops beautifully to 100 Ohms.
  2. If you plug an LDR directly into 5V and A0, the pin will read a flat 1023 all day long because it's just reading the raw voltage pushing through the resistor.

The Voltage Divider Solution

Because the Arduino only understands voltage, we must convert the varying resistance into varying voltage.

  1. You build a bridge.
  2. You connect 5V to one leg of the LDR.
  3. You tie the other leg of the LDR to BOTH the A0 pin AND a 10K Ohm fixed resistor.
  4. You tie the other end of the 10K resistor to Ground.
  5. The Physics Result: When the LDR changes resistance, it essentially "fights" the fixed 10K resistor. The mathematical pressure between them changes. The point between them (A0) now experiences a massive voltage swing!
  6. If you cover the LDR, analogRead(A0) drops to 200. Shine a light, it hits 900.

Writing the Control Logic

Now the physical light is a variable (int lightValue). We can control the world.

  • if (lightValue < 400) { digitalWrite(LED_BUILTIN, HIGH); }
  • You have just successfully engineered the exact same automated logic system used by streetlamps worldwide!

Needed Base Hardware

  • Arduino Uno/Nano.
  • One Cadmium-Sulfide (CdS) Photoresistor / LDR.
  • One 10K Ohm Resistor (Required for the voltage divider math).

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

title: "Interface a Photoresistor"
description: "The classic LDR! Master the foundational electronics skill of building voltage dividers to convert changing light levels into mathematical variables inside the Arduino IDE."
category: "Basic Electronics"
difficulty: "Easy"