0% found this document useful (0 votes)
27 views7 pages

Lesson 7 Photoresistor

Uploaded by

cejek20
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views7 pages

Lesson 7 Photoresistor

Uploaded by

cejek20
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Lesson 7 Photoresistor

Introduction

In this lesson, you will learn how to measure light intensity using an Analog
Input.

Hardware Required

 1 * RexQualis UNO R3

 1 * Breadboard

 8 * LED

 8 * 220ohm Resistors

 1 * 74HC595 IC

 1 * 1kohm resistor

 1 * Photoresistor

 14 * M-M Jumper Wires

Principle

Photoresistor

A photoresistor 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 the light-dependent resistor (LDR).
Code interpretation

int lightPin = 0; // Pin to pin AO on the Arduino

int latchPin = 11;//Pin 12 (RCLK) of the shift register to pin 11 on


the Arduino – this will be referred to as the “latch pin”

int clockPin = 12;//Pin 11 (SRCLK) of the shift register to pin 12


on the Arduino – this will be referred to as the“clock pin”

int dataPin = 9;//Pin 14 (SER) of the shift register to pin 9 on the


Arduino – this will be referred to as the “data pin”

int leds = 0;

void setup()

//The 'setup' function just sets the three pins we are using
to be digital outputs.

pinMode(latchPin, OUTPUT);

pinMode(dataPin, OUTPUT);

pinMode(clockPin, OUTPUT);
}

void updateShiftRegister()

digitalWrite(latchPin, LOW);

shiftOut(dataPin, clockPin, LSBFIRST, leds);

digitalWrite(latchPin, HIGH);

//divide the raw reading by 57 rather than 114. In other


words, we divideit by half as much as we did with the pot to
split it into nine zones, from no LEDs lit to all eight lit.

//This extra factor is to account for the fixed 1 kΩ resistor.


This means that when the photocell has a resistance of 1 kΩ
(the same as the fixed resistor), the raw reading will be 1023
/ 2 = 511. This will equate to all the LEDs being lit and then a
bit (numLEDSLit) will be 8.

void loop()

int reading = analogRead(lightPin);

int numLEDSLit = reading / 57; //1023 / 9 / 2

if (numLEDSLit > 8) numLEDSLit = 8;

leds = 0; // no LEDs lit to start

for (int i = 0; i < numLEDSLit; i++)

{
leds = leds + (1 << i); // sets the i'th bit

updateShiftRegister();

Experimental Procedures

Step 1:Build the circuit

Schematic Diagram
Step 2:Open the code:Photoresistor_Code
Step 3: Attach Arduino UNO R3 board to your computer via
USB cable and check that the 'Board Type' and 'Serial Port' are
set correctly.

Step 4: Upload the code to the RexQualis UNO R3 board.

Then, When you place the light source close to the


photoresistor, LED is on in turn.
If it isn’t working, make sure you have assembled the circuit
correctly, verified and uploaded the code to your board. For
how to upload the code and install the library, check Lesson 0
Preface.

You might also like