The making of: Arduino controlled blinds with music

August 3rd, 2012

Everyday I have to deal with something way more challenging than discovering an off-by-one bug in a messy 2k lines source and that’s waking up. I love to sleep, what can I say.

But a month ago I finally decided that my every morning agony had to stop and that there must have been a way to wake up in a pleasant way. So I decided to brainstorm on a few ideas. For sure I wanted music to wake me up, not an annoying buzzing alarm sound, something like the Lion King’s theme song. Then I had to deal with the darkness in the room. At first I thought to put a few lamps that could be controlled to turn on when the music starts. But that ended up being a rather complicated solution, and I wasn’t sure about the quality of the light. What about natural sun light? Yes, that was it. Make automated blinds that open when the music kicks in.

The first step was to replace the ugly curtains I have been having in my room with some cheap blinds I bought for $20. Then I removed the stick that allows you to maneuver them and moved the leverage pin upside down. I wasn’t sure of how I would have hooked it up, but placing my system on top of the blinds seemed to make sense.

The I had to find a project box that would enclose my system. I wanted to make this solution as cheap as possible, so I didn’t go buy one, but I looked around my room for old electronic parts and I found this old CD-ROM reader from late 1990s that had a very nice aluminum enclosure. It ended up being more useful than just providing me with a nice box. It also had some nice plastic bits that I later used to hook up the Arduino to the box.

I wanted the blinds to operate in this manner:

  • Music kicks in, blinds open and wait for music to stop
  • Music stops, blinds stay open for 30 more seconds, then they close.
I wanted to control the music with my iPod Touch and have controls that would allow me to operate the blinds manually. So I bought a cheap pair of speakers from eBay for $5 and an audio jack long enough that I could run alongside the window ($9). I also bought an audio splitter that would allow me to plug the cable into the speakers while allowing the other end to be used to detect the start of the music.
I already had an Arduino board that was sitting in my room collecting dust, so all I needed was some wire, solder, screws, patience and a motor.

