Tag Archives: LDR

Use a Comparator or Op-Amp to Simplify Light Dependent Resistor Output

If your project calls for light sensitivity, it’s hard to beat light dependent resistors (LDRs), also known as photoresistors. They’re available for a few cents each, and their resistance varies based on how much light they receive. In the dark, these devices produce resistances in the megohm range, and can fall to hundreds of ohms or even less when exposed to sufficient light. You first instinct when prototyping this type of device is likely to use an analog input on an Arduino or similar dev board to sense voltage levels. This works quite well in many situations, but you may also want to consider a comparator or operational amplifier (op-amp) to turn this analog input into a simple on/off signal. You could also use one of these components by itself to produce a usable output without the use of a microcontroller.

LDR Analog Input to Microcontroller

An LDR setup for Arduino Analog Input. Illustration: Jeremy S. Cook in Fritzing

First, let’s examine how a microcontroller would see an LDR input. Using the circuit illustrated in the figure above with an Arduino Uno, an LDR is attached to 5VDC, then routed to the analog input A0. Voltage at the intersection of A0, the resistor, and LDR is divided between the fixed resistor and LDR, which decreases its resistance as light is applied. Voltage at this analog input increases with the lowered resistance in proportion to the amount of light the LDR sees.

The Arduino board is thus able to sense the resulting voltage level and convert it to an analog value. A threshold can be setup to respond to different light levels as on or off, or the analog signal can be used for proportional control. Note that the resistor in this illustration is just a placeholder; it would need to be adjusted based on your LDR sensitivity. You can also use a trimming resistor to tweak output values as needed.

Comparator Digitizes Analog Signal

What if you need light input, but just want an on/off value? Analog inputs can handle this programmatically, but if you’re using an Arduino Uno you’re restricted to the 6 analog pins. There’s also the normally minor issue of additional program complexity. If you need more performance out of your setup, you could turn to a comparator, or operational amplifier (op-amp) set up to act as one, to convert this analog value into a simple on/off signal.

Caption: An LDR and LM358 Op-amp setup to detect light as a binary signal to an Arduino Uno Illustration: Jeremy S. Cook in Fritzing

For example, if you were going to use an LM358 op-amp and LDR to detect light, you could tie the V+ (pin 8) to the 5V supply of your Arduino, ground (pin 4) to the Arduino’s ground, and output A (pin 1) to a digital pin on your Arduino board. The inverting input (pin 2) would be hooked to a voltage divider between +5V and ground, and your LDR would be setup in a voltage divider on the non-inverting input (pin 3). Here the LDR would act as the resistor from +5V to the op-amp input, and the set resistor would run to ground.

This will give you an on/off input to your Arduino without mucking about with any extra programming. Note that because of the way this op-amp operates, the output will be less than 5V, but will be sufficient to trigger the needed input. Obviously this will add some wiring complexity—more work than a few lines of code—so it’s not ideal in all situations.

Comparator Sans Arduino

You’re probably wondering at this point why you wouldn’t simply get a dev board capable of more analog inputs if that’s what is needed. After all, hooking up additional wiring or adding more complication to your PCB isn’t trivial. Certainly there are some applications that call for this, but for really simple electronics, you may not need a microcontroller at all.

Caption: An LDR and LM358 Op-amp setup to turn an LED on when there isn’t sufficient light available.
Illustration: Jeremy S. Cook in Fritzing

One such simple application would be a light that you want to come on when the ambient light drops below a certain threshold. In this application, you’d want to put the resistors only voltage divider on the non-inverting input (pin 3), while the LDR voltage divider would be placed on the inverting input (pin 2). This would cause the voltage on pin 2 to be larger than pin 3 when the light is on, turning the output (pin 1) on when there isn’t enough light.

Of course LDRs are but one type of sensor, and there are many models of op-amps and comparators with different characteristics available depending on your needs. If you’re just starting out with sensors and electronics, using a dev board like an Arduino is a great choice. As you advance in your knowledge, you might also consider analog electronics for your builds. While not appropriate or necessary for every project, it’s a great tool to have available when purely digital processing doesn’t quite fit your application.

Jeremy S. Cook and Zach Wendt are engineers who enjoy sharing how electronic components can best impact applications. Jeremy writes for a variety of technical publications. Zach works for Arrow Electronics, a major supplier of Arduino products.

