How to Use a Photoresistor (or Photocell) - Arduino Tutorial

254,191

293

16

Introduction: How to Use a Photoresistor (or Photocell) - Arduino Tutorial

About: Arduino Tutorials by Codebender.cc Team

A photoresistor or photocell is a light-controlled variable resistor. The resistance of a photoresistor decreases with increasing incident light intensity. A photoresistor can be applied in light-sensitive detector circuits, and light- and dark-activated switching circuits. It's also called light-dependent resistor (LDR).

In this tutorial you will learn how to use a photoresistor with and without arduino uno.

So, let's get started!

Step 1: How to Use Photoresistor

Let's see how a photoresistor react in light. Build the circuit above and notice how led brightness change.

The resistance value becomes smaller when there is much light in the room. So in the dark the led remains off because the resistance has become very big.

The Arduino will help us to reverse this situation, let's see how in next step.

Step 2: The Circuit

You will need:

  • Arduino uno
  • Breadboard
  • LED
  • 220 Ohm & 10 KOhm resistors
  • Photoresistror

Step 3: The Code

Here's the 'led & photoresistor' code, embedded using codebender!

How it works:

  • Read analog value from photoresistor/photocell
    -> value=analogRead(pResistor)
  • Check if value is bigger than e.g. 25
  • Send command to turn on/off the led

Try downloading the codebender plugin and clicking on the Run on Arduino button to program your Arduino with this sketch. And that's it, you've programmed your Arduino board!

You can keep playing with that by clicking the "Edit" button and start making your own modifications to the code.

For example, try to change "25" value and see how it changes the program.

Step 4: Well Done!

You have successfully completed one more Arduino "How to" tutorial and you learned how to use a photoresistor!

I hope you liked this, let me know in the comments.

There will be more of them, so make sure to click Follow button!

Be the First to Share

    Recommendations

    • For the Home Contest

      For the Home Contest
    • Make It Bridge

      Make It Bridge
    • Game Design: Student Design Challenge

      Game Design: Student Design Challenge

    16 Comments

    0
    zaqili
    zaqili

    Question 2 years ago on Step 2

    could you explain on why do you connect the bread board that way

    0
    Neutrino_bucketlist
    Neutrino_bucketlist

    3 years ago

    I doubt anyone is still reading this in 2020, but here is my take on this.

    If you set a global variable equal to A5, then hook up just the photoresistor (with a 10k resistor in series with the ground) and read the inputs with the serial monitor on a 1 second delay (so you can read the numbers and see what the high and low is). Once you know those numbers set the lightVal to 50 to 75 below the lowest number you saw, maybe out of 100 or so values.

    Then do the if statement something like this, if(lightVal > lightCal -100 || lightVal == lightCal-100). At the end of the loop put in a 400ms delay. Those 2 settings with take pretty much all of the chatter out.

    I hooked this circuit up to a relay module and wired in a 120v light since I plan on using this for my porch lights. That's why I had a "chatter".

    0
    agent oo7
    agent oo7

    5 years ago

    Sorry,but the program isn't going to get cuted and paseted,and the ''run on

    arduino'' button isn't working .could you tell me please how to get it working?

    0
    MuhK
    MuhK

    5 years ago

    thank u very much for make it simple

    0
    yashb62
    yashb62

    5 years ago

    are resistors imp.

    0
    geraldlec
    geraldlec

    5 years ago

    Hello,

    I'm new to arduino, had to replace the 10 KOhm with a 1 KOhm

    With 1KOhm:

    if (value > 25) led stays off

    50: led on if i cover the photoresistor

    100: led on at 2 or 3 mm from the photoresistor

    With 330 Ohm:

    100: led on if i put my hand between photoresistor and window (source light)

    Thanks a lot,

    Very fun :)

    0
    sara33
    sara33

    7 years ago on Introduction

    How would I code this so I could see the output's power? I'm using analogRead and serial.print, but the analog read keeps saying 1023, even when I put my hand over the photoresister.

    0
    emmy99999
    emmy99999

    Reply 5 years ago

    I am having the same problem. Did you ever figure it out?

    0
    wenden_jason
    wenden_jason

    7 years ago

    I thought the proper name for these was an LDR (light dependant resistor)

    0
    zbot473
    zbot473

    7 years ago on Introduction

    I m an instructable noob

    How do you do that box in the intro page

    0
    gaganvajra
    gaganvajra

    7 years ago on Introduction

    hi im quite new to arduino and i have a question about voice recognition module v3.1

    .can anybody help me please....

    i need to know how to use the commands and what r the commands.......

    0
    codebender_cc
    codebender_cc

    Reply 7 years ago on Introduction

    Hi! Just stay online and make sure that you have pressed the "Follow" button.

    I will write a "How to" tutorial with this in the future.

    0
    tinker2015
    tinker2015

    7 years ago on Introduction

    hi im quite new to arduino and i have a question about photocells i was hoping you could help me with i need to stop/pause a sketch using a photocell when its detected a change in light how would i do this any help at all will be appreciated

    0
    codebender_cc
    codebender_cc

    Reply 7 years ago on Introduction

    Hi! That is quite simple. Just use the part of code with " if " conditions.