Controlling Linear Actuators with a Light Dependent Resistor

Light Dependent Resistors

Light Dependent Resistors (LDR), or photoresistors, are variable resistors that has their resistance value change based on the amount of light that is detected by the photoelectric element. Generally, the more light that is shined on the photoresistor, the lower the resistance value the photoresistor has [1]. This can be quite useful as this changing resistance value can be read as an indication of the amount of light present and used by a microcontroller to perform a corresponding action. LDRs are often found as inexpensive and basic element, like below, but you can also find light sensors that are specifically designed to detect sunlight or UV light. Depending on what sensor you choose, you may need to consult its datasheet to see how to connect it with your microcontroller.

Photoresistor

Are Photoresistors Optical Sensors?

The short answer is yes, photoresistors are optical sensors. But not all optical sensors function like a photoresistors. Optical sensors are a family of sensors that utilizes light in various ways. Some optical sensor use light to detect the presence of an object or even used in feedback in linear actuators, while photoresistors give an indication of how much light is present. When looking for a light detecting sensor, it is important to know the distinction between photoresistors and other optical sensors.

 Optical Sensor in a Linear Actutaor

Potential Use Cases with Linear Actuators

LDRs can be used in conjunction with linear actuators for two basic purposes; the first is to have the actuator to react when there is too much light, and the other is to have the actuator to move to maximize the amount of light seen by the LDR. The first use case is useful for applications where you want to minimize the amount of light, like protecting light sensitive plants or automating a canopy over a patio or porch. The second use case is useful in applications like solar panels where you are trying to position them to maximize the amount of light seen by the panels.

Solar Panels

Utilizing an LDR to Control a Linear Actuator

Luckily, the feedback from the LDR won’t change based on either use case, so connecting and reading the feedback from the LDR can be implemented identically. To setup the photoresistor, you simply need to connect the positive side of the photoresistor to an appropriate power supply and the negative side to an analog pin of a microcontroller, like an Arduino, to read the output. You will also want to connect a resistor, which is connected to ground, to the output side of the photoresistor, like shown below, to protect the analog pins of the microcontroller.

 Photoresistor connected to an Arduino

 

You can drive the linear actuator with the microcontroller using either a pair of relays or by using a motor driver. To see how to do this, you can check out our blog on How to Control a Linear Actuator with an Arduino. The positioning of your LDR sensor will depend based on your use case; if you are trying to protect an area from light, you’ll want the LDR with whatever you are trying to protect, but if you want to maximize light exposure, you’ll need the sensor to move with the object you are exposing to the light. To read the feedback from the LDR in either case will be identical as you simply read the analog voltage from the output side of the sensor.

How you utilize this feedback to control your linear actuator will vary based on your application and use case. For the first use case where you are minimizing light exposure, you can either drive the linear actuator to a known position if a certain amount of light is detected or you could drive the linear actuator until the photoresistor detects a lower amount of light. The former is shown in the code sample below. While this is a basic implementation, you can do much more creative solutions using this solution as a starting point. For example, you could position a shade over a light sensitive plant only during peak daylight times and only when it is sunny. By using the photoresistor, you could determine whether it was sunny enough to need to move the actuator and position the shade.

In the second use case where you are maximizing light exposure, you’ll need to determine what position maximizes the light exposed to the LDR. To do this effectively, you’ll need to make use of a feedback linear actuator to track the position of the actuator. You can find guides on how to use the different feedback options for linear actuators on our tutorial page. The code sample below shows you how you could accomplish this using a potentiometer feedback linear actuator. You simply track the lowest resistance value from the LDR, which is the highest voltage value, and the corresponding position of the actuator. You’ll first want to extend the actuator to the max length and then retract it to measure the LDR output over the entire length of the actuator. Once the actuator has moved through its entire range, you simply move to the position that had the highest corresponding output from the LDR. To practically implement this, you’ll probably want to run the below code on a timer to find a new position periodically throughout the day.

There are lots of creative ways you can make use of photoresistors with linear actuators and we’d love to see what you’ve done. With Firgelli Automation’s wide selection of linear actuators and accessories, you can make your next light controlled project a breeze.

References:

  1. Electronics Notes. Light Dependent Resistor LDR: Photoresistor. Retrieved from: https://www.electronics-notes.com/articles/electronic_components/resistors/light-dependent-resistor-ldr.php

Share this article

Featured Collections

Need Help Finding the Right Actuator?

We precision engineer and manufacture our products so you get direct manufacturers pricing. We offer same day shipping and knowledgeable customer support.

Give us a call or email us and we'll be happy to help you find the best actuator for your project.