Raspberry pi

Raspberry pi 3 LDR Sensor, circuit and python programming 2020

raspberry pi 3 ldr


raspberry pi 3 LDR- We will learn how to use an LDR “light-dependent resistor to control a light-emitting diode”  in this project. Depending on the light intensity in the house, the led will be on and off.

The Amazon Purchase links are given below:

Raspberry Pi 3 full package: Best offer: https://amzn.to/2F4QqqE
Power bank: https://amzn.to/2Q4oDga
LDR: https://amzn.to/2MG2t1E

Arduino Uno: https://amzn.to/39aq6ZT
Mega 2560: https://amzn.to/2SszMsI
lm7805 Voltage Regulator: https://amzn.to/2ERYoTJ
330-ohm resistors pack: https://amzn.to/2Qj1Igg
female DC power jack socket: https://amzn.to/377Pg9M
470uf capacitors: https://amzn.to/2MrN3xR
5×7 cm Vero board: https://amzn.to/37b7KWO
female headers: https://amzn.to/350w6RE
connection wires: https://amzn.to/2MvOJXd
Super Starter kit for Beginners: https://amzn.to/398dliF
Jumper Wires: https://amzn.to/2SrnBwo
Bread Board: https://amzn.to/2MxV5FM
12v Adaptor: https://amzn.to/2MuOlZk
PCB plate: https://amzn.to/2MuwNMB
Variable Supply: https://amzn.to/39d0KdP
Digital Multimeter: https://amzn.to/34WbVoa
Vero Board / stripboard: https://amzn.to/39nL9Zg
Soldering iron kit: “best” You guys should definitely purchase this: https://amzn.to/2PVwexF
Solder wire: https://amzn.to/2QlOvTS
Wire Stripper: https://amzn.to/353tYJa
wirecutter: https://amzn.to/2tV2lFj
PCB small portable drill machine: https://amzn.to/2MvQqnx


Please Note: these are affiliate links. I may make a commission if you buy the components through these links. I would appreciate your support in this way!


raspberry pi 3 ldr Circuit Diagram:

raspberry pi 3 ldr

In my previous article, this is the circuit I described. We regulated this led with a push button in the previous tutorial. I changed a circuit this time and added an LDR. So this time we’re going to use an LDR to control this led. The LDR is connected to 3.3v and the LDR’s other arm is connected to the 10uf condenser’s positive side. While the condenser’s other leg is attached to the gnd … now take wire from the middle and attach it to the raspberry pi pin number 7. Our circuit diagram is done. So pin number 11 is connected to the LED and the RC circuit is connected to pin number 7.

raspberry pi 3 ldr

As you can see, all the components are interfaced according to the circuit diagram, as you can see that 330-ohm resistor links the LED in series. The  cathode  side of  the led is  associated  with pin  number which is the ground pin of the raspberry pi…While the other end of the resistor is attached to the pin number 11 … The LDR is connected in series to the 10uf capacitor on the right side…The  first  leg of  the  LDR is  connected  to the  pin  number which is the 3.3v pin  …. the  other  leg  of  the  LDR  is  connected  to  the  positive  leg  of the condenser … and the middle  wire  is  connected  to  the  pin  number of the  raspberry pi ..  and the ground leg of the condenser is connected to the ground 

raspberry pi 3 ldr

Now let’s raspberry pi power up. We’re prepared for programming now… as you can see that there’s no keyboard and there’s no link between the mouse and the laptop or LCD. Because we’re going to use the ssh network to write and execute programs, as I described in my previous tutorials.

raspberry pi 3 ldr Programming:

raspberry pi 3 ldr Program Explanation:

Open the putty software.

Place your raspberry pi’s IP address so press open. 

 Enter pi as your name for your account. 

And when you sign in, raspberry as your username and click enter.

Using clear command to clear the window … using ls to list all files and folders. Type cd youtube to open the youtube directory ….Now use ls to list all the filesLED1.py is the last tutorial program made…Let’s now make another file with the LDR name and the.py extensionOnly type sudo nano ldr.py and press in.

The editor is opened as you can see..First we import  rpi.gpio ..  time ..  and then use the set mode to specify the numbering scheme to be used.I’ve already explained these three instructions in my 2nd  tutorial,  so recommend that you watch the linked tutorial in the description then define variable delay time and set it to.1 …. later, if you want to change the delay, you can simply change this value over here.Use this variable to store the LDR valueLet’s set pins now … LDR 7ldr is linked to pin number 7…led=11….LED is connected to pin number 11….Now let’s use gpio.setup to configure the led as output, as you know led is an output tool. Now let’s use gpio.output to turn off the led...We keep the led off by default … let’s now make user-defined function with the name rc_time.…rc_time  is function specified by the user and takes one argument as the LDR input connected to pin number 7…Let’s make another name count variable and set it to … first set pin number which is ldr as output.…Now use the gpio.output method to turn off the pin which is LDRNow use the delay time.sleep function… now switch pin number which is ldr back to output…

Now let’s make an infinite while looping …. by simply typing while true … now let’s print the LDR value for this we use the print function … only store the LDR value in variable value … value rc time function and use the print function to print this value…Now let’s use if conditions to toggle on and turn off the led value  10000 after checking this project in my room ..And then use the exception and eventually I explained the instructions in my previous tutorials…So now our software is ready… press o on the keyboard to save… and then press x to exit the editor… now use the ls command to list all the files, as you can see the development of the ldr.py folder… just type python ldr.py and press enter…

Watch Video Tutorial

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button