A Shopping List of Parts
1. LDR: cost less than ₹10
2. Resistor: 2.2KΩ , less than ₹1
3. Capacitor: 300nF, costs less than less than ₹5
4. Full size Breadboard: ₹ 80
5. Jumper wires: Female to female, male to female
This work is only costs less than ₹100 if you are an electronic hobbyist. Since an electronic hobbyist have atleast the components like LDR, breadboard, jumper wires etc. on his hand.
LDR
LDR is also known as Light Dependent Resistor or Photo Resistor or Photoconductive Cell or Photo Detector. The resistance of Photoconductive Cell decreases as the intensity of light increases. Photo Detectors are made up of semiconducting materials which possesses energy band equivalent to the order of that of photon. Cadmium Sulfide (CdS) is a potential candidate of photo detector whose Forbidden Energy Gap (FEG) ≅ energy of light. You can clearly see the CdS tracks on the top of LDR.Circuit
Circuit Diagram |
- Connect 3.3v Raspberry Pi pin(Pin 1) to positive rail of breadboard.
- Connect pin 6 of Raspberry Pi to negative rail of breadboard.
- Connect resistor, LDR and capacitor in series on terminal strip of breadboard as shown in figure.
- Connect broken (connectionless) end of resistor to positive rail of breadboard.
- Connect broken end of 330nF capacitor to negative rail of breadboard.
- The node joining to the LDR and 330nF capacitor to GPIO #4 using jumper wire.
The Fritzing is an no-profit open source software that allows you to draw the breadboard, schematic, and PCB of a circuit. It is a very straight forward application and it has a wide range of graphical symbols.`
if you have any doubt about about Raspberry Pi GPIO pins click here. In this blog chipprogrammer I used pin n for representing physical numbering of GPIO pins and GPIO #n to represent the BCM numbering of GPIO header where n is the number. However you should take care about numbering of GPIO. The above link will redirect to an interactive pin out of Raspberry Pi provided by Github.
Working of Circuit
You can also use 5V GPIO hader for the working of circuit. Here I am using 3.3V GPIO header for protecting the GPIO pins. The 2.2 KΩ resistor is also used for protecting the GPIO pins. Here we are connecting LDR for sensing the light. As I mensioned earlier the LDR is a variable resistor and when light increaes the resistance will decrease. If you are using a flash light to check the working of circuit you may able to see the RC time constant of the circuit approaches zero gradually. If you were used 5V GPIO header as your Vcc your GPIO pins may get damaged. Since your GPIO pins can only tolerate 3.3V, since it is working on 3.3V CMOS logic.
In the world of electronics or electrical engineering there is only two outputs: analog or digital. As we all know that the change in resistance with respect to change in intensity of light is a an analog value. But the Raspberry Pi has no inbuilt or on-chip analog-to-digital converter(ADC). We can overcome this problem using the 330nF capacitor. You may interested to know how that is possible? The analog I/O with Raspberry Pi is little trickier. When we talk about voltages and Raspberry Pi, the voltages less than 1.8V is considered off and voltages greater than 1.8V is considered as on. It is shown on the figure below.
The capacitor is just like your pocket and it wiill fill rapidly, if your time is good and it will become empty, if your fate and time is bad. It will charge faster if the variable resistance of LDR is lower due to the RC time constant is low. Also it will charge like a snail when the RC time constant is high at dark due to resistance of LDR become high. The time constant is given by:In the world of electronics or electrical engineering there is only two outputs: analog or digital. As we all know that the change in resistance with respect to change in intensity of light is a an analog value. But the Raspberry Pi has no inbuilt or on-chip analog-to-digital converter(ADC). We can overcome this problem using the 330nF capacitor. You may interested to know how that is possible? The analog I/O with Raspberry Pi is little trickier. When we talk about voltages and Raspberry Pi, the voltages less than 1.8V is considered off and voltages greater than 1.8V is considered as on. It is shown on the figure below.
Analog I/O of Raspberry Pi(courtesy Raspberry Pi learning) |
て=RC
For LDR, resistance at dark is approximately 1㏁ and hence for this resistance and 330nF capacitance て= 330 msec. For LDR, resistance at light is 10㏀ and hence て=33msec. You can calculate this resistance using online time constant calculator provided by digikey.
The time module of the Python makes the program trickier and will help us to measure this time constants.
There is two methods to find out the light levels received by LDR. The first method is some complicated and in this method the Python time and RCtime of RPi.GPIO module is directly used for this program. The first program is abstracted in the gpiozero library and hence it easy to handle second program.
Method 1
import RPi.GPIO as GPIO, time
# Tell the GPIO library to use
# Broadcom GPIO references
GPIO.setmode(GPIO.BCM)
# Define function to measure charge time
def RCtime(PiPin):
measurement = 0
# Discharge capacitor
GPIO.setup(PiPin, GPIO.OUT)
GPIO.output(PiPin, GPIO.LOW)
time.sleep(0.1)
GPIO.setup(PiPin, GPIO.IN)
# Count loops until voltage across
# capacitor reads high on GPIO
while (GPIO.input(PiPin) == GPIO.LOW):
measurement += 1
return measurement
# Main program loop
while True:
print (RCtime(4)) # Measure timing using GPIO4
This program is available on our github repository and it is named as ldr_spy.py. Cloning of these programs are discussed at the end of this session.
# Tell the GPIO library to use
# Broadcom GPIO references
GPIO.setmode(GPIO.BCM)
# Define function to measure charge time
def RCtime(PiPin):
measurement = 0
# Discharge capacitor
GPIO.setup(PiPin, GPIO.OUT)
GPIO.output(PiPin, GPIO.LOW)
time.sleep(0.1)
GPIO.setup(PiPin, GPIO.IN)
# Count loops until voltage across
# capacitor reads high on GPIO
while (GPIO.input(PiPin) == GPIO.LOW):
measurement += 1
return measurement
# Main program loop
while True:
print (RCtime(4)) # Measure timing using GPIO4
Method 2
from gpiozero import LightSensor, Buzzer
ldr = LightSensor(4) # alter if using a different pin
while True:
print(ldr.value)
ldr = LightSensor(4) # alter if using a different pin
while True:
print(ldr.value)
The program shown in method 2 is named as ldr_RC_time_check.py in our GitHub repository. You have to run these Python codes and observe the outputs using following commands:
The circuit diagram to turn on LED at night is shown above. There is no change in the above circuitry. In this circuitry we connected LED to the GPIO #17 through a 220Ω series resistor. You can use following commands to clone all programs from our GitHub repository:
$sudo python ldr_spy.py
$sudo Python ldr_RC_time_check.py
Note: Don't run codes simultaneously.$sudo Python ldr_RC_time_check.py
Immortal Brightness
You have to note down the values of these RC time constants during the dark and bright circumstances. These values will help you to turn on and off light by comparing real world situation. However I am not writing these programs to turn on and off light. You can change values in the RCtime((4)) in the if and else statements of the Python code corresponding to our GitHub repository named as newldr.py. Also you can change ldr.value in the if and eligible statements of our program (ldrorg.py) from GitHub repository to turning your LED on at night.Circuit for turn on LED at dark |
The circuit diagram to turn on LED at night is shown above. There is no change in the above circuitry. In this circuitry we connected LED to the GPIO #17 through a 220Ω series resistor. You can use following commands to clone all programs from our GitHub repository:
$cd ~
$ git clone git://github.com/chipprogrammers/ldr.git
Then type following commands to turn on LED at dark circumstances.$ git clone git://github.com/chipprogrammers/ldr.git
$cd ldr
$sudo python newldr.py
Or
$sudo python ldrorg.py
You can also check the working of program by masking LDR with your finger tip. Don't forgot to run ldr_spy.py which is explained in method 1 to note down the RCtime(4) value to change the value on newldr.py. Also you have to run ldr_RC_time_check.py to note down the values of ldr.value explained in method 2 for change these values program ldrorg.py.$sudo python newldr.py
Or
$sudo python ldrorg.py
Click here to view all four programs explained in this post.
ObiesiVfer_ni Colleen Kennedy Download crack
ReplyDeletestanontugood
VogigVul-fu Mai Miller Tenorshare 4uKey Password Manager 2.0.3.3
ReplyDeleteMorphVOX Pro
VMware Workstation
Air Explorer Pro 4.0.1
pibottwetre