Cirkit Designer Logo
Cirkit Designer
Your all-in-one circuit design IDE
Home / 
Component Documentation

How to Use YL-40: Examples, Pinouts, and Specs

Image of YL-40
Cirkit Designer LogoDesign with YL-40 in Cirkit Designer

Introduction

The YL-40 module is a versatile photoelectric sensor designed to measure environmental factors such as humidity and temperature. It is commonly used in a wide range of applications, including home automation, weather stations, and Internet of Things (IoT) projects. Its ease of use and accuracy make it a popular choice for hobbyists and professionals alike.

Explore Projects Built with YL-40

Use Cirkit Designer to design, explore, and prototype these projects online. Some projects support real-time simulation. Click "Open Project" to start designing instantly!
Battery-Powered Line Following Robot with IR Sensors and Cytron URC10 Motor Controller
Image of URC10 SUMO AUTO: A project utilizing YL-40 in a practical application
This circuit is a robotic control system that uses multiple IR sensors for line detection and obstacle avoidance, powered by a 3S LiPo battery. The Cytron URC10 motor driver, controlled by a microcontroller, drives two GM25 DC motors based on input from the sensors and a rocker switch, with a 7-segment panel voltmeter displaying the battery voltage.
Cirkit Designer LogoOpen Project in Cirkit Designer
ESP32-Based Automated Plant Watering System with Soil Moisture Sensing
Image of Agro-Shield transmitter and water pump motor circuit diagram: A project utilizing YL-40 in a practical application
This is a soil moisture monitoring and water pump control system. It uses an ESP32 microcontroller to read soil moisture levels through a YL-69 sensor and YL-83 LM393 module, and controls a water pump via a 5V relay based on the moisture data. The system is powered by a series-parallel arrangement of 18650 batteries, with a buck converter regulating the voltage.
Cirkit Designer LogoOpen Project in Cirkit Designer
WiFi LoRa Environmental Monitoring System with INMP441 Mic and Multiple Sensors
Image of ba_sensing: A project utilizing YL-40 in a practical application
This circuit is a solar-powered environmental monitoring system that uses a WiFi LoRa 32V3 microcontroller to collect data from various sensors, including a microphone, UV light sensor, air quality sensor, and temperature/humidity/pressure sensor. The collected data is processed and transmitted via LoRa communication, making it suitable for remote environmental data logging and monitoring applications.
Cirkit Designer LogoOpen Project in Cirkit Designer
Battery-Powered Laser Emitter with Solar Charging and LED Indicator
Image of rx: A project utilizing YL-40 in a practical application
This circuit is a solar-powered laser emitter system with an LED indicator. The solar panel charges a 18650 battery via a TP4056 charging module, and a push button controls the activation of the laser emitter and the LED through a MOSFET switch.
Cirkit Designer LogoOpen Project in Cirkit Designer

Explore Projects Built with YL-40

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 URC10 SUMO AUTO: A project utilizing YL-40 in a practical application
Battery-Powered Line Following Robot with IR Sensors and Cytron URC10 Motor Controller
This circuit is a robotic control system that uses multiple IR sensors for line detection and obstacle avoidance, powered by a 3S LiPo battery. The Cytron URC10 motor driver, controlled by a microcontroller, drives two GM25 DC motors based on input from the sensors and a rocker switch, with a 7-segment panel voltmeter displaying the battery voltage.
Cirkit Designer LogoOpen Project in Cirkit Designer
Image of Agro-Shield transmitter and water pump motor circuit diagram: A project utilizing YL-40 in a practical application
ESP32-Based Automated Plant Watering System with Soil Moisture Sensing
This is a soil moisture monitoring and water pump control system. It uses an ESP32 microcontroller to read soil moisture levels through a YL-69 sensor and YL-83 LM393 module, and controls a water pump via a 5V relay based on the moisture data. The system is powered by a series-parallel arrangement of 18650 batteries, with a buck converter regulating the voltage.
Cirkit Designer LogoOpen Project in Cirkit Designer
Image of ba_sensing: A project utilizing YL-40 in a practical application
WiFi LoRa Environmental Monitoring System with INMP441 Mic and Multiple Sensors
This circuit is a solar-powered environmental monitoring system that uses a WiFi LoRa 32V3 microcontroller to collect data from various sensors, including a microphone, UV light sensor, air quality sensor, and temperature/humidity/pressure sensor. The collected data is processed and transmitted via LoRa communication, making it suitable for remote environmental data logging and monitoring applications.
Cirkit Designer LogoOpen Project in Cirkit Designer
Image of rx: A project utilizing YL-40 in a practical application
Battery-Powered Laser Emitter with Solar Charging and LED Indicator
This circuit is a solar-powered laser emitter system with an LED indicator. The solar panel charges a 18650 battery via a TP4056 charging module, and a push button controls the activation of the laser emitter and the LED through a MOSFET switch.
Cirkit Designer LogoOpen Project in Cirkit Designer

