Linear Actuated Window Shutters

Hi all,

This is just a post for posterity.
I learned a lot from reading other forum posts so wanted to post my final product as it may help somebody else.

This project uses linear actuators (tubes that change length) to open and close refrigerator panels covering windows. There are three sets of actuators which are controlled from a wireless remote control. I have incorporated a photo-resistor to open the windows when the sun reaches a high enough intensity and close them when it drops. There is also a timer function in there which is disables as the photo-resistor is a more sophisticated solution.

If this project looks like yours please feel free to ask questions.
If anyone has any feedback on my amateurish-ness please let me know also :slight_smile:

#include <Time.h>
#include <TimeLib.h>
#include <TimeAlarms.h>

#define to 4 // transom open - 2.4m transom window in family room’s (looking from outside)
#define tc 5 // transom closed
#define bo 2 // large window open (window “bank”)
#define bc 3 // large window closed (window “bank”)
#define lo 6 // library open
#define lc 7 // library closed

#define boin 10 // large window open (window “bank”)
#define bcin 11 // large window closed (window “bank”)
#define toin 12 // transom open
#define tcin 13 // transom closed
#define cancel 9 // to stop timer BUTTON 11 on remote
#define power 14 // “A0” on board
#define powerin 15 // “A1” on board

unsigned long curr = 0;
unsigned long prev = 0;
unsigned long tim = 150000; //150000 = 150 seconds
unsigned long x = 0;
int but = LOW;

int light[20];
int lindex = 0;
float lsum = 0;
float lavg = 0;
int i = 0;

int analogPin = 5;
int val = 0;
int aval = 300;

void setup()
{

setTime(14, 15, 00, 1, 1, 16); // set time to 13:30:00pm Jan 1 2016
//Alarm.alarmRepeat(21, 00, 0, PowerOff);
//Alarm.alarmRepeat(9, 00, 00, WindowsOpen);
//Alarm.alarmRepeat(17, 00, 00, WindowsClose); // 5:00pm every day

Alarm.timerRepeat(180, LightRead); //run every 3 minutes

pinMode(to, OUTPUT);
pinMode(tc, OUTPUT);
pinMode(bo, OUTPUT);
pinMode(bc, OUTPUT);
pinMode(lo, OUTPUT);
pinMode(lc, OUTPUT);
pinMode(power, OUTPUT);

pinMode(boin, INPUT);
pinMode(bcin, INPUT);
pinMode(toin, INPUT);
pinMode(tcin, INPUT);
pinMode(powerin, INPUT);
pinMode(cancel, INPUT);

digitalWrite(to, LOW);
digitalWrite(tc, LOW);
digitalWrite(bo, LOW);
digitalWrite(bc, LOW);
digitalWrite(lo, LOW);
digitalWrite(lc, LOW);

Serial.begin(9600);

}

void loop()
{

if (digitalRead(boin) == HIGH) {
BankOpen();
}
else if (digitalRead(bcin) == HIGH) {
BankClosed();
}
else if (digitalRead(toin) == HIGH) {
TransomOpen();
}
else if (digitalRead(tcin) == HIGH) {
TransomClosed(); //NOTE - dont reference input pins if they are not hooked up, seems to screw it up
}
else if (digitalRead(powerin) == HIGH) {
PowerCut();
}

Alarm.delay(10);

val = analogRead(analogPin); // read the input pin
Serial.println(val); // debug value
}

void WindowsOpen()
{

prev = millis();

while (curr < tim && but == 0)
{
digitalWrite(bo, HIGH);
digitalWrite(lo, HIGH);
but = digitalRead(cancel);
curr = millis() - prev;
}
digitalWrite(bo, LOW);
digitalWrite(lo, LOW);
but = 0;
curr = 0;

prev = millis();

while (curr < tim && but == 0)
{
digitalWrite(to, HIGH);
but = digitalRead(cancel);
curr = millis() - prev;
}
digitalWrite(to, LOW);
but = 0;
curr = 0;
}

void WindowsClose()
{
prev = millis();

while (curr < tim && but == 0) {
digitalWrite(bc, HIGH);
digitalWrite(tc, HIGH);
digitalWrite(lc, HIGH);
but = digitalRead(cancel);
curr = millis() - prev;
}
digitalWrite(bc, LOW);
digitalWrite(tc, LOW);
digitalWrite(lc, LOW);
but = 0;
curr = 0;
}

void BankOpen()
{
prev = millis();

while (curr < tim && but == 0)
{
digitalWrite(bo, HIGH);
but = digitalRead(cancel);
curr = millis() - prev;
}
digitalWrite(bo, LOW);
but = 0;
curr = 0;
}

void BankClosed()
{
prev = millis();

while (curr < tim && but == 0)
{
digitalWrite(bc, HIGH);
but = digitalRead(cancel);
curr = millis() - prev;
}
digitalWrite(bc, LOW);
but = 0;
curr = 0;
}

void TransomOpen()
{
prev = millis();

while (curr < tim && but == 0)
{
digitalWrite(to, HIGH);
but = digitalRead(cancel);
curr = millis() - prev;
}
digitalWrite(to, LOW);
but = 0;
curr = 0;
}

void TransomClosed()
{
prev = millis();

while (curr < tim && but == 0)
{
digitalWrite(tc, HIGH);
but = digitalRead(cancel);
curr = millis() - prev;
}
digitalWrite(tc, LOW);
but = 0;
curr = 0;
}

void PowerOff()
{
prev = millis();

while (curr < 32400000 && but == 0) { // 32400 seconds = 9 hours
digitalWrite(power, HIGH);
but = digitalRead(cancel);
curr = millis() - prev;
}
digitalWrite(power, LOW);
but = 0;
curr = 0;
}

void PowerCut()
{
prev = millis();
curr = millis() - prev;

while (curr < 21600000 && but == 0) //21600 seconds = 6 hours
{
digitalWrite(power, HIGH);
but = digitalRead(cancel);
curr = millis() - prev;
}
digitalWrite(power, LOW);
but = 0;
curr = 0;
}

void LightRead()
{
light[lindex] = analogRead(analogPin);
lindex++;
lavg = 0;

if (lindex == 19 )
{

for (i = 0; i < 20; i++)
{
lsum += light*;*

  • }*
  • lavg = lsum / 20; // is 0-19 so is still 20 elements*
  • lindex = 0;*
  • lsum = 0;*
  • }*
  • if (lavg > 750) // (1k pulldown resistor)950 full sunlight, 800 lightly overcast day, 600 @ 17:30 in July and 200 @ Dusk (17:45). 50 points diff with varying orientations*
  • {*
  • WindowsOpen();*
  • }*
  • if (lavg < 400 && lavg > 10)*
  • {*
  • WindowsClose();*
  • }*
  • if (lavg < 10)*
  • {*
  • PowerCut();*
  • }*
    }

This looks interesting but maybe something for this section of the forum: http://forum.arduino.cc/index.php?board=29.0

You should edit anyway to include code tags to stop your code being mistranslated as formatting characters.

I guess it does not (yet) support daylight saving time clock changes:

setTime(14, 15, 00, 1, 1, 16); // set time to  13:30:00pm Jan 1 2016

Thanks for posting, but please edit your post to add code tags ("</>" button).