Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
tech guy
Published

Photo Resistor

This is a tutorial on how to use a photo resistor.

IntermediateProtip15 minutes1,451
Photo Resistor

Things used in this project

Hardware components

Photo resistor
Photo resistor
×1
Arduino UNO
Arduino UNO
×1
Resistor 221 ohm
Resistor 221 ohm
×1
Breadboard (generic)
Breadboard (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×3
USB-A to B Cable
USB-A to B Cable
×1

Story

Read more

Schematics

photo_resistor_oMFqfO11iU.fzz

Code

photo resistor 1000

Arduino
const int pResistor = A0; // Photoresistor at Arduino analog pin A0
const int ledPin=13;       // Led pin at Arduino pin 9

//Variables
int value; // Store value from photoresistor (0-1023)

void setup(){//run setup
 pinMode(ledPin, OUTPUT);  // Set lepPin - 9 pin as an output
 pinMode(pResistor, INPUT);// Set pResistor - A0 pin as an input (optional)
}

void loop(){ //begin loop
  value = analogRead(pResistor);
  
  //You can change value "25"
  if (value > 25){
    digitalWrite(ledPin, HIGH);  //Turn led on
  }
  else{
    digitalWrite(ledPin, LOW); //Turn led off
  }

  delay(500); //Small delay
}

Credits

tech guy
7 projects • 9 followers
Contact

Comments

Please log in or sign up to comment.