Arduino Photoresistor setup

This assignment is an intro to working with a different kind of an input: a photoresistor. Instead of simply pushing a button, a sensor like this makes your program more dynamic.

Photoresistors measure the amount of light; “A photoresistor is a type of resistor whose resistance decreases when the intensity of light increases. In other words, the flow of electric current through the photoresistor increases when the intensity of light increases.”

So, the more light, the lower the resistance.

Photoresistors (also called light dependent) resistors are used to adjust brightness in displays or to cause a streetlight turn on or off when a chosen light level is detected.

This resistance can be measured as a number that the Arduino can read.  This number can be used in an if/else statement with greater than, less than symbols to control when something happens in a program.

Click here for a video description of this assignment.

Here’s what you have to do (including answering questions about the program and circuit):

  1. look at the sample circuit below and build it in
  2. copy and paste the sample code (below the image) into your Tinkercad program (delete whatever codes is there first).  No typing. Really. Just copy and paste.
  3. Run the program and be sure to click on Serial Monitor below your code.
  4. Click here to answer questions about your code and circuit.  You will also turn in your code URL here.

Copy this sample code and paste into your Photoresistor circuit -don’t forget to include those two curly braces at the on the last two lines:

int light=0;
int lightVal;
int red=13;

void setup()
pinMode (red, OUTPUT);

void loop()
lightVal = analogRead(light);
Serial.println (lightVal);
if (lightVal>=300)
digitalWrite (red, HIGH);

digitalWrite (red, LOW);