How to Control Your Linear Actuator Using Light-Triggered Sensors

Introduction: How to Control Your Linear Actuator Using Light-Triggered Sensors

About: Progressive Automations is your primary source for electric linear actuators, motion control systems and automation accessories. For over a decade, we have supplied various industries with top quality automati…

For quite some time, makers and DIYers have been using our actuators to automate their chicken coop doors. This is often done using our digital programmable timer switch or PA-35 Wi-Fi Control Box. Lately, many of you have been requesting a simple automated way to control your linear actuator by using a light sensor. This is great for projects like the chicken coop door, whereby it opens when it gets light out, and closes when it gets dark. These requests were the inspiration for this Instructable!

This is a relatively simple project. However, if you are among the majority of people and find electronics and programming a bit intimidating, this is a great place to get started!

Supplies:

  • 1 x PA-07-2-5 linear actuator
  • 1 x PS-20-12 power supply
  • 1 x Arduino Uno microcontroller
  • 1 x 2-channel relay module
  • 1 x light-dependent resistor (also known as a photoresistor or LDR)
  • 1 x 10K resistor (resistor value can vary)

Step 1: Choose the Right Actuator

In this example, we are using a PA-07-2-5. If you are using this system for a chicken coop door, this will not be the appropriate actuator due to its short stroke length and low force rating. However, this may be a good option if you are building something else, like an automated door lock. For help finding the right actuator for your application, you can refer to one of our many blog posts here. To specifically calculate the force required use the steps described in the link here.

Step 2: Wiring

The wiring for this project is as follows:

LDR to Arduino

  • LDR lead 1 – Ground
  • LDR lead 2 – 5V (via 10k resistor)
  • LDR lead 2 – Analog Pin 0

Relay Module to Arduino

  • VCC – 5V
  • GND – GND
  • IN1 – Pin 2
  • IN2 – Pin 3

Relay Module to Power Supply and Actuator

  • +12V to NC1 (normally closed terminal on relay one)
  • -12V to NO1 (normally open terminal on relay one)
  • NC1 to NC2
  • NO1 to NO2
  • COMMON1 to Actuator Lead 1
  • COMMON2 to Actuator Lead 2

This wiring is using a 2-channel relay module. This is a very simple setup that is easy to code, but it does have its limitations. If you want to add features such as speed control or force feedback, you may want to consider using the MegaMoto motor driver shield instead. More info on that here.

Step 3: The Code

The functionality of the provided code below is meant to be as simple as possible. When there is light, the actuator will retract. When it is dark, the actuator will extend (or vice versa depending on the wiring). To prevent the actuator from being triggered unintentionally, (if someone walks by and blocks the light, or if a flash of lighting is picked up by the sensor) the change from dark to light (or light to dark) must last at least thirty seconds. This delay can easily be changed by changing the value of “const int triggerDelay”.

The amount of light present is determined by reading the voltage going to analog pin 0. The more light there is, the less resistance our light-dependent resistor will have. Since we are using a pullup resistor, this will mean the voltage will go down as the environment gets brighter. The Arduino reads this as a value between 0 and 1028. If you want to change the value at which the state of the actuator will change, simply change the value of “const int threshold” (set to 650 by default).

We hope you found this tutorial useful. If you have any questions or want to share your project with us, please feel free to contact us by phone or email!



/*The hardware required for this project is an
Arduino, one light dependant resistor (LDR), a 10K resistor and a 2-channel 5V relay module.

Its purpose is to control the extension and retraction of an actuator based on the amount of light that is present.

Written by Progressive Automations 12/02/2020

*/

#define relay1 2 //relay used to extend actuator

#define relay2 3 //relay used to retract actuator

int ldr; //analog reading from light dependent resistor

int countOpen = 0;//counts how long sensor is recieving light

int countClose = 0;//counts how long the sensor is not recieving light

const int triggerDelay = 3000;//number of seconds x 100 to wait after lighting changes before triggering actuator

const int threshold = 650;//

void setup() {

Serial.begin(9600);

pinMode(relay1,OUTPUT);

pinMode(relay2,OUTPUT);

digitalWrite(relay1,HIGH);

digitalWrite(relay2,HIGH);

}

void loop() {

checkSensor();

}

void checkSensor()

{

ldr = analogRead(0);

Serial.println(ldr);

if(ldr > threshold)//if reading is greater than threshold, start counting

{

countOpen++;//count how long the sensor is not recieving light

delay(10);

}

else

{

countOpen = 0;//reset count to zero if statement is not true

}

if(countOpen > triggerDelay)// wait x seconds before triggering actuator

{

extend();//extend actuator

}

if(ldr < threshold)//if reading is less than threshold, start counting

{

countClose++;//count how long sensor is recieving light

delay(10);

}

else

{

countClose = 0;

}

if(countClose > triggerDelay)// wait x seconds before triggering actuator

{

retract();

}

}

void extend()

{

digitalWrite(relay1,LOW);

digitalWrite(relay2,HIGH);

}

void retract()

{

digitalWrite(relay2,LOW);

digitalWrite(relay1,HIGH);

}

Be the First to Share

    Recommendations

    • Pi Day Speed Challenge

      Pi Day Speed Challenge
    • Trash to Treasure Contest

      Trash to Treasure Contest
    • Microcontroller Contest

      Microcontroller Contest

    Comments