Arduino Curtain Automation: DIY Home Automation Tutorial!

From our STAR Maker: Shizen

This Arduino Curtain Automation project will let you automate your curtain blinds using just an arduino and a stepper motor.
I just moved to America for pursuing my higher studies. Because my dorm is very dark, I wanted to brighten up my room when I wanted to. Since I would be there for only for a month, I couldn’t make anything too complicated. So I decided to make myself this DIY Arduino Curtain Automation system. Using regular curtain blinds I could control the amount of light in the room and suit it according to my needs.

Arduino curtain automation

The design for this Arduino Curtain Automation system is quite simple and there are two ways to activate the curtains:

  1. Using a sound sensor (mic) to control it using my claps (Step 2).
  2. Using buttons to move the shades of the curtain (Step 3).

So lets get started with our DIY Arduino Curtain Automation system, follow the simple instructions to replicate this project.

What are the stuff required to do this project?

Arduino curtain automation

  1. Arduino (I am using Arduino Nano to save space; in the picture, it’s attached to a shield for easy testing): India link, US link
  2. Adafruit sound sensor (optional): India link, US link
  3. Stepper motor +Darlington array driver: India link, US link
  4. 2-3 Buttons
  5. An LED for indication
  6. Jumper wires and breadboard

How does it work?

Arduino curtain automation

The working of this DIY Arduino Curtain Automation system is very simple. Here, the arduino takes input from either the sound sensor (mic) or buttons. It then correspondingly controls the stepper motor through the darlington array driver for the motor. The stepper motor is attached to the control stick of the curtain blinds and thus on rotation, opens/closes the blinds.

STEP 1: Interfacing the stepper motor

Arduino curtain automation

The first step I did was testing the design for the Arduino curtain automation system. The motor is connected to the 4 wires of the driver as shown in the diagram. Depending on the direction of rotation for your curtain, you need to plug the driver accordingly

Basically, the first button from the right will activate the motor to spin a particular degree (you can change in the code). Press the button 4 times and it will return to the original place since it will spin around 90 degrees during each press. The middle button will lock the circuit, so that the first button cannot activate the motor. The LED will turn ON when the motor is locked. The final button will return the motor to the original place no matter where is it, at the time pressed. It’s still a simple program, hope you guys understand. You can find the code below.

int pin[8]={2,3,4,5,6,7,8,9};
int steps[][4] = 
  {
    {HIGH,HIGH,LOW,LOW},
    {HIGH,LOW,LOW,HIGH},
    {LOW,LOW,HIGH,HIGH},
    {LOW,HIGH,HIGH,LOW},
  } ;

int numofroun=1; //Change accordingly to your needs

int current=1;
int type=3;
int place=0;

int lastLockState = LOW;   
long lastLockTime = 0;
int LockState;
int Lockreading;
bool lock=true;

int lastPauseState = LOW;   
long lastPauseTime = 0;
int PauseState;
int Pausereading;
bool Pauseled=false;
bool pause=false;

int lastReturnState = LOW;   
long lastReturnTime = 0;
int ReturnState;
int Returnreading;

void setup() {
  for (int num=0; num<5; num++) pinMode(pin[num],OUTPUT);
  for (int num=5; num<8; num++) pinMode(pin[num],INPUT);
}

void reset(){
  for(int num=0;num<4;num++) digitalWrite(pin[num],LOW);
}

void stepper()
{
  for (int num=0; num<4;num++) { digitalWrite(pin[num],steps[abs(type-current)][num]);} if(type==0) {++place;} if(type==3) {--place;} delay(2); } void button1() { Lockreading = digitalRead(pin[5]); if (Lockreading != lastLockState) { lastLockTime = millis(); } if ((millis() - lastLockTime) > 50)
  {
    if (Lockreading != LockState) {
      LockState = Lockreading;
      if (LockState == HIGH) {
        lock=false;        
        if ((place!=1536*numofroun)&&(place!=1024*numofroun)&&(place!=512*numofroun)) {type=abs(type-3);}
      }
    }
  }
  lastLockState = Lockreading;
}

void button2()
{
  Pausereading = digitalRead(pin[6]);
  if (Pausereading != lastPauseState) 
  {
    lastPauseTime = millis();
  }
  if ((millis() - lastPauseTime) > 50)
  {
    if (Pausereading != PauseState) {
      PauseState = Pausereading;
      if (PauseState == HIGH) {
        Pauseled=!Pauseled;
        pause=!pause;
        if (Pauseled) {digitalWrite(pin[4],HIGH);}
        if (!Pauseled) {digitalWrite(pin[4],LOW);}
      }
    }
  }
  lastPauseState = Pausereading;
}

