Introduction

Have you dreamt of waking up to your smart blinds automatically letting in the bright sunshine of a new day? Have you longed for sleeping soundly in the darkness of your room after your blinds sensed the sun went down? Well, rest easy, now your dreams can come true. The scope of this project is creating a system for automating blinds by detecting light and distinguishing between dusk and dawn.

Things you will need:

  • The Sparkfun RedBoard Arduino kit
  • A breadboard
  • A Generic Servo – or a continuous rotation servo (but these are very expensive)
  • 10 jumper wires
  • A Photoresistor – photocell/light controlled variable resistor
  • A soldering iron (for creating a continuous rotation servo)
  • A popsicle stick or something to connect the servo and the blinds

Using the Sparkfun RedBoard Arduino kit, complete Circuit 6 and Circuit 8. Essentially, we will be combining these two circuits in this project. The SparkFun website already does a great job of explaining these circuits, so make sure to come back here after completing these two circuits. Here are some problems I ran into while completing these:

Circuit 6- Photoresistor

NOTE: The calibrated interval with the manual set up (Min level 0 and max level 1023 for the light levels) may not work well depending on the lighting conditions of your room. In fact, the circuit may work fine the entire time, but there may be a very subtle difference between when the LED is dim and when it is bright. After using the auto function, it is much more obvious that the light is, in fact, changing in accordance with the input from the photoresistor.

Circuit 8- Single Servo

It is surprisingly easy to put a servo in backwards…also connecting the signal to ground will 100% of the time cause the circuit not to work… So an easy fix was reversing the order of the pins. Now everything works! Here’s a cool gif of the servo spinning (well…almost spinning..not doing an entire 360 of course)

Rotating the Servo

Servos typically only turn up to 180 degrees, unless you get a fancy schmancy continuous rotation servo. However, blinds require a servo that can turn more than 180 degrees. Thankfully, we can solve this issue by taking apart the servo and removing the potentiometer. Alter your servo for continuous rotation and direction change by soldering an extra wire to control the direction.

Step 2: Connecting servo to blinds

A problem that I show in the video is that if the servo is not placed properly on the rotating mechanism, it rotates around itself instead of rotating the mechanism that shuts and opens the blinds. This problem was easily fixed by adjusting the angle where the popsicle head attachment attaches to the rotating mechanism on the blind. A similar problem occurs if a weaker or smaller servo is used. This is why I bought servos separate from the ones provided in the SIK kit.

Controlling when to stop servo from spinning

Unfortunately, because of the servo modification for continuous rotation, we can no longer simply stop the servo by setting it to an angle like in SIK Circuit 8. However, this problem is solved by having a loop to count the number of rotations made so that it can stop after it knows that the blinds are fully opened or closed- in this case after 4 full rotations. Of course, this means that the settings for this design will be binary (fully opened or fully closed) instead of having in between options. This design can be replaced with one that allows for in-between values, or extended to work with an Android app for manual user control.

Turning slower in one direction

Another issue I came across was that the servo tuned faster counterclockwise than it did clockwise. This was strange, as it did not seem to be because of the code. I tried changing the code several times and it continued to remain a problem. My thought was that it may be a hardware limitation or maybe I had done something wrong when modifying the servo. Either way, I liked this design because it meant the blinds closed more slowly and opened faster, I don’t mind, I love sunlight!

Photoresistor Light exposure

The calibrated interval with the manual set up (Min level 0 and max level 1023 for the light levels) didn’t work very well for my room. After I used the auto function it was much more obvious that it was in fact working. After using the auto function for the Arduino to automatically determine which settings are best, the photoresistor served as a much better input.

Making a video on the implementation seemed like a much better way to explain the project and how I made it, so please refer to the attached video for the program implementation.

View video here: (https://youtu.be/cQVNoQGKh0g)

Unit testing was the best test approach to determine that each individual component works before testing the system as a whole.

Program Implementation

The programming for the automated blinds used a lot of the SIK circuit I learned from circuit 8 (Driving a servo motor) combined with circuit 6 (Reading a photoresistor). The hardest part of programming the circuit was figuring out how to communicate with the extra wire I soldered onto the servo for changing the servo direction. Also how to take the input from the photoresistor and translate this to changing the servo direction using this new wire.


#include</span> <span class="cpf">&lt;Servo.h&gt;  // servo library</span>
<span class="n">Servo</span> <span class="n">servo1</span><span class="p">;</span>  <span class="c1">// servo control object</span>
<span class="kt">void</span> <span class="nf">setup</span><span class="p">()</span>
<span class="p">{</span>
  <span class="n">servo1</span><span class="p">.</span><span class="n">attach</span><span class="p">(</span><span class="mi">9</span><span class="p">);</span>
  <span class="n">pinMode</span><span class="p">(</span><span class="mi">5</span><span class="p">,</span> <span class="n">OUTPUT</span><span class="p">);</span>
    <span class="n">Serial</span><span class="p">.</span><span class="n">begin</span><span class="p">(</span><span class="mi">9600</span><span class="p">);</span>     <span class="c1">// opens serial port, sets data rate to 9600 bps</span>
  <span class="n">Serial</span><span class="p">.</span><span class="n">println</span><span class="p">(</span><span class="s">"Please input 0 or 1"</span><span class="p">);</span>
<span class="p">}</span>

<span class="kt">void</span> <span class="nf">loop</span><span class="p">()</span> <span class="p">{</span>
  <span class="kt">int</span> <span class="n">direction</span><span class="p">;</span>
<span class="c1">// if user input</span>
<span class="k">if</span><span class="p">(</span><span class="n">Serial</span><span class="p">.</span><span class="n">available</span><span class="p">()</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span>
  <span class="c1">//then change position of servo to whatever the user input</span>
<span class="n">direction</span> <span class="o">=</span> <span class="n">Serial</span><span class="p">.</span><span class="n">parseInt</span><span class="p">();</span>
  <span class="k">if</span><span class="p">(</span> <span class="n">direction</span> <span class="o">==</span> <span class="mi">0</span> <span class="p">)</span>
<span class="p">{</span>
<span class="n">digitalWrite</span><span class="p">(</span><span class="mi">5</span><span class="p">,</span> <span class="n">HIGH</span><span class="p">);</span>
<span class="n">servo1</span><span class="p">.</span><span class="n">write</span><span class="p">(</span><span class="mi">180</span><span class="p">);</span> <span class="c1">// sets the servo position according to the scaled value</span>
<span class="p">}</span>
<span class="k">else</span> <span class="k">if</span> <span class="p">(</span> <span class="n">direction</span> <span class="o">==</span> <span class="mi">1</span> <span class="p">)</span>
<span class="p">{</span>
<span class="n">digitalWrite</span><span class="p">(</span><span class="mi">5</span><span class="p">,</span> <span class="n">LOW</span><span class="p">);</span>
<span class="n">servo1</span><span class="p">.</span><span class="n">write</span><span class="p">(</span><span class="mi">180</span><span class="p">);</span> <span class="c1">// sets the servo position according to the scaled value}</span>
<span class="mf">4.2.1</span> <span class="n">Testing</span> <span class="n">photoresistor</span> 
<span class="cp">#include</span> <span class="cpf">&lt;Servo.h&gt;  // servo library</span>
<span class="k">const</span> <span class="kt">int</span> <span class="n">sensorPin</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="k">const</span> <span class="kt">int</span> <span class="n">ledPin</span> <span class="o">=</span> <span class="mi">9</span><span class="p">;</span>
<span class="n">Servo</span> <span class="n">servo1</span><span class="p">;</span>  <span class="c1">// servo control object</span>
<span class="kt">int</span> <span class="n">lightLevel</span><span class="p">,</span> <span class="n">high</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="n">low</span> <span class="o">=</span> <span class="mi">1023</span><span class="p">;</span>
<span class="kt">void</span> <span class="n">setup</span><span class="p">()</span>
<span class="p">{</span>  <span class="n">pinMode</span><span class="p">(</span><span class="n">ledPin</span><span class="p">,</span> <span class="n">OUTPUT</span><span class="p">);</span>
  <span class="n">servo1</span><span class="p">.</span><span class="n">attach</span><span class="p">(</span><span class="mi">9</span><span class="p">);</span>
  <span class="n">pinMode</span><span class="p">(</span><span class="mi">5</span><span class="p">,</span> <span class="n">OUTPUT</span><span class="p">);</span>
    <span class="n">Serial</span><span class="p">.</span><span class="n">begin</span><span class="p">(</span><span class="mi">9600</span><span class="p">);</span>     <span class="c1">// opens serial port, sets data rate to 9600 bps</span>
<span class="kt">void</span> <span class="n">loop</span><span class="p">(){</span>
  <span class="n">lightLevel</span> <span class="o">=</span> <span class="n">analogRead</span><span class="p">(</span><span class="n">sensorPin</span><span class="p">);</span>
  <span class="n">autoTune</span><span class="p">();</span>  <span class="c1">// have the Arduino do the work for us!</span>
  <span class="n">analogWrite</span><span class="p">(</span><span class="n">ledPin</span><span class="p">,</span> <span class="n">lightLevel</span><span class="p">);}</span>
<span class="kt">void</span> <span class="n">autoTune</span><span class="p">(){</span>
  <span class="k">if</span> <span class="p">(</span><span class="n">lightLevel</span> <span class="o">&lt;</span> <span class="n">low</span><span class="p">)</span>  <span class="p">{</span>    <span class="n">low</span> <span class="o">=</span> <span class="n">lightLevel</span><span class="p">;</span>  <span class="p">}</span>
  <span class="k">if</span> <span class="p">(</span><span class="n">lightLevel</span> <span class="o">&gt;</span> <span class="n">high</span><span class="p">)</span>  <span class="p">{</span>    <span class="n">high</span> <span class="o">=</span> <span class="n">lightLevel</span><span class="p">;</span>  <span class="p">}}

<span class="cp">

Outcome

My robot met all of my personal design expectations, however, a lot of improvements can still be made. What I would like to add are:

  1. A bluetooth or Wifi connection so that the Sparkfun does not require to be mounted to the laptop
  2. An android app for users to control their blinds remotely
  3. A temperature reader attached to display the temperature and potentially use this information as well to determine if the blinds should be opened
  • Buy a different set of blinds that have a better turning mechanism
  • Build a small enclosure where the servo can be permanently attached to the blinds
  • Place photoresistor outside

Hopefully by completing this project you can learn a little about how servos and photoresistors work, as well as using the Arduino IDE, feedback loops, and about automation in general. Some ideas for creating a better system for automating blinds are adding bluetooth or experimenting with adding an app for users to control the blinds remotely. Video Link: https://www.youtube.com/watch?v=cQVNoQGKh0g&t=21s

Note: This project will be experimental, since this requires the photoresistor to be placed outside for optimal results, and also requires bluetooth or wifi communication with a server.

to understand the basics of how servos and photoresistors work.

Leave a Reply