tscircuit / docs

docs, tutorials and guides for tscircuit
https://docs.tscircuit.com
5 stars 9 forks source link

Light Activated Switch Tutorial with LDR (Light Dependent Resistor and NPN transistor) #26

Open seveibar opened 1 month ago

seveibar commented 1 month ago

The light-activated switch is a simple and practical circuit that uses a light-dependent resistor (LDR) and a transistor to control an output, such as turning on an LED or activating a relay based on ambient light levels. Let’s break down how this circuit works and its components in more depth:

Components:

  1. Light Dependent Resistor (LDR)

    • A special type of resistor whose resistance decreases when exposed to higher light intensity and increases in darkness. It’s used as the sensor in the circuit.
  2. NPN Transistor (e.g., 2N2222 or BC547)

    • Acts as a switch, controlling the current flow to the output device (such as an LED) based on the light level detected by the LDR. An NPN transistor requires a small current at its base to allow a larger current to flow between its collector and emitter.
  3. Resistor (typically 10kΩ or adjustable potentiometer)

    • Connected in series with the LDR to create a voltage divider. This resistor sets the threshold light level at which the transistor switches on or off.
  4. LED (or another output like a buzzer, motor, or relay)

    • The component that responds to the switching action of the transistor. When the transistor is activated, the LED turns on.
  5. Power Supply

    • A typical power supply (such as a 9V battery or 5V DC source) powers the circuit.

Circuit Design:

1. Voltage Divider (LDR + Resistor)

The LDR and a fixed resistor (or a variable resistor like a potentiometer) are connected in series to form a voltage divider. The voltage at the point between the LDR and the resistor is fed into the base of the NPN transistor. This voltage depends on the light intensity:

[ V_{\text{base}} = \frac{R_2}{R_1 + R2} \times V{\text{in}} ]

2. Transistor Operation

3. Output

Working Explanation:

  1. High Light Conditions (Daylight)

    • The LDR’s resistance is low in bright light, and the voltage at the base of the transistor is not sufficient to turn it on.
    • As a result, the transistor remains in the OFF state, and no current flows through the collector-emitter junction. Hence, the output (e.g., the LED) is OFF.
  2. Low Light Conditions (Darkness)

    • In darkness, the LDR’s resistance increases significantly, which increases the voltage across the base of the transistor.
    • When the base-emitter voltage exceeds the transistor’s threshold (typically 0.7V for an NPN transistor), the transistor switches ON, allowing current to flow through the collector-emitter path, lighting up the LED or turning on another output device.

Adjusting Sensitivity:

Applications:

  1. Automatic Street Lights: Turns on lights when it gets dark.
  2. Garden Lighting: Lights up an area when the light level drops in the evening.
  3. Night Lamps: Automatically switches on a lamp when a room becomes dark.
  4. Solar Garden Lights: Detects low light and turns on the LEDs powered by a solar cell and battery.

Improvements and Modifications:

  1. Hysteresis: To avoid rapid switching between ON and OFF states (which could happen due to small light changes), you can introduce hysteresis by adding positive feedback or using a Schmitt trigger.

  2. Relay Control: Instead of powering a low-current device like an LED, you could connect the transistor’s output to a relay, allowing you to control high-power devices like mains-powered lamps, fans, or other appliances.

  3. Dual Control with PNP/NPN Transistors: You can design a circuit that has both light-activated and darkness-activated outputs by using a PNP transistor to handle high-light conditions and an NPN transistor to handle low-light conditions.

Schematic Diagram:

Power Supply (+) ----->---|
                          |
                       [ LDR ]
                          |
                          |------ Base (Transistor)
                       [ Resistor ]
                          |
Power Supply (-) ----->---|------- Emitter (Transistor)

Collector (Transistor) ----->---- LED ----> Ground

In this configuration:

This is a great introduction to transistor switching, sensors (like the LDR), and how basic electronic control systems work.