Presentation is loading. Please wait.

Presentation is loading. Please wait.

Light Dependent Resistor

Similar presentations


Presentation on theme: "Light Dependent Resistor"— Presentation transcript:

1 Light Dependent Resistor
1

2 Light Dependent Resistor
Circuit Layout component: light dependent resistor breadboard location: f30 and f27 component: 0.1uF capacitor breadboard location: g27 (long lead to positive voltage) and g24 (short lead to ground) Text Copyright (c) 2017 by Dr. E. Horvath 2

3 Light Dependent Resistor
Component: 0.1uF Electrolytic Capacitor positive (GPIO output or voltage source) identified by the longer wire negative (GND) identified by negative on the side of the capacitor male to female jumper wire breadboard location: j30 to 3.3V (pin 1) breadboard location: j27 to GPIO 4 (pin 7) breadboard location: j24 to GND (pin 6) Text Copyright (c) 2017 by Dr. E. Horvath 3

4 Light Dependent Resistor
from gpiozero import LightSensor from time import sleep ldr = LightSensor(4) try: while True: sleep(0.1) if ldr.value < 0.7: #adjust this to make the circuit more or less sensitive print("Light blocked") Text Copyright (c) 2017 by Dr. E. Horvath 4

5 Light Dependent Resistor
else: print("Light on") except KeyboardInterrupt: print("Exiting ...") finally: ldr.close() Text Copyright (c) 2017 by Dr. E. Horvath 5

6 Light Dependent Resistor
In order to understand the LightSensor code, go to cd /usr/share/pyshared/gpiozero This folder has a number of files for input and output. input_devices.py: Button, LightSensor, MotionSensor, AnalogInputDevice(requires ADC - Analog to Digital Converter Chip), DigitalInputDevice, SmoothedInputDevice, WaitableInputDevice output_devices.py: OutputDevice, DigitalOutputDevice, LED, Buzzer, PWMOutputDevice, PWMLED, RGBLED, Motor (requires H-bridge) Text Copyright (c) 2017 by Dr. E. Horvath 6

7 Twilio In the terminal: Menu → Accessories → Terminal
ping to check that you are online Install the twilio classes from the Python twilio package: sudo pip3 install twilio Go to and sign up for a trial account. Text Copyright (c) 2017 by Dr. E. Horvath 7

8 Twilio Credentials Text Copyright (c) 2017 by Dr. E. Horvath 8

9 Twilio Phone Number Text Copyright (c) 2017 by Dr. E. Horvath 9

10 Twilio Phone Number Text Copyright (c) 2017 by Dr. E. Horvath 10

11 Twilio Go to the command prompt and enter the following to install the required libraries for Twilio: sudo pip3 install twilio sudo pip3 install pytz Text Copyright (c) 2017 by Dr. E. Horvath 11

12 Twilio from twilio.rest import Client #put your credentials here
ACCOUNT_SID = "your account security identifier" AUTH_TOKEN = "your authentication token" #create an object to represent the connection client = Client(ACCOUNT_SID,AUTH_TOKEN) to_phone_number = “ " # your phone number from_phone_number = " " # twilio phone number #send the SMS (Short Messaging Service) text message client.messages.create(to = to_phone_number, from_ = from_phone_number, body = body_message) Text Copyright (c) 2017 by Dr. E. Horvath 12

13 Light Dependent Resistor and Buzzer
Image from 13

14 Buzzer Connections Buzzer breadboard location j1: + on buzzer
breadboard location j8: second connection on buzzer male to female jumper wire breadboard location f1: to GPIO 17 (pin 11) breadboard location f8: GND (pin 9) Text Copyright (c) 2017 by Dr. E. Horvath 14

15 Buzzer Connections from gpiozero import LightSensor,Buzzer
from time import sleep ldr = LightSensor(4) buzzer = Buzzer(17) try: while True: sleep(0.1) if ldr.value < 0.7: #adjust this to make the circuit more or less sensitive Text Copyright (c) 2017 by Dr. E. Horvath Text Copyright (c) 2017 by Dr. E. Horvath 15

16 Buzzer Connections print("Light blocked") buzzer.on() sleep(4) else:
print("Light on") buzzer.off() except KeyboardInterrupt: print("Exiting ...") finally: ldr.close() buzzer.close() Text Copyright (c) 2017 by Dr. E. Horvath 16

17 RC Circuits Background Information
Consider a circuit that is composed of a resistor and a capacitor in series with a power supply. In series means that one wire connects the power supply to the resistor, another wire connects the other lead of the resistor to the capacitor, and one more wire connects the other lead of the capacitor back to the power supply completing the circuit. To understand how this circuit behaves, let's review Ohm's Law and what resistors and capacitors are. Text Copyright (c) 2017 by Dr. E. Horvath