void button3()
{
  Returnreading = digitalRead(pin[7]);
  if (Returnreading != lastReturnState) 
  {
    lastReturnTime = millis();
  }
  if ((millis() - lastReturnTime) > 50)
  {
    if (Returnreading != ReturnState) {
      ReturnState = Returnreading;
      if (ReturnState == HIGH) {
        type=3;
        while (place>0)
        {
          for (int num=0; num<4;num++) { 
          digitalWrite(pin[num],steps[3-current][num]);}
          --place;
          if (current==3) {current=0;}
          else ++current;
          delay(2);
        }
        reset();
      }
    }
  }
  lastReturnState = Returnreading;
}

void loop() {
  if (lock==true) {button2();button3();}
  if (!pause)
  {
    if (lock==true) {button1();}
    if (lock==false) {stepper();}
    if ((place==2048)or(place==0)or(((place==1536*numofroun)or(place==1024*numofroun)or(place==512*numofroun))&&(type==3)))
       {lock=true;reset();}
    if (current==3) {current=0;}
    else ++current;
  }
}

 

STEP 2: Setting up the Arduino Curtain Automation system

Arduino curtain automation

Now after testing the stepper motor, you can use the connection diagram above to make the final prototype. After I finished making mine, I simply changed the input (button) into a sound sensor. You can find the code below.

int pin[8]={2,3,4,5,6,7,8,9};
int steps[][4] = 
  {
    {HIGH,HIGH,LOW,LOW},
    {HIGH,LOW,LOW,HIGH},
    {LOW,LOW,HIGH,HIGH},
    {LOW,HIGH,HIGH,LOW},
  } ;

float numofroun=4.5; //Change accordingly to your needs

int current=1;
int type=3;
int place=0;

int claps = 0;
long detectionSpanInitial = 0;
long detectionSpan = 0;
long spancondition;
bool spanconditioncheck=false;

bool lock=true;

int lastPauseState = LOW;   
long lastPauseTime = 0;
int PauseState;
int Pausereading;
bool Pauseled=false;
bool pause=false;

int lastReturnState = LOW;   
long lastReturnTime = 0;
int ReturnState;
int Returnreading;

void setup() {
  for (int num=0; num<5; num++) pinMode(pin[num],OUTPUT);
  for (int num=5; num<8; num++) pinMode(pin[num],INPUT);
}

void reset(){
  for(int num=0;num<4;num++) digitalWrite(pin[num],LOW);
}


void stepper()
{
  for (int num=0; num<4;num++) { digitalWrite(pin[num],steps[abs(type-current)][num]);} if(type==0) {++place;} if(type==3) {--place;} delay(2); } void sound() { int sensorState = digitalRead(pin[5]); if (sensorState == 0){ if (claps == 0){ detectionSpanInitial = detectionSpan = millis(); claps++; } else if (claps > 0 && millis()-detectionSpan >= 50){
      detectionSpan = millis();
      claps++;
    }
  }
  if (millis()-detectionSpanInitial >= 400)
  {
    if (claps == 2)
    {
      lock=false;        
      if ((place!=1024*numofroun)&&(place!=512*numofroun)) {type=abs(type-3);}
      spancondition=millis();
    }
    claps = 0;
  }
}

void button1()
{
  Pausereading = digitalRead(pin[6]);
  if (Pausereading != lastPauseState) 
  {
    lastPauseTime = millis();
  }
  if ((millis() - lastPauseTime) > 50)
  {
    if (Pausereading != PauseState) {
      PauseState = Pausereading;
      if (PauseState == HIGH) {
        Pauseled=!Pauseled;
        pause=!pause;
        spancondition=millis();
        if (Pauseled) {digitalWrite(pin[4],HIGH);}
        if (!Pauseled) {digitalWrite(pin[4],LOW);}
      }
    }
  }
  lastPauseState = Pausereading;
}

void button2()
{
  Returnreading = digitalRead(pin[7]);
  if (Returnreading != lastReturnState) 
  {
    lastReturnTime = millis();
  }
  if ((millis() - lastReturnTime) > 50)
  {
    if (Returnreading != ReturnState) {
      ReturnState = Returnreading;
      if (ReturnState == HIGH) {
        type=3;
        while (place>0)
        {
          for (int num=0; num<4;num++) { digitalWrite(pin[num],steps[3-current][num]);} --place; if (current==3) {current=0;} else ++current; delay(2); } reset(); spancondition=millis(); } } } lastReturnState = Returnreading; } void loop() { if (lock==true) {button1();button2();} if (!pause) { if ((lock==true)&&(millis()-spancondition>1000)) {sound();}
    if (lock==false) {stepper();spanconditioncheck=false; }
    if ((place==2048*numofroun)or(place==0)or(((place==1024*numofroun)or(place==512*numofroun))&&(type==3))){
       lock=true;
       reset();
       if (!spanconditioncheck){
        spancondition=millis();
        spanconditioncheck=true;
       }
     }
    if (current==3) {current=0;}
    else ++current;
  }
}

 
Arduino curtain automation

