Light Dependent Resistor Light Dependent Resistor Circuit Layout

  • Slides: 25
Download presentation
Light Dependent Resistor

Light Dependent Resistor

Light Dependent Resistor Circuit Layout component: light dependent resistor breadboard location: f 30 and

Light Dependent Resistor Circuit Layout component: light dependent resistor breadboard location: f 30 and f 27 component: 0. 1 u. F capacitor breadboard location: g 27 (long lead to positive voltage) and g 24 (short lead to ground) Text Copyright (c) 2017 by Dr. E. Horvath

Light Dependent Resistor Component: 0. 1 u. F Electrolytic Capacitor positive (GPIO output or

Light Dependent Resistor Component: 0. 1 u. F 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: j 30 to 3. 3 V (pin 1) breadboard location: j 27 to GPIO 4 (pin 7) breadboard location: j 24 to GND (pin 6) Text Copyright (c) 2017 by Dr. E. Horvath

Light Dependent Resistor from gpiozero import Light. Sensor from time import sleep ldr =

Light Dependent Resistor from gpiozero import Light. Sensor from time import sleep ldr = Light. Sensor(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

Light Dependent Resistor else: print("Light on") except Keyboard. Interrupt: print("Exiting. . . ") finally:

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

Light Dependent Resistor In order to understand the Light. Sensor code, go to cd

Light Dependent Resistor In order to understand the Light. Sensor code, go to cd /usr/share/pyshared/gpiozero This folder has a number of files for input and output. input_devices. py: Button, Light. Sensor, Motion. Sensor, Analog. Input. Device(requires ADC - Analog to Digital Converter Chip), Digital. Input. Device, Smoothed. Input. Device, Waitable. Input. Device output_devices. py: Output. Device, Digital. Output. Device, LED, Buzzer, PWMOutput. Device, PWMLED, RGBLED, Motor (requires H-bridge) Text Copyright (c) 2017 by Dr. E. Horvath

Twilio In the terminal: Menu → Accessories → Terminal ping www. pythonwithraspberrypi. com to

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

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

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

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

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

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

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

Twilio Go to the command prompt and enter the following to install the required

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

Twilio from twilio. rest import Client #put your credentials here ACCOUNT_SID = "your account

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 = “+15015551212 " # your phone number from_phone_number = "+1501724567" # 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

Light Dependent Resistor and Buzzer Image from http: //www. raspberrypi. org

Light Dependent Resistor and Buzzer Image from http: //www. raspberrypi. org

Buzzer Connections Buzzer breadboard location j 1: + on buzzer breadboard location j 8:

Buzzer Connections Buzzer breadboard location j 1: + on buzzer breadboard location j 8: second connection on buzzer male to female jumper wire breadboard location f 1: to GPIO 17 (pin 11) breadboard location f 8: GND (pin 9) Text Copyright (c) 2017 by Dr. E. Horvath

Buzzer Connections from gpiozero import Light. Sensor, Buzzer from time import sleep ldr =

Buzzer Connections from gpiozero import Light. Sensor, Buzzer from time import sleep ldr = Light. Sensor(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)Copyright 2017 by Dr. E. Horvath Text (c) 2017 by Dr. E. Horvath

Buzzer Connections print("Light blocked") buzzer. on() sleep(4) else: print("Light on") buzzer. off() except Keyboard.

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

RC Circuits Background Information Consider a circuit that is composed of a resistor and

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

Voltage, Current, Resistance V represents voltage measured in units of Volts. For example, V

Voltage, Current, Resistance V represents voltage measured in units of Volts. For example, V = 5 V. 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 milli. Amperes. For example, I = 16 m. A. 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

Ohm's Law According to Ohm's Law, the voltage across a component is equal to

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=IR 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

Ohm's Law Examples Example 1: Suppose that a 1. 5 kohm resistor is connected

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

Capacitance A capacitor stores charge, and capacitance is a measure of a component's capacity

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 micro. Farad or 0. 1 micro. Farad, which is 10 to the minus 6 Farads. Text Copyright (c) 2017 by Dr. E. Horvath

The RC Circuit Let's suppose a resistor and an uncharged capacitor are connected in

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

Light Dependent Resistors In the vast majority of circuits where you use resistors, the

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 Power. Point 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

Light Dependent Resistors (LDR) In the vast majority of circuits where you use resistors,

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 Power. Point 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

Using an LDR with the Raspberry Pi In order to use the light dependent

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