How to use a Photo-Resister(LDR)
Photocell
Introduction
|
A photoresistor or photocell is a light-controlled variable resistor. The resistance of a photoresistor decreases with increasing incident light intensity. A photoresistor can be applied in light-sensitive detector circuits, and light- and dark-activated switching circuits. It's also called light-dependent resistor (LDR).
In this tutorial you will learn how to use a photoresistor with and without arduino uno. How to use a photoresistor
Let's see how a photoresistor react in light. Build the circuit above and notice how led brightness change.
The resistance value becomes smaller when there is much light in the room. So in the dark the led remains off because the resistance has become very big. The Arduino will help us to reverse this situation, let's see how in next step. What you will need - Hardware
For this tutorial you will need:
The Circuit
The connections are pretty easy, see the image above with breadboard circuit schematic.
The Code ::
How it works:
***********************************************************
/* Use a photoresistor (or photocell) to turn on an LED in the dark *///Constants const int pResistor = A0; // Photoresistor at Arduino analog pin A0 const int ledPin=9; // Led pin at Arduino pin 9 //Variables int value; // Store value from photoresistor (0-1023) void setup(){ pinMode(ledPin, OUTPUT); // Set lepPin - 9 pin as an output pinMode(pResistor, INPUT);// Set pResistor - A0 pin as an input (optional) } void loop(){ value = analogRead(pResistor); //You can change value "25" if (value > 25){ digitalWrite(ledPin, LOW); //Turn led off } else{ digitalWrite(ledPin, HIGH); //Turn led on } delay(500); //Small delay }
***********************************************************
Well done!
You have successfully completed one more Arduino "How to" tutorial and you learned how to use a photoresistor!
I hope you liked this, let me know in the comments. |
Comments
Post a Comment