I used foam board to make the holder for the motor (1, 2) and curtain handle (3) of my Arduino curtain automation system. Because my dorm doesn’t allow modding the wall, I later used double side tape to stick it in place (1).

Arduino curtain automation

The pause button is there so that if your room gets too loud, you can lock it so that the blinds won’t go crazy. Note that you might have to adjust the potentiometer on the sound sensor to adjust the sensitivity.

Arduino curtain automation

Check out the demo video of the clap controlled DIY Arduino Curtain Automation system here:

STEP 3: An alternate version using just buttons

Arduino curtain automation

If you don’t like sound control, you can simply use a button. In this Arduino curtain automation design, there are only two buttons: activate and return (since the pause isn’t needed). The activate is the same as before; the reset button will return the curtain back to the original place while activating the LED. You can find the code for this version here.

int pin[8]={2,3,4,5,6,7,8};
int steps[][4] = 
  {
    {HIGH,HIGH,LOW,LOW},
    {HIGH,LOW,LOW,HIGH},
    {LOW,LOW,HIGH,HIGH},
    {LOW,HIGH,HIGH,LOW},
  } ;
int current=1;
int type=3;
int place=0;

int lastLockState = LOW;   
long lastLockTime = 0;
int LockState;
int Lockreading;
bool lock=true;

int lastReturnState = LOW;   
long lastReturnTime = 0;
int ReturnState;
int Returnreading;

void setup() {
  for (int num=0; num<5; num++) pinMode(pin[num],OUTPUT);
  for (int num=5; num<7; num++) pinMode(pin[num],INPUT);
}

void reset(){
  for(int num=0;num<4;num++) digitalWrite(pin[num],LOW);
}

void stepper()
{
  for (int num=0; num<4;num++) { digitalWrite(pin[num],steps[abs(type-current)][num]);} if(type==0) {++place;} if(type==3) {--place;} delay(2); } void button1() { Lockreading = digitalRead(pin[5]); if (Lockreading != lastLockState) { lastLockTime = millis(); } if ((millis() - lastLockTime) > 50)
  {
    if (Lockreading != LockState) {
      LockState = Lockreading;
      if (LockState == HIGH) {
        lock=false;        
        if ((place!=1024*4)&&(place!=512*4)) {type=abs(type-3);}
      }
    }
  }
  lastLockState = Lockreading;
}

void button2()
{
  Returnreading = digitalRead(pin[6]);
  if (Returnreading != lastReturnState) 
  {
    lastReturnTime = millis();
  }
  if ((millis() - lastReturnTime) > 50)
  {
    if (Returnreading != ReturnState) {
      ReturnState = Returnreading;
      if (ReturnState == HIGH) {
        type=3;
        digitalWrite(pin[4],HIGH);
        while (place>0)
        {
          for (int num=0; num<4;num++) { 
          digitalWrite(pin[num],steps[3-current][num]);}
          --place;
          if (current==3) {current=0;}
          else ++current;
          delay(2);
        }
        digitalWrite(pin[4],LOW);
        reset();
      }
    }
  }
  lastReturnState = Returnreading;
}

void loop() {
  if (lock==true) {button1();button2();}
  if (lock==false) {stepper();}
  if ((place==2048*4)or(place==0)or(((place==1024*4)or(place==512*4))and(type==3))){lock=true;reset();}
  if (current==3) {current=0;}
  else ++current;
}

 
Check out the demo video of this version of my DIY Arduino Curtain Automation system:

I hope that you enjoyed my Android Curtain Automation project. And I hope to keep posting more of my projects even though I get quite busy with college. Have fun automating your curtains :)

Arduino curtain automation

From our STAR Maker: Shizen

 

-Submitted by Shizen
I am a Vietnamese student. I just graduated high school and now I’m studying abroad in the US. I am doing my major in electrical engineering.

Recommended Posts
Showing 4 comments
  • Tom
    Reply

    what rezistors u use for this ?

  • DIN0
    Reply

    nice article… but in this article it showed Sound sensor and Button version…. can i ask u how i want to construct this circuit if i want to replace the sound sensor with the ldr sensor?? Really need ur answer ASAP… Wished that u have a good day and Thank You

  • Reply

    I do not even know how I stopped up right here, but I assumed this
    submit used to be good. I do not recognise who you’re however certainly you’re going to
    a well-known blogger if you aren’t already. Cheers!

  • sdrshnptl
    Reply

    Hello @Shizen,
    nice written and explained article.

Leave a Comment

− 5 = 5

Start typing and press Enter to search