Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

How to Use Light Sensor w Relay: Examples, Pinouts, and Specs

Image of Light Sensor w RelayDesign with Light Sensor w Relay in Cirkit Designer

Introduction

The XHM131 Light Sensor w Relay is a versatile electronic component designed to detect ambient light levels and activate a relay based on user-defined thresholds. This component is ideal for automating devices such as lights, fans, or other appliances, making it a popular choice for home automation, industrial applications, and DIY projects. Manufactured in China, the XHM131 combines a light-dependent resistor (LDR) for light detection and a relay module for switching high-power devices.

Explore Projects Built with Light Sensor w Relay

Use Cirkit Designer to design, explore, and prototype these projects online. Some projects support real-time simulation. Click "Open Project" to start designing instantly!
Image of LDR-Activated Relay Control for Dual Bulb Illumination: A project utilizing Light Sensor w Relay in a practical application
LDR-Activated Relay Control for Dual Bulb Illumination

This circuit appears to be a light-activated switch controlling two bulbs using a 5V relay, with an LDR (Light Dependent Resistor) as the sensor. The relay is powered by a 48V to 5V converter, which is switched on by a 12V battery through an SPST toggle switch. The LDR's output is connected to the relay's input, enabling the relay to switch the bulbs on or off based on the ambient light level detected by the LDR.

Open Project in Cirkit Designer
Image of Arduino UNO-Based Smart Lighting System with Motion Detection and Energy Monitoring: A project utilizing Light Sensor w Relay in a practical application
Arduino UNO-Based Smart Lighting System with Motion Detection and Energy Monitoring

This circuit is designed to monitor and control lighting based on ambient light levels and motion detection. It uses an Arduino UNO to read data from an LDR and two HC-SR501 motion sensors, and controls a 2-channel relay module to turn lights on or off. The system also measures current and voltage, displays these values on an LCD, and can be remotely controlled or monitored via the Blynk platform.

Open Project in Cirkit Designer
Image of Wi-Fi Enabled Motion-Activated Lighting System with Radar Sensor: A project utilizing Light Sensor w Relay in a practical application
Wi-Fi Enabled Motion-Activated Lighting System with Radar Sensor

This circuit is designed to control an AC LED bulb using a 220V power source, with an infrared motion sensor and an MMWave radar sensor providing input signals. The two-channel relay is used to switch the LED bulb on and off based on the sensor inputs, while the ESP8266 microcontroller is likely programmed to process the sensor data and control the relay. A converter is included to interface between the sensors, microcontroller, and the relay, ensuring proper voltage levels.

Open Project in Cirkit Designer

Common Applications and Use Cases

Technical Specifications

Key Technical Details

Pin Configuration and Descriptions

The XHM131 module has a total of 6 pins and terminals for input and output connections. Below is the pinout description:

Pin/Terminal Label Description
1 VCC Connect to a 5V DC power supply.
2 GND Ground connection.
3 OUT Digital output pin that indicates the light detection status (HIGH or LOW).
4 NC Normally Closed terminal of the relay.
5 COM Common terminal of the relay.
6 NO Normally Open terminal of the relay.

Usage Instructions

How to Use the Component in a Circuit

  1. Power the Module: Connect the VCC pin to a 5V DC power source and the GND pin to ground.
  2. Adjust the Sensitivity: Use the onboard potentiometer to set the light threshold at which the relay activates.
  3. Connect the Load:
    • For devices that should turn ON when light is detected, connect the load between the NO (Normally Open) and COM (Common) terminals.
    • For devices that should turn OFF when light is detected, connect the load between the NC (Normally Closed) and COM terminals.
  4. Monitor the Output: The OUT pin provides a digital signal (HIGH or LOW) that can be read by a microcontroller like an Arduino.

Important Considerations and Best Practices

Example: Connecting to an Arduino UNO

Below is an example of how to use the XHM131 with an Arduino UNO to control an LED based on ambient light levels.

Circuit Connections

Arduino Code

// Define the pin connected to the XHM131 OUT pin
const int lightSensorPin = 2;  
// Define the pin connected to the relay (NO terminal)
const int relayPin = 13;  

void setup() {
  pinMode(lightSensorPin, INPUT);  // Set the light sensor pin as input
  pinMode(relayPin, OUTPUT);       // Set the relay pin as output
  digitalWrite(relayPin, LOW);     // Ensure the relay is off initially
  Serial.begin(9600);              // Initialize serial communication
}

void loop() {
  int lightStatus = digitalRead(lightSensorPin);  // Read the light sensor output
  
  if (lightStatus == HIGH) {
    // If light is detected, activate the relay
    digitalWrite(relayPin, HIGH);
    Serial.println("Light detected: Relay ON");
  } else {
    // If no light is detected, deactivate the relay
    digitalWrite(relayPin, LOW);
    Serial.println("No light detected: Relay OFF");
  }
  
  delay(500);  // Add a small delay for stability
}

Troubleshooting and FAQs

Common Issues and Solutions

  1. Relay Not Activating

    • Cause: Insufficient power supply or incorrect wiring.
    • Solution: Verify that the VCC pin is receiving a stable 5V DC and check all connections.
  2. Erratic Behavior

    • Cause: Electrical noise or unstable power supply.
    • Solution: Use a decoupling capacitor (e.g., 100µF) across the VCC and GND pins to stabilize the power supply.
  3. Relay Stuck in One State

    • Cause: Incorrect potentiometer adjustment.
    • Solution: Adjust the potentiometer to set the desired light threshold.
  4. Arduino Not Detecting Output

    • Cause: Incorrect pin configuration or faulty module.
    • Solution: Ensure the OUT pin is connected to the correct Arduino pin and test the module with a multimeter.

FAQs

This concludes the documentation for the XHM131 Light Sensor w Relay.