فن
خوبصورتی اور تندرستی
دستکاری
ثقافت اور تاریخ
تفریح
ماحول
خوراک اور مشروبات
سبز مستقبل
ریورس انجینئرنگ
سائنسز
کھیل
ٹیکنالوجی
پہننے والے آلات
Reading a Photoresistor — SIK Circuit 6
Ed

تخلیق کار

Ed

17. March 2026

Reading a Photoresistor — SIK Circuit 6

Use a photoresistor (light sensor) to control LED brightness. Learn about voltage dividers, analog input, and the map() function for sensor-to-output conversion.

ہدایات

1

Parts & Introduction

A photoresistor (or LDR — Light Dependent Resistor) changes resistance based on light levels. Combined with a fixed resistor, it forms a voltage divider that the Arduino can read as an analog value. You'll use this to control LED brightness automatically.

Parts Needed

  • 1x Arduino Uno + USB cable
  • 1x Breadboard
  • 1x Photoresistor
  • 1x LED (any color)
  • 1x 330Ω Resistor
  • 1x 10KΩ Resistor (for voltage divider)
  • 6x Jumper Wires
2

Hardware Hookup

Wiring Instructions

  1. Connect one side of the photoresistor to 5V.
  2. Connect the other side to Analog Pin A0.
  3. Connect a 10K resistor from Analog Pin A0 to GND (this completes the voltage divider).
  4. Connect the LED positive leg to Digital Pin 9 (PWM-capable).
  5. Connect the LED negative leg through a 330Ω resistor to GND.

The voltage divider produces a voltage proportional to light level, which the Arduino reads as 0-1023.

3

Arduino Code

Open the Arduino IDE and upload the following sketch to your Arduino board.

photoresistor.inoarduino
/*
SparkFun Inventor's Kit
Example sketch 06 — PHOTORESISTOR

Use a photoresistor (light sensor) to control LED brightness.

Hardware connections:
  Photoresistor: one side to 5V, other side to analog pin 0
  10K resistor between analog pin 0 and GND
  LED: positive to digital pin 9 (PWM), negative through 330 ohm to GND

This code is completely free for any use.
*/

const int sensorPin = 0;
const int ledPin = 9;

int lightLevel, high = 0, low = 1023;

void setup()
{
  pinMode(ledPin, OUTPUT);
}

void loop()
{
  lightLevel = analogRead(sensorPin);

  manualTune();

  //autoTune();

  analogWrite(ledPin, lightLevel);
}

void manualTune()
{
  lightLevel = map(lightLevel, 0, 1023, 0, 255);
  lightLevel = constrain(lightLevel, 0, 255);
}

void autoTune()
{
  if (lightLevel < low)
  {
    low = lightLevel;
  }
  if (lightLevel > high)
  {
    high = lightLevel;
  }

  lightLevel = map(lightLevel, low+30, high-30, 0, 255);
  lightLevel = constrain(lightLevel, 0, 255);
}
4

Test & Experiment

What You Should See

The LED brightness changes based on ambient light. Cover the photoresistor to dim or brighten the LED (depending on orientation).

Troubleshooting

  • LED stays dark: Check LED polarity. Also verify the photoresistor is in the circuit correctly.
  • Not responding to light: The photoresistor spacing is non-standard — make sure both legs are making good contact.
  • Subtle changes: Try using a flashlight or covering the sensor completely for more dramatic results.

Experiments to Try

  • Uncomment autoTune() to let the Arduino automatically calibrate to your lighting conditions.
  • Use the sensor to trigger actions at specific light thresholds (e.g., turn on a "night light" when dark).

مواد

  • SparkFun Inventor's Kit - V3.2 - 1 kitNOK 999.20
    دیکھیں
  • Arduino Uno R3 - 1 pieceپلیس ہولڈر
    دیکھیں
  • Breadboard - 1 pieceپلیس ہولڈر
    دیکھیں
  • Photoresistor - 1 pieceپلیس ہولڈر
    دیکھیں
  • 5mm LED - 1 pieceپلیس ہولڈر
    دیکھیں
  • 330 Ohm Resistor - 1 pieceNOK 24.00
    دیکھیں
  • 10K Ohm Resistor - 1 pieceNOK 24.00
    دیکھیں
  • Jumper Wires - 6 piecessNOK 39.20
    دیکھیں

درکار اوزار

  • Computer with Arduino IDE

CC0 پبلک ڈومین

یہ بلیو پرنٹ CC0 کے تحت جاری کیا گیا ہے۔ آپ اجازت لیے بغیر اس کام کو نقل، ترمیم، تقسیم اور کسی بھی مقصد کے لیے استعمال کرنے کے لیے آزاد ہیں۔

میکر کی حمایت کریں ان کے بلیو پرنٹ کے ذریعے پروڈکٹس خرید کر جہاں وہ میکر کمیشن وینڈرز کی طرف سے مقرر، کماتے ہیں، یا اس بلیو پرنٹ کی نئی تکرار بنائیں اور آمدنی شیئر کرنے کے لیے اسے اپنے بلیو پرنٹ میں کنکشن کے طور پر شامل کریں۔

بحث

(0)

لاگ ان بحث میں شامل ہونے کے لیے

تبصرے لوڈ ہو رہے ہیں...