Technical Specifications

Key Technical Details

  • Operating Voltage: 3.3V to 5V
  • Temperature Measurement Range: -40°C to 80°C
  • Humidity Measurement Range: 0% to 100% RH
  • Temperature Measurement Accuracy: ±0.5°C
  • Humidity Measurement Accuracy: ±2% RH
  • Interface: I2C

Pin Configuration and Descriptions

Pin Number Pin Name Description
1 VCC Power supply (3.3V to 5V)
2 GND Ground
3 SDA I2C Data Line
4 SCL I2C Clock Line

Usage Instructions

Connecting to a Circuit

To use the YL-40 sensor module with an Arduino UNO, follow these steps:

  1. Connect the VCC pin of the YL-40 to the 5V output on the Arduino.
  2. Connect the GND pin to one of the GND pins on the Arduino.
  3. Connect the SDA pin to the A4 pin (SDA) on the Arduino.
  4. Connect the SCL pin to the A5 pin (SCL) on the Arduino.

Programming the Arduino

Here is a sample code snippet to read temperature and humidity data from the YL-40 sensor using an Arduino UNO. Before using the code, make sure to install the necessary libraries for handling the I2C communication.

#include <Wire.h>

// YL-40 I2C address (check datasheet for your module)
const int YL40_I2C_ADDRESS = 0xXX; // Replace 0xXX with the actual address

void setup() {
  Wire.begin(); // Initialize I2C communication
  Serial.begin(9600); // Start serial communication at 9600 baud rate
}

void loop() {
  // Request 4 bytes of data from the YL-40 sensor
  Wire.beginTransmission(YL40_I2C_ADDRESS);
  Wire.requestFrom(YL40_I2C_ADDRESS, 4);
  
  // Read the data if available
  if (Wire.available() == 4) {
    float humidity = Wire.read() * 256 + Wire.read();
    humidity /= 10;
    float temperature = Wire.read() * 256 + Wire.read();
    temperature /= 10;
    
    // Print the readings to the serial monitor
    Serial.print("Humidity: ");
    Serial.print(humidity);
    Serial.print("% RH, Temperature: ");
    Serial.print(temperature);
    Serial.println("C");
  }
  
  // Wait for 2 seconds before reading again
  delay(2000);
}

Important Considerations and Best Practices

  • Ensure that the power supply voltage matches the operating voltage of the YL-40 module to prevent damage.
  • Use pull-up resistors on the SDA and SCL lines if multiple I2C devices are connected to the same bus.
  • Avoid placing the sensor near heat sources or in direct sunlight to prevent inaccurate readings.
  • For long-term monitoring, implement error handling and reconnection strategies in your code.

Troubleshooting and FAQs

Common Issues

  • Inaccurate Readings: Ensure the sensor is not affected by external heat sources and is properly calibrated.
  • No Data on Serial Monitor: Check the wiring and ensure the correct I2C address is used in the code.
  • Sensor Not Detected: Verify connections and scan the I2C bus for the correct address.

Solutions and Tips

  • If the sensor readings are unstable, add a delay between readings to allow the sensor to stabilize.
  • Use a logic level converter if you're interfacing the YL-40 with a 3.3V microcontroller to protect the sensor's I2C lines.
  • Regularly update your sensor's firmware if available to ensure optimal performance.

FAQs

Q: Can the YL-40 sensor be used outdoors? A: Yes, but it should be placed in a weatherproof enclosure to protect it from the elements.

Q: How do I calibrate the YL-40 sensor? A: Calibration procedures vary; refer to the manufacturer's guidelines for specific instructions.

Q: What is the I2C address of the YL-40 sensor? A: The default I2C address is typically provided in the sensor's datasheet. If you're unsure, you can run an I2C scanner sketch to find out the address.

Remember to consult the YL-40 sensor's datasheet for more detailed information and specifications.