Circuit 1C: Photoresistor: Parts Needed
Circuit 1C: Photoresistor: Parts Needed
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
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.
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
}