කලාව
රූපලාවණ්‍ය සහ සුවතාව
ශිල්පය
සංස්කෘතිය සහ ඉතිහාසය
විනෝදාස්වාදය
පරිසරය
ආහාර සහ පාන
ප්‍රතිලෝම ඉංජිනේරු
විද්‍යාවන්
ක්‍රීඩා
තාක්ෂණය
පැළඳිය හැකි
Reading a Photoresistor — SIK Circuit 6
Ed

නිර්මාතෘ

Ed

17. මාර්තු 2026FI
85
0
0
0
0

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

මෙම පියවර සඳහා ද්‍රව්‍ය:

SparkFun Inventor's Kit - V3.2SparkFun Inventor's Kit - V3.21 කට්ටලය

අවශ්‍ය මෙවලම්:

Computer with Arduino IDEComputer with Arduino IDE
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.

මෙම පියවර සඳහා ද්‍රව්‍ය:

BreadboardBreadboard1 කැබැල්ල
Jumper WiresJumper Wires5 කැබලි
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);
}

මෙම පියවර සඳහා ද්‍රව්‍ය:

Arduino Uno R3Arduino Uno R31 කැබැල්ල

අවශ්‍ය මෙවලම්:

Computer with Arduino IDEComputer with Arduino IDE
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).

ද්‍රව්‍ය

8
  • SparkFun Inventor's Kit - V3.210% කොමිස්
    1 කට්ටලය
    $108.84
  • Breadboard10% කොමිස්
    1 කැබැල්ල
    Magento Legacy Storeships internationally
    සිට$9.76
  • Jumper Wires10% කොමිස්
    5 කැබලි
    Magento Legacy Storeships internationally
    සිට$4.27
  • Arduino Uno R310% කොමිස්
    1 කැබැල්ල
    Magento Legacy Storeships internationally
    සිට$27.80
  • 1 කැබැල්ල
    ස්ථානගත
  • 5mm LED10% කොමිස්
    1 කැබැල්ල
    Magento Legacy Storeships internationally
    සිට$3.66
  • 1 කැබැල්ල
    ස්ථානගත
  • 10K Ohm Resistor10% කොමිස්
    1 කැබැල්ල
    Magento Legacy Storeships internationally
    සිට$1.22

අවශ්‍ය මෙවලම්

1
  • ස්ථානගත
ඇස්තමේන්තුගත එකතුව
නිර්මාණකරු මිලදී ගත් දේ. මිලක් නොමැතිව පෙන්වන ද්‍රව්‍ය ඔබ මිලදී ගන්නා තැනින් ලැබේ.
$108.84

CC0 පොදු වසම

මෙම බ්ලූප්‍රින්ට් CC0 යටතේ නිකුත් කර ඇත. ඔබට අවසර නොමැතිව පිටපත් කිරීම, වෙනස් කිරීම, බෙදා හැරීම සහ භාවිතා කිරීම කළ හැක.

බ්ලූප්‍රින්ට් හරහා නිෂ්පාදන මිලදී ගැනීමෙන් නිර්මාතෘට සහාය වන්න නිර්මාතෘ කොමිසම විකුණුම්කරුවන් විසින් නියම කළ, හෝ මෙම බ්ලූප්‍රින්ට්හි නව අනුවාදයක් සාදා ආදායම බෙදා ගැනීමට ඔබේ බ්ලූප්‍රින්ට්හි සම්බන්ධතාවයක් ලෙස ඇතුළත් කරන්න.

සාකච්ඡාව

(0)

පිවිසෙන්න සාකච්ඡාවට එක්වීමට

අදහස් පූරණය කරමින්...