My first attempt involved taking an old motor that I found time ago inside a Polaroid camera; unfortunately that didn’t seem to have enough strength, so I had to go online and purchase a low powered  motor from Solarbotics (https://www.solarbotics.com/product/gm3/).

(Failed attempt: using a motor from an old Polaroid camera)

(Success: the motor from Solarbotics had enough power to operate the blinds)

I drilled a small hole on the rotating plastic knob and I hooked an untwisted paper clip to it. In turn I later used the paper clip to connect the motor to the blinds.

I decided to use the 5V output from the Arduino to power the speakers, although the label required 6V. It still worked fine! Awesome.

The tricky part was to get the Arduino to control the motor. Each output pin serves around 50 mA and it wasn’t enough to power the motor alone. So I used two pins in parallel to control each polarity of the motor (using 4 pins total). Whenever I wanted to move the motor clockwise I would set two pins to 5V and the other two to 0V, to move the counter-clockwise I would invert the voltage. It worked! To detect the music I stripped the audio cable and plugged one wire into an analog pin and detected the change in voltage to find out when the music would start.

It was then time to think about the manual controls; I went to radio shack and bought a small project box, along with two switches. I took some wire and made a twisted pair for each switch, that way I could run a small current through each pair and detect with the Arduino whether the switch was on (current running) or off (current not running). I made a few holes in the project box to fit the switches and mounted it on the side of the window with a few screws.

I finally put all the wires in their place (trying to make it look nice), mounted the box on top of the blinds with a few screws and wrote some code. The tricky part of the code was to calibrate it in such a way that noise would not cause the blinds to open (that could have been an embarrassing situation during certain times of the day 🙂 ).


const int motorPin1a = 12;
const int motorPin1b = 13;

const int motorPin2a = 7;
const int motorPin2b = 8;

const int cwSwitchReadPin = A0;
const int cwSwitchWritePin = 5;

const int ccwSwitchReadPin = A2;
const int ccwSwitchWritePin = 3;

const int musicPin = A5;

const int timeToOpenCurtain = 11500;

int musicBeatCount = 0;
int musicSilentCount = 0;
int curtainOpened = 0;

void setup() {
  pinMode(motorPin1a, OUTPUT);
  pinMode(motorPin2a, OUTPUT);
  pinMode(motorPin1b, OUTPUT);
  pinMode(motorPin2b, OUTPUT);

  pinMode(cwSwitchWritePin, OUTPUT);
  pinMode(cwSwitchReadPin, INPUT);

  pinMode(ccwSwitchWritePin, OUTPUT);
  pinMode(ccwSwitchReadPin, INPUT);

  pinMode(musicPin, INPUT);

  digitalWrite(cwSwitchWritePin, HIGH);
  digitalWrite(ccwSwitchWritePin, HIGH);

  Serial.begin(9600);
}

void loop() {
  int cwValue = analogRead(cwSwitchReadPin);

  if (cwValue < 500){
      runMotorCw();
      musicBeatCount = 0;
      musicSilentCount = 0;
      curtainOpened = 0;
  }else{
      stopMotor();
  }

  int ccwValue = analogRead(ccwSwitchReadPin);
  Serial.println(cwValue);

  if (ccwValue < 1015){
      runMotorCcw();
      musicBeatCount = 0;
      musicSilentCount = 0;
      curtainOpened = 0;
  }else{
      stopMotor();
  }

  // Read from music analog
  int musicValue = analogRead(musicPin);
  if (curtainOpened == 0 && musicValue > 4){
    musicBeatCount++;
  }else{
    musicBeatCount--;
    if (musicBeatCount < 0) musicBeatCount = 0;
  }

  if (musicBeatCount > 10 && curtainOpened == 0){
      runMotorCcw();
      delay(timeToOpenCurtain);
      curtainOpened = 1;
  }

  if (curtainOpened == 1){
     if (musicValue < 3){
        musicSilentCount++;
     }else{
        musicSilentCount--;
        if (musicSilentCount < 0) musicSilentCount = 0;
     }

     if (musicSilentCount > 30){
        delay(30000);
        runMotorCw();
        delay(timeToOpenCurtain);
        curtainOpened = 0;
        musicSilentCount = 0;
     }
  }
}

void stopMotor(){
  digitalWrite(motorPin2a, LOW);
  digitalWrite(motorPin1a, LOW);
  digitalWrite(motorPin2b, LOW);
  digitalWrite(motorPin1b, LOW);
}

void runMotorCcw(){
  digitalWrite(ccwSwitchWritePin, LOW);
  digitalWrite(motorPin1a, LOW);
  digitalWrite(motorPin2a, HIGH);
  digitalWrite(motorPin1b, LOW);
  digitalWrite(motorPin2b, HIGH);
  delay(250);
  digitalWrite(ccwSwitchWritePin, HIGH);
}

void runMotorCw(){
  digitalWrite(cwSwitchWritePin, LOW);
  digitalWrite(motorPin2a, LOW);
  digitalWrite(motorPin1a, HIGH);
  digitalWrite(motorPin2b, LOW);
  digitalWrite(motorPin1b, HIGH);
  delay(250);
  digitalWrite(cwSwitchWritePin, HIGH);
}

I uploaded the code to the Arduino and closed the project box. Tada’!

I’ll end this post with a video showing the final result! Enjoy!

4 Comments

  1. amazing! the best thing will be to open gradually the curtains, so you don’t wake up too short

    Comment by Qwertj — August 4, 2012 @ 9:52 am
  2. :O

    Comment by Muszynskisimone — August 15, 2012 @ 9:09 am
  3. […] http://www.pierotoffanin.com – Today, 6:04 PM Rescoop […]

  4. […] reference to this project, today I updated the Arduino sketch for my automated blinds. It turns out that a drier and colder […]

RSS feed for comments on this post. TrackBack URI

Sorry, the comment form is closed at this time.