18 Voltage, Current, Resistance
V represents voltage measured in units of Volts. For example, V = 5V. I represents current measured in units of Amperes. The Ampere represents a very large amount of current, larger than any current encountered in most electronics labs which is why current is usually measured in units of milliAmperes. For example, I = 16mA. R represents resistance measured in units of Ohms. Typical resistance values used in these projects range from several hundred to several thousand. For example, R = 470 ohms. The unit of the ohm is often written as the capital Greek letter omega. Text Copyright (c) 2017 by Dr. E. Horvath

19 Ohm's Law According to Ohm's Law, the voltage across a component is equal to the current that flows through it times the resistance of the component. V = I R In this equation, current must be in units of amperes. Ohm's Law is not an actual physical law, but a relation that holds for components such as resistors. Do be aware that Ohm's Law is not valid for many components that are commonly used in the electronics lab; such devices are called non-ohmic. Text Copyright (c) 2017 by Dr. E. Horvath

20 Ohm's Law Examples Example 1: Suppose that a 1.5kohm resistor is connected to a 6V battery. What is the current that flows through a resistor? I = V/R = 6 V/(1500 ohms) = .004 A or 4 mA To express current in milliAmps, multiply your answer by 1000. Example 2: Suppose that the current that flows through a resistor is 12 mA and the resistance of the resistor is 2200 ohms. What is the voltage across the resistor? First convert current from milliAmps to Amps by dividing the current by 1000, so 12 mA = .012 A. Then, use Ohm's Law. V = IR = (.012 A)(470 ohms) = 5.64V. Text Copyright (c) 2017 by Dr. E. Horvath

21 Capacitance A capacitor stores charge, and capacitance is a measure of a component's capacity for storing charge. Capacitance is defined as charge divided by voltage. Expressed mathematically, this is C = Q/V In this equation, C represents capacitance, Q represents charge, and V represents voltage. Capacitance is measured in units of Farads, V is measured in units of Volts, and Q is measured in units of Coulombs. Most of the capacitors you'll be using will be on the order of 1 microFarad or 0.1 microFarad, which is 10 to the minus 6 Farads. Text Copyright (c) 2017 by Dr. E. Horvath

22 t = RC, measured in seconds
The RC Circuit Let's suppose a resistor and an uncharged capacitor are connected in series and are then hooked up to a power supply. The capacitor builds up charge exponentially until the voltage across the capacitor is equal to the voltage of the power supply. After this point, no more current flows. How fast this process takes place depends on the resistance of the resistor and the capacitance of the capacitor. The product of resistance and capacitance gives the RC time constant for the circuit. t = RC, measured in seconds The mathematics of this circuit lie beyond the scope of this class, but it suffices for our purposes to know how to calculate the time. Text Copyright (c) 2017 by Dr. E. Horvath

23 Light Dependent Resistors
In the vast majority of circuits where you use resistors, the resistance of the resistors remains constant, the resistance being indicated by bands of color. (See the PowerPoint Presentation on how to read the resistance of a resistor.) In some cases, however, the resistance of the resistor changes depending on a condition. The resistance of a light dependent resistor depends on the amount of light that falls on the sensor. Hence, if you can determine the resistance of the resistor you can gauge how light or dark it is. This is a very useful component to turn on lights automatically once the sun goes down or to set off an alarm if an intruder interrupts a beam of light. Text Copyright (c) 2017 by Dr. E. Horvath

24 Light Dependent Resistors (LDR)
In the vast majority of circuits where you use resistors, the resistance of the resistors remains constant, the resistance being indicated by bands of color. (See the PowerPoint Presentation on how to read the resistance of a resistor.) In some cases, however, the resistance of the resistor changes depending on a condition. The resistance of a light dependent resistor depends on the amount of light that falls on the sensor. Hence, if you can determine the resistance of the resistor you can gauge how light or dark it is. This is a very useful component to use in circuits that turn on lights automatically once the sun goes down or to set off an alarm if an intruder interrupts a beam of light. Text Copyright (c) 2017 by Dr. E. Horvath

25 Using an LDR with the Raspberry Pi
In order to use the light dependent resistor with the Raspberry Pi, connect the LDR in series with a capacitor and hook the free lead of the LDR up to a GPIO pin and the free lead of the capacitor to ground. As we discussed earlier, the time constant of an RC circuit equals the product of resistance and capacitance. As the light level changes, the resistance of the LDR changes, and hence, the time constant of the RC circuit changes. We, the programmers, don't need to know how to process the input from the RC circuit to determine the resistance. We'll use packages that take care of the processing, so the details are hidden from us. The method returns a value between 0 and 1, so you the programmer can code action to be taken if the value rises above a certain level or falls below a certain level. Text Copyright (c) 2017 by Dr. E. Horvath


Download ppt "Light Dependent Resistor"

Similar presentations


Ads by Google