The KY-018 module is a light sensor based on a photoresist, also known as a light-dependent resistor (LDR) or photocell, which is a type of resistor that changes its resistance in response to the intensity of light falling on it. This module is used for detecting and measuring the intensity of ambient light.
It provides analog output signals that can be conveniently interfaced and read by microcontrollers such as Arduino, Raspberry Pi, ESP32, and others. The data is transmitted using a single-wire analog protocol.
This article will provide detailed information about analog KY-018 light sensor module, including specifications, pinout, circuit & connection diagram, and how to interface with Arduino, and more. Let's get started!
KY-018 Module Specifications
The quick specifications of the KY-018 Photoresistor module is given below:
- Type: Analog
- Module: Light Sensor
- Operating Voltage: DC 3.3V to 5V
- Operating Temperature Range: -30°C to +70°C [-22°F to +158°F]
- Dark resistance: 500kΩ
- Light Sencing Responsce: 30μS
- Spectrumpeak Value: 540
- Board Dimantions (L x W x H): 30mm x 15mm x 6mm
- Weight: 2gm
KY-018 Module Pinout
The module has 3 male header pins those are -
- Pin (S): Analog Signal
- Pin (Middle): DC +3V3 or +5V
- Pin (-): GND
KY-018 Module Circuit Diagram
Schematic of the ky-018 photoresistor (light sensor) module circuit is shown below.
Components are used in the circuit - S1: 5mm LDR, and R1: 10kΩ Resistor.
KY-018 Module Interfacing with Arduino
Connection diagram of the KY-018 Photoresistor module with an Arduino is shown below.
Connect the power pin (middle) and ground pin (-) of the ky-018 module to +5V (or +3.3V) and GND on the Arduino, respectively. The module signal pin (s) connect to digital pin A0 on the Arduino.
Interfacing Working Explanation
The working principle of ky-018 module with arduino board is simple. The photoresistor (S1) in the module acts as a variable resistor that changes its resistance based on the intensity of light falling on it. When more light is present, the resistance decreases, and when less light is present, the resistance increases.
The photoresistor (S1) is connected in a voltage divider configuration with a fixed resistor (R1). The output signal (S) voltage is taken from the junction between the photoresistor and the fixed resistor.
The Arduino's analog input pin is used to read the voltage at the output of the voltage divider. The analog input pin can measure voltages between 0 and 5V and converts them into a digital value.
In the Arduino code, you can use the 'analogRead()' function to read the voltage value from the analog input pin connected to the KY-018 module. The function returns a value between 0 and 1023, representing the analog voltage value.
By mapping the analog input value to the appropriate light intensity range, you can determine the level of light falling on the photoresistor. For example, you can use the 'map()' function to map the analog input value to a specific light intensity range.
Finally, you can use the mapped light intensity value to perform actions or control other components connected to the Arduino based on the detected light level.
Arduino Source Code
Here's a basic Arduino sketch for the KY-018 module, allows you to measure light intensity using the photoresistor and prints the corresponding light intensity level.
const int photoresistorPin = A0; // Arduino analog input pin connected to KY-018 OUT pin (S)
void setup() {
Serial.begin(9600); // Initialize serial communication
}
void loop() {
int sensorValue = analogRead(photoresistorPin); // Read analog value from the photoresistor
// Map the analog value to a light intensity range (adjust the values based on your specific needs)
int lightLevel = map(sensorValue, 0, 1023, 0, 100);
Serial.print("Light Intensity: ");
Serial.print(lightLevel);
Serial.println("%");
delay(1000); // Wait for a second
}
Once you upload the code to your Arduino board, open the Serial Monitor in the Arduino IDE at a baud rate of 9600. You should see the measured light intensity printed every second in the Serial Monitor.
Note that you may need to adjust the mapping values (0, 1023, 0, 100) in the 'map()' function according to the specific characteristics of your KY-018 module and the desired light intensity range you want to work with.
No comments
If you have any doubts or questions, please let me know. Don't add links as it goes to spam. Share your valuable feedback. Thanks