Arduino PhotoResistor Example – KY-018

Hello World! I made another example for one of my sensors. Now we are using the KY-018 Arduino PhotoResistor Sensor as a switch to turn on light when shining some light on it, in the video i turn the light on with a laser, a flashlight, a candle, and a lighter, it does not matter what kind of light you use.
See the next step for the Schematic Code & parts list.

ky-018, Arduino PhotoResistor

Parts list:
Arduino uno, I used the RobotDyn Uno.
KY-019 1 channel Relay
1 Led of any color. I used blue.(Don’t really need this)
KY-018 Photoresistor sensor.
Lamp + socket and power cable (optional) You can an add any device!


Author: Danny van den Brande, BlueCore Tech.
In this example we use the Arduino PhotoResistor as a switch.
Its just some basic code, you can adjust the value at the if statement between 0 and 1023.
int Relay = 2;
int BlueLed = 3;
int Sensor = A0;
int sensorValue;

void setup() {
  pinMode(BlueLed, OUTPUT);
  pinMode(Relay, OUTPUT);
  pinMode(Sensor, INPUT);


void loop() {
  sensorValue = analogRead(Sensor);
  if(analogRead(1)>200 && analogRead(1)< 1023)
    digitalWrite (BlueLed, LOW);
    digitalWrite (Relay, LOW);
    Serial.println(sensorValue, DEC);
    digitalWrite (BlueLed, HIGH);
    digitalWrite (Relay, HIGH);
    Serial.println(sensorValue, DEC);

What is a photoresistor?
A photoresistor (or light-dependent resistor, LDR, or photocell) is a light-controlled variable resistor. The resistance of a photoresistor decreases with increasing incident light intensity; in other words, it exhibits photoconductivity. A photoresistor can be applied in light-sensitive detector circuits, and light- and dark-activated switching circuits.

A photoresistor is made of a high resistance semiconductor. In the dark, a photoresistor can have a resistance as high as several megohms (MΩ), while in the light, a photoresistor can have a resistance as low as a few hundred ohms. If incident light on a photoresistor exceeds a certain frequency, photons absorbed by the semiconductor give bound electrons enough energy to jump into the conduction band. The resulting free electrons (and their hole partners) conduct electricity, thereby lowering resistance. The resistance range and sensitivity of a photoresistor can substantially differ among dissimilar devices. Moreover, unique photoresistors may react substantially differently to photons within certain wavelength bands.


Danny van den Brande

Programmer, Game Designer, 3D Designer, Web Designer, Graphic Designer. Jup this website looks crappy.. :) But enjoy the projects! Everything you need is here.

Leave a Reply

Your email address will not be published. Required fields are marked *