Skip to main content

LIGHT-DEPENDENT RESISTOR (LDR)

    ANALOGUE INPUTS

In the world of electrical engineering, there are two type of input and output (I/O): analogue and digital. Digital I/O is fairly easy to understand; it's either on or off1 or 0.
When talking about voltages and the Raspberry Pi, any input that is approximately below 1.8V is considered off and anything above 1.8V is considered on. For output, 0V is off and 3.3V is on.
Analogue I/O is a little trickier. With an analogue input, we can have a range of voltages from 0V up to 3.3V, and the Raspberry Pi is unable to detect exactly what that voltage is.
How, then, can we use a Raspberry Pi to determine the value of an analogue input, if it can only tell when the voltage to a GPIO pin goes above 1.8V?

USING A CAPACITOR FOR ANALOGUE INPUTS

Capacitors are electrical components that store charge.
When current is fed into a capacitor, it will begin to store charge. The voltage across the capacitor will start off low, and increase as the charge builds up.
By putting a resistor in series with the capacitor, you can slow the speed at which it charges. With a high resistance, the capacitor will charge slowly, whereas a low resistance will let it charge quickly.
If you time how long it takes the capacitor's voltage to get over 1.8V (or be on), you can work out the resistance of the component in series with it.

    LIGHT-DEPENDENT RESISTORS

An LDR (sometimes called a photocell) is a special type of resistor.
When light hits the LDR, its resistance is very low, but when it's in the dark its resistance is very high.
By placing a capacitor in series with an LDR, the capacitor will charge at different speeds depending on whether it's light or dark.

    CREATING A LIGHT-SENSING CIRCUIT

  1. Place an LDR into your breadboard, as shown below:
  1. Now place a capacitor in series with the LDR. As the capacitor is a polar component, you must make sure the long leg is on the same track as the LDR leg.
  1. Finally, add jumper leads to connect the two components to your Raspberry Pi.

   CODING A LIGHT SENSOR

Luckily, most of the complicated code you would have to write to detect the light levels received by the LDR has been abstracted away by the gpiozero library. This library will handle the timing of the capacitor's charging and discharging for you.
Use the following code to set up the light sensor:
  from gpiozero import LightSensor, Buzzer

  ldr = LightSensor(4)  # alter if using a different pin
  while True:
      print(ldr.value)
Run this code, then cover the LDR with your hand and watch the value change. Try shining a strong light onto the LDR.

Comments

Popular posts from this blog

CLOUD WORKFLOW SCHEDULING WITH DEADLINE AND TIME SLOT ALGORITHM

CLOUD WORKFLOW SCHEDULING WITH DEADLINE AND TIME SLOT ALGORITHM Abstract Allocating service capacities in cloud computing is based on the assumption that they are unlimited and can be used at any time. However, available service capacities change with workload and cannot satisfy users’ requests at any time from the cloud provider’s perspective because cloud services can be shared by multiple tasks. Cloud service providers provide available time slots for new user’s requests based on available capacities. In this paper, we consider workflow scheduling with deadline and time slot availability in cloud computing. An iterated heuristic framework is presented for the problem under study which mainly consists of initial solution construction, improvement, and perturbation. Three initial solution construction strategies, two greedy- and fair-based improvement strategies and a perturbation strategy are proposed. Different strategies in the three phases result in several heuristics. ...

Android Tutorial

Android  is a complete set of software for mobile devices such as tablet computers, notebooks, smartphones, electronic book readers, set-top boxes etc. It contains a  linux-based Operating System ,  middleware  and  key mobile applications . It can be thought of as a mobile operating system. But it is not limited to mobile only. It is currently used in various devices such as mobiles, tablets, televisions etc. This tutorial is developed for beginners and experienced persons. Let's see the topics of android that we are going to learn. Basics of Android In this fundamental chapter, you will learn about android, its components, how to create first android application, internal of first android application etc. What is Android History and Version Software Stack Core Building Blocks Android Emulator Installing softwares Setup Eclipse Hello Android example Internal Details Dalvik VM AndroidManifest.xml R.java Hide Title Bar Activity and I...

Force Sensing Resistor FSR400

Force Sensing Resistor FSR400 This is a small  force sensitive resistor . It has a 0.16" (4 mm) diameter active sensing area. This FSR will vary its resistance depending on how much pressure is being applied to the sensing area. The harder the force, the lower the resistance. When no pressure is being applied to the FSR, its resistance will be larger than 1MΩ, with full pressure applied the resistance will be 2.5kΩ. Two pins extend from the bottom of the sensor with 0.1" pitch making it bread board friendly. These sensors are simple to set up and great for sensing pressure, but they aren't incredibly accurate. Use them to sense if it's being squeezed, but you may not want to use it as a scale. Dimensions: Overall length: 1.75" Overall width: 0.28" Sensing area: 0.3"