In this Arduino photoresistor Tutorial, we build a simple and easy light meter. For this, we use a photoresistor a Nokia 5110 LCD display an Arduino Mega. A photoresistor or light-dependent resistor (LDR) or photocell is a light-controlled variable resistor. The resistance of a photoresistor decreases with increasing incident light intensity; in other words, it exhibits photoconductivity. A photoresistor can be applied in light-sensitive detector circuits, and light- and dark-activated switching circuits.

Intro to the Arduino Photoresistor Tutorial

This is a very simple circuit with which we can measure the light intensity falling on a sensor. We are using a photoresistor this one here, an Arduino for controlling the whole circuit and a display a Nokia 5110 display. In the display, we can see the light intensity measurement in percent and a bar graph. A live bar graph. So, if I put my finger on the sensor you can see that the light intensity falls. It is a very simple circuit, don’t be fooled by the wires. We only need a photoresistor and a resistor. An Arduino and a display in order to display the results. So it is a very easy circuit and very useful in order to detect darkness or presence of light.

We can power down our equipment when is night or power it up when it is the day. So let’s see how easy it is to connect it to an Arduino. All we need is a photoresistor and a standard resistor. The photoresistors are light controlled variable resistors. These are also known as Light Dependent Resistors LDRs. In terms of operation, a photoresistor is usually very resistive, in MΩ, when placed in the dark however when it is illuminated its resistance decreases significantly.

——————–
WHERE TO BUY
——————–

1. Arduino Mega: https://educ8s.tv/part/ArduinoMega

2. Photoresistors: https://educ8s.tv/part/Photoresistors

3. Nokia 5110 display: https://educ8s.tv/part/NOKIA5110

4. Small Breadboard: https://educ8s.tv/part/SmallBreadboard

5. Wires: https://educ8s.tv/part/Wires

6. Resistors: https://educ8s.tv/part/Resistors

Full disclosure: All of the links above are affiliate links. I get a small percentage of each sale they generate. Thank you for your support!

[adsense]

We’re going to use this photoresistor and a standard resistor about 100KΩ. Any resistor from 10ΚΩ to 100 ΚΩ is fine. Then we take the breadboard and connect the photoresistor and the resistor here. First I put in the photoresistor and then the resistor. Ok, this is the 100 ΚΩ resistor. Now, let’s put a red wire here and connect it to the positive and a black wire from here and connect it to the negative. Now, we are ready the signal we are going to receive from the photoresistor is this pin here. We place a green wire and this goes to an analog pin on our Arduino. So, let’s connect the Arduino as well. Arduino Mega is here.

We take a red wire from 5V and we connect it to 5v of the breadboard We take ground from Arduino and we connect it to Ground of the breadboard and signal to an analog pin of our choice. I have chosen pin 13. This is a simple circuit which reads the value from a photoresistor. Now we have to connect the display in order to display the results. I’m not going to show you how to connect the Nokia 5110 display now because it takes some time but you can watch our previous video in which we describe the connection of the display with the Arduino in detail. OK, I now have connected the display as well. Let’s power it up and see if it is working. okay, we are ready, as you can see it’s very easy, the light meter is working fine.

——————–
LIBRARIES
——————–

? Nokia 5110 Library: http://www.rinkydinkelectronics.com/library.php?id=48

Now let’s see the software side on this project. So let’s look at the code of this project, first of all, we have to include the Nokia 5110 Graph.h library that we discussed in the previous video. Please check this video in order to see how to use this library in order to drive the 5110 display. So, first of all, we declare the LCD, the pins of the LCD, some variables here and the most important variable is the LDR pin 13, we declare in which pin the photoresistor is connected. We have connected it to pin 13 so this is it.

Then the Setup function we initialize the LCD screen and set the font.Next in the loop function which is iterated forever, with about 100ms delay, first of all, we clear the screen and update the screen and we read the light intensity. The light intensity is an int variable and it has a value around from 0 to 1,023. I have calibrated the sensor I saw that when the photoresistors are placed under direct sunlight the value that it reads is about 20. And when it is absolute darkness it is around 1010. So, what I have done, is that I don’t want these values that don’t mean anything I converted them to percent so when we have absolute darkness I map it to 0%. And when I have full sunlight the photoresistor will read a value of around 20 I map it to a value of 100% In this line we make the conversion. From analogRead to percent. Then I add the percent sign here and convert these string to a character array because the lcd.print command can only display character arrays. not strings, not integers not floats. I take the light intensity from here I convert it to percent, then I convert it to a character array, and I print it on the screen.

Then we have the printBar and fillBar functions. Those are the functions that are responsible for drawing the bar graph in the display. It is very simple, the first one draws an empty rectangle and then the fillBar it converts the percent value into pixels and draws four lines in order to fill the bar graph.

——————–
CODE
——————–

 

 

 

——————–

SUBSCRIBE ON YOUTUBE

——————–

Never miss a video: Subscribe to educ8s.tv