कला
सुन्दरता र कल्याण
हस्तकला
संस्कृति र इतिहास
मनोरञ्जन
वातावरण
खाना र पेय
रिभर्स इन्जिनियरिङ
विज्ञान
खेलकुद
प्रविधि
पहिर्न मिल्ने
Reading a Photoresistor — SIK Circuit 6
Ed

सिर्जनाकर्ता

Ed

17. मार्च 2026FI
८१

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

Materials for this step:

SparkFun Inventors Kit - V3.2SparkFun Inventors Kit - V3.21 किट
Arduino Uno R31 टुक्रा
Breadboard1 टुक्रा
Photoresistor1 टुक्रा
5mm LED1 टुक्रा
330 Ohm Resistor330 Ohm Resistor1 टुक्रा
10K Ohm Resistor10K Ohm Resistor1 टुक्रा
Jumper WiresJumper Wires5 टुक्रा

Tools needed:

Computer 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.

Materials for this step:

Photoresistor1 टुक्रा
5mm LED1 टुक्रा
330 Ohm Resistor330 Ohm Resistor1 टुक्रा
10K Ohm Resistor10K Ohm Resistor1 टुक्रा
Breadboard1 टुक्रा
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);
}

Materials for this step:

Arduino Uno R31 टुक्रा

Tools needed:

Computer 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

आवश्यक उपकरणहरू

1
  • Computer with Arduino IDE
Estimated Total
$141.00

CC0 सार्वजनिक डोमेन

यो ब्लुप्रिन्ट CC0 अन्तर्गत जारी गरिएको छ। तपाईं अनुमति नसोधी प्रतिलिपि, परिमार्जन, वितरण र प्रयोग गर्न सक्नुहुन्छ।

ब्लुप्रिन्ट मार्फत उत्पादनहरू किनेर सिर्जनाकर्तालाई सहयोग गर्नुहोस् सिर्जनाकर्ता कमिसन विक्रेताले तोकेको, वा यो ब्लुप्रिन्टको नयाँ संस्करण बनाउनुहोस् र आम्दानी बाँड्न आफ्नो ब्लुप्रिन्टमा जडानको रूपमा समावेश गर्नुहोस्।

छलफल

(0)

लग इन छलफलमा सामेल हुन

टिप्पणीहरू लोड गर्दै...