Mini Infra-Red Remote Robot Controller Shield For Arduino Nano

The Mini Infra-Red Remote Robot Controller shield for Arduino Nano is designed to drive mini mobile robots. Low voltage DC Motor controller interface allows Infrared wireless control of two DC motors, two PWM and 2 Direction signal outputs to drive two motors separately. TB6612 IC is the heart of the project. IC can handle constant current up to 1.2A, Supply 6-12V DC. One LDR connected to Analog pin A7 for application like light sensitive robot controller. Infrared receiver TSOP1738 used as IR receiver which is connected to Digital pin D2 of Arduino Nano. Nano D7-Direction Motor A, D4 Direction Motor B, D5 Motor A PWM signal, D6 Motor B PWM signal.

Mini Infra-Red Remote Robot Controller Shield For Arduino Nano – [Link]

Automatic monitor brightness controller

26189508935_1c9ac089ab_z-600x399

Dilshan Jayakody build a auto monitor brightness controller that adjusts your monitor brightness according to lighting conditions. He writes:

The sensor unit of this system is build around PIC18F2550 8-bit microcontroller. To measure the light level we use LDR with MCU’s inbuilt ADC. The control software of this unit is design to work with Microsoft Windows operating systems and it use Windows API’s DDC/CI related functions to control the monitors/display devices.

Automatic monitor brightness controller – [Link]

Light and Dark Sensitive Switch

Light_Switch_Photo

Light / Dark Sensitive Switch project is a simple project which operates a relay when the light falling on the LDR goes below or goes above a set point.

  • Input – 12 V @ 50 mA
  • Relay output – SPDT relay
  • 2-in-1 kit, either as light sensitive kit or dark sensitive switch
  • Onboard preset to set the level
  • Power-On LED indicator
  • Relay On LED indicator
  • Power Battery Terminal (PBT) for easy relay output connection
  • Four mounting holes of 3.2 mm each
  • PCB dimensions 50 mm x 54 mm

Light and Dark Sensitive Switch – [Link]

RELATED POSTS

Anti-Drowsiness Alarm

This reference design is an anti-drowsiness alarm, which aims to keep the drivers alert by disrupting one’s drowse. According to the study by U. S. National Highway Traffic Safety Administration (NHTSA), drowsy driving is the primary contributor of at least 100,000 auto crashes a year. Statistics shows that most crashes caused by drowsy driving occur from midnight to 8:00 am. During these times, a person often goes to sleep since it is dark outside.

The light dependent resistor (LDR) and the transistors (Q2 and Q3) serve as switch that prevents the oscillation of CD4060 binary counter. When the LDR is exposed to light (i.e., daytime), Q3 conducts while Q2 does not. This makes the RESET pin of CD4060 high to prevent it from oscillating. At night, Q3 does not conduct while Q2 conducts and pulls the RESET pin of CD4060 to ground. This starts the oscillations of CD4060 as indicated by the flashing of LED6. The internal oscillator of binary counter CD4060 oscillates at a frequency based on the values of R8, R9 and C3. The sensitivity of the LDR can be adjusted by the potentiometer R12. When the Q13 (pin 3) output of CD4060 becomes high, the RESET pin (pin 4) of the NE555 becomes high and it starts oscillating. Its pulse rate can be slightly adjusted using the potentiometer R6. The pulsed output of NE555 is then fed to the clock input of CD4017. The CD4017 is a decade counter with ten outputs, but only one of its outputs is high at a time and all the other outputs remain low. The output from NE555 serves as clock for CD4017. As a result, the Q1 output of CD4017 becomes high at the first positive edge from NE555 after 50 seconds. After 6 minutes, the Q6 output goes high and LED4 glows for one minute and the warning buzzer sounds. If the circuit is not reset using push-to-switch 1977737-1 after hearing the warning beep from PZ1, the counting of CD4017 continues and at the end of the 10th minute, the Q9 output becomes high to activate CD4093.

This circuit is designed to keep the drivers awake while driving at night. This is done by sounding intermittent beeps and by emitting flashing light. As long as Q9 output of CD4017 remains high, CD4093 oscillates and the piezobuzzer beeps and the white LEDs flash with a frequency determined by the values of R3 and C1.

Anti-Drowsiness Alarm – [Link]