0% found this document useful (0 votes)
57 views

Circuit 1C: Photoresistor: Parts Needed

This document describes a circuit using a photoresistor that can be used to make a simple night light. It explains that a photoresistor's resistance changes based on the amount of light it receives, decreasing as more light shines on it. It also discusses how an analog to digital converter is used to allow the microcontroller to read the analog signal from the photoresistor, and how a voltage divider circuit converts the changing resistance to a changing voltage that can be read. The code samples the photoresistor, compares it to a threshold, and turns an LED on or off accordingly to function as a night light.

Uploaded by

Darwin Vargas
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)
57 views

Circuit 1C: Photoresistor: Parts Needed

This document describes a circuit using a photoresistor that can be used to make a simple night light. It explains that a photoresistor's resistance changes based on the amount of light it receives, decreasing as more light shines on it. It also discusses how an analog to digital converter is used to allow the microcontroller to read the analog signal from the photoresistor, and how a voltage divider circuit converts the changing resistance to a changing voltage that can be read. The code samples the photoresistor, compares it to a threshold, and turns an LED on or off accordingly to function as a night light.

Uploaded by

Darwin Vargas
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/ 3

Circuit 1C: Photoresistor

In circuit 1B, you got to use a potentiometer, which varies resistance based on the twisting of a knob.
In this circuit, you’ll be using a photoresistor, which changes resistance based on how much light the
Page | 1
sensor receives. Using this sensor you can make a simple night-light that turns on when the room
gets dark and turns off when it is bright.

Parts Needed
Grab the following quantities of each part listed to build this circuit:

NEW COMPONENTS

PHOTORESISTORS are lightsensitive, variable resistors. As more light shines on the


sensor’s head, the resistance between its two terminals decreases. They’re an easy-to-
use component in projects that require ambientlight sensing.

NEW CONCEPTS
ANALOG TO DIGITAL CONVERSION:
In order to have the microcontroller sense analog signals, we must first pass them
through an Analog to Digital Converter (or ADC). The six analog inputs (A0–A5)
covered in the last circuit all use an ADC. These pins sample the analog signal and
create a digital signal for the microcontroller to interpret. The resolution of this signal is
based on the resolution of the ADC. In the case of the microncontroller, that resolution
is 10-
bit. With a 10-bit ADC, we get 2 ^ 10 = 1024 possible values, which is why the analog
signal can vary between 0 and 1023.

VOLTAGE DIVIDERS CONTINUED:


Since the MICROCONTROLLER can’t directly interpret resistance (rather, it reads voltage), we need
to use a voltage divider to use our photoresistor, a part that doesn’t output voltage. The resistance of
the photoresistor changes as it gets darker or lighter. That changes or “divides” the voltage going
through the divider circuit. That divided voltage is then read in on the analog to digital converter of
the analog input.

The voltage divider equation:


assumes that you know three values of the above circuit: the input voltage (Vin),
and both resistor values (R1 and R2). If R1 is a constant value (the
resistor) and R2 fluctuates (the photoresistor), the amount of voltage
measured on the Vout pin will also fluctuate.
Hookup Guide

Page | 2
Source Code:

int photoresistor = 0; //this variable will hold a value based on the brightness of the ambient light
int threshold = 750; //if the photoresistor reading is below this value the light will turn on
void setup() Page | 3
{
Serial.begin(9600); //start a serial connection with the computer
pinMode(13, OUTPUT); //set pin 13 as an output that can be set to HIGH or LOW
}

void loop()
{
//read the brightness of the ambient light
photoresistor = analogRead(A0);
//set photoresistor to a number between 0 and 1023 based on how bright the ambient light is
Serial.println(photoresistor); //print the value of photoresistor in the serial monitor on the computer
//if the photoresistor value is below the threshold turn the light on, otherwise turn it off
if (photoresistor < threshold) {
digitalWrite(13, HIGH); // Turn on the LED
} else {
digitalWrite(13, LOW); // Turn off the LED
}
delay(100); //short delay to make the printout easier to read
}

You might also like