Hackster is hosting Hackster Holidays, Ep. 5: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Friday!Stream Hackster Holidays, Ep. 5 on Friday!
tropicalbean
Published

How to Use a Photoresistor!

Learn how to use a photoresistor in a matter of minutes!

IntermediateFull instructions provided627
How to Use a Photoresistor!

Things used in this project

Hardware components

Photo resistor
Photo resistor
×1
Arduino UNO
Arduino UNO
×1
LED (generic)
LED (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Resistor 10k ohm
Resistor 10k ohm
×1
Breadboard (generic)
Breadboard (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Circuit Diagram

Wire up your circuits like this, and you should be good to go.

Code

sketch_mar11a.ino

Arduino
This code basically checks if electricity is running through the photoresistor, and if there is, it should turn on the LED.
int ledPin = 2;

void setup() {
    Serial.begin(9600);
    pinMode(ledPin, OUTPUT);
}

void loop() {
    int value = analogRead(A0);

    Serial.println("Analog Value: ");
    Serial.println(value);
    
    if (value > 450) {
        digitalWrite(ledPin, LOW);
    } else {
        digitalWrite(ledPin, HIGH);
    }
    
    delay(250);
}

Credits

tropicalbean

tropicalbean

0 projects • 0 followers

Comments