Top Logo Sp Logo
Arduino Blinds Control Project

Arduino Blinds Control Project

Arduino Blinds Control Project

Materials

Hookup Instructions

  1. Connect a jumper wire from the 5V pin on the Arduino to one of the + rails on the breadboard.

2. Connect a jumper wire from the GND pin on the Arduino to the - rail next to the + rail you chose on the breadboard.

3. Place a 10 kohm resistor on the breadboard with one leg connected to the - rail with ground connected to it.

4. Place the photocell on the breadboard with one leg connected to the resistor.

5. Place a jumper from the + rail with 5V on it to the other leg of the photocell.

6. Place a jumper from analog pin 0 to the leg of the photocell connected to the 10 kohm resistor.

7. Place the servo connector pins on the breadboard.

8. Place a jumper from the red wire to the + rail with 5V on it on the breadboard.

9. Place a jumper from the black wire to the - rail with ground on it on the breadboard.

10. Place a jumper from digital pin 3 to the signal wire on the servo (the picture shows yellow, my physical servo has a white wire).

Programming Instructions

Overview: There are many ways to go about programming a simple control function like this one.   Here, we will read the raw value from the photocell, see if it’s in our acceptable range (decided by you from your setting. Easy way to do this is write a simple sketch reading the analog value and see about what it reads in different lighting), then adjust the servo accordingly to increase or decrease the light.

Variables

We need several variables in the program to keep track of various things. Create these as global variables at the beginning of the sketch.

  1. Create an instance of the Servo class (see servo at cc/reference).
  2. Create an integer variable for your photoresistor pin and set it equal to 0 to use analog pin 0.
  3. Create an integer variable to read the analog value in Name it something that makes sense to you.
  4. Create an integer variable for the upper limit of acceptable light and set it to what you decided (mine was about 300).
  5. Create an integer variable for the lower limit of acceptable light and set it to what you decided (mine was about 95).
  6. Create an integer variable for the max position of the servo. Mine is 180 because I have a 180 degree servo. If you have a 270 or 360 degree servo, set it accordingly.
  7. Create an integer variable for the minimum position of the servo and set it equal to 0.
  8. Create an integer variable for the halfway position of your servo to initialize it to so it can have maximum travel in both directions to adjust the light with. Mine is 90 because I have a 180 degree servo.
  9. Create an integer variable to store the current position of the servo and set it equal to 0.

Setup

  1. Attach the servo variable to pin 3 (see attach() at cc/reference).
  2. Write the initial position declared above to the servo (see write() at cc/reference).
  3. Store the current position as the initial position just written to the servo.
  4. Initialize the serial port at 9600 baud.

Decrease Light

  1. Next, we need to create a function that includes steps to decrease the amount of light coming through the blinds.
  2. Below your loop function, create a function “void decLight()” or something named how you’d like it.
  • In this function, first check to make sure that if you move the servo in the decrease direction you won’t go below the minimum position.
  • If you won’t, decrease your current position variable by 10 and write it to the servo.

Increase Light

  1. Next, we need to create a function that includes steps to increase the amount of light coming through the blinds.
  2. Below your loop function, create a function “void incLight()” or something named how you’d like it.
  • In this function, first check to make sure that if you move the servo in the increase direction you won’t go above the maximum position.
  • If you won’t, increase the current position variable by 10 and write it to the servo.

 

Loop

  1. In the main loop, you first need to read the analog value from the photocell. You can either build another function to do this, or simply use the analogRead() function here (see analogRead() at arduino.cc/reference).
  2. If your analog value is between your upper limit and lower limit, do nothing!
  3. Else if (hint hint) the analog value is above your upper limit, call your decrease light function.
  4. Else if (hint hint) the analog value is below your lower limit, call your increase light function.
  5. Else (hint hint) do nothing. (You’re program should never get here, but it’s required to avoid syntax errors.)
  6. You can then print the current analog value to see what kind of light intensity you currently have.
Shop the story