LDR with Arduino – Measure Light Intensity using Photoresistor
Using FDR FDR is a light dependent resistor for the circuit. We need to have a breadboard, so here I have a breadboard. Let me just place it like this. Okay, and you see I have to take this LDR sensor and I will put on a breadboard something like this. This is how Im going to place the light dependent resistor sensor. Okay, then I need a resistor which is a 1 kilo, ohm resistor that Im using for today, and I would going to connect the one end of the resistor to the one end of the LDR, okay. So, okay, so you then can see the circuit properly. The connection between this one leg of the LDR is connected to the one end of the resistor, because this breadboard is vertically short when it comes to the same column. Okay, this entire column is vertically short, so that is how we were going to place the LDR with resistor now to connect to the Arduino Uno. You see, we have this a zero pin on Arduino and then we have a ground and we have a 5 volt pin okay on Arduino now to connect the socket, we need to have a 3 male to male jumper wires. So I would first take the red color and I would connect to the free end of the LDR. Okay, look at this, because these are vertically short and this I will going to connect to the 5 volt on Arduino Uno.
Ok, so this is the 5 volt pin on Arduino Uno. Ok, then, I need to take the male pin of the sensor so where our one end of the LDR will going to connect to the resistor. So the same leg, where I will to connect this jumper wire and then I would connect to a zero pin because thats where the sensor data is coming. Okay, so basically I will take another jumper wire and I would going to connect the free end of the resistor. Okay, look at this. Nothing is connected, so I would okay because they are vertically short here: okay, they are vertically short and I would going to connect to the ground pin on Arduino Uno, okay. So basically, the connection is is kind of simple the the middle pin where our LDR and resistor connects that goes to a zero pin through the yellow wire. I can show you this yellow wire and then the free end of the LDR that goes to five volts through this red wire and that will going to connect to the 502. Nor do we know and the one end of the resistor, which is a free end through this green wire. It should connect to the ground thing. Okay, look at this its connected to the ground. You know now do we know, so this is how we were going to set up the circuit and lets not waste your time and write a program. Let me define a variable integer light and this will be integer light and in the setup function I would going to write serial dot begin because I want to use a serial monitor and it will be 9600 baud rate and in the loop function.
I would then say: light is equals to, I dont know read and because the LDR is connected to a zero pin on Arduino, I would say a zero and then see the o dot. Println, okay, thats the thats. The way we will going to print the light variable value, the slight value will be printed on serial monitor after a delay of one second, so every one second or maybe a hundred milliseconds, say, for example, we will going to print this light intensity data on our Serial monitor, okay, so let me just press control, a and control control, t it will align the code and then let me just make sure the board is Arduino and then do is the compote is selected and let me upload button and if everything goes well, you Can see lower left corner done uploading and let me open a serial monitor and you see now Im getting a data which is somewhere 200 or something like that. Okay. So when I take my hand on the top of I do this at the art sensor, you see the value will drop it down. If I remove my hand, okay, then it will again come back to some somewhere around 200 or something right. So if I want to modify this code in a way that if the temperature drops lets say a less than hundred okay, then I want to turn on the LED, which is connected to pin number thirteen okay and by the way on Arduino.
We have a built in LED which is connected to pin number thirteen right. So let me close this, you know serial monitor and in the setup function I will say Ben mode and I would say bin Mohd. Thirteen number pin that I want to set up into the output mode because LED is output, device, okay and then, after this line of code, like light intensity, I would just say if and then a block of code, okay and then lets say else: a block of Code, this is basically a syntax of evils, so let me make it a little bit more clear for you to understand whats happening here right. So if the light value, if light is less than hundred okay, then we want the LED to be done on so its a digital right and the thirteen number led to become in high, and if else, if the value of LDR is less than hundred, that means 80 or something then we want this led to be done it of right. So whenever I cover the FDR with my hand, then the brightness will be reduced, so it will be dark around the LDR sensor and the LED will just connect to pin number 13 will be light out. Okay, so let me upload the code and see if it works so lower left corner. You can see done uploading. So let me open a serial monitor to see the data so right now Im getting 214 or something like this.
So when I cover the LDR sensor, then you see the LED will light up this this this LED on Arduino Uno right, which is by default. It is connected to pin number 13 right. So when I remove my hand, the LED connected to pin number 13 will light up, so if I cover it turns on, if I remove my hand, it goes off right, so it basically detects the light intensity around the LDR, and this is how you are going To read the light intensity data from your LDR sensor, I hope you will find this video, educational and entertaining will see us into the next lesson.