You are on page 1of 24

AUTOMATED BLINDS

Prepared for
Professor Rashdee
EET-344: Microprocessor with Peripherals
DeVry University, Fremont

Prepared by
Mai Zoua Vang
Justin Niel
Joshua Quintero

February 13, 2007


CONTENTS

Page

ABSTRACT..................................................................................................….................1

INTRODUCTION/FEASIBILITY………………………………………………………..1

MATERIALS AND EQUIPMENTS……………………………………………………...5


Basic information of ADC ………………………………………………………..5
Basic information of reversed-bias LED………………………………………....6
Basic information of 3-to-8 line decoder………………………………………....6
Basic information of stepping motor ……………………………………………..7
Basic information of ULN2003 …………………………………………………..7

PROGRAMMING AND INTERFACING APPROACH…..…………………………….8


Flowchart …………………………………………………………………………8
Hardware ………………………………………………………………………...12

SOFTWARE CODE…….……………………………………………………………….14

RESULTS ……………………………………………………………………………….19

CONCLUSION ………………………………………………………………………….19

WORKS CITED ………………………………………………………………………...20

APPENDIX ……………………………………………………………………………...21

ii
LIST OF ILLUSTRATIONS

Figures Page

1. Figure 1: Light Sensors 2

2. Figure 2: Left Sensor 2

3. Figure 3: Center Sensors 3

4. Figure 4: Right Sensor 3

5. Figure 5: Blinds 4

6. Figure 6: ADC Pin out 5

7. Figure 7: 3-to-8 Decoder Pin out (MM74HC138M) 6

8. Figure 8: Stepper Motor sequence 7

9. Figure 9: ULN2003 pin out 7

10. Figure 10: ADC connection to decoder 12

11. Figure 11: ULN2003 connection to Stepper Motor 13

12. Figure 12: Circuit 13

iii
1

ABSTRACT

Background

Have you ever had trouble with your blinds letting out too much heat at night when you forget to
close them? Or would you like your blinds to be open, letting in sunlight and heat as soon as you
get up in the morning? Well we are here to help! We at Solar Blind Systems Inc. have devised a
solution for all of your troubles. It is automatic blinds! These specially designed blinds will
allow the shutters to follow the sunlight in order to let in an optimal amount of heat for your
home and close up when not in use.

Results

We found that we can create blinds that will follow light using light sensors and a simple
program in C++ that will compare the inputs, after the comparison is made, and the output will
be sent to our motor to change the position of the blinds. When there is no sunlight outside to let
in, the blinds will simply close up to retain the heat that is in your home already. This system
will not only be convenient to the average homeowner, but it will also save you money on
electricity bill.

Conclusion

If you would like to save possibly hundreds of dollars on your electricity bill over the next few
years, automatic blinds are the answer for you! With our unique power saving techniques of
blind management, we will save you both time and energy.

INTRODUCTION/ FEASABILITY

These electronic blinds are the future of the world as we know it. No longer will we be required
to maintain our own household blinds to gain optimal lightning and contain the heat stored in our
homes. The natural heating provided by the sun will be sufficient to allow the owner to use less
natural gas and/or electricity to heat their home. The homeowners will also benefit from the
optimal lightning procedures of the system to enable the users to be able to worry less about
using indoor lights. This also can be used on focusing solar cells toward the sun.

The process is simple; we take in light from four strategic locations and compare their values to
locate the position of the sun.
2

There are four light sensors located at different angles.


Figure 1: Light Sensors

Light sensors

Divider

If the sun shines to the left, the left sensor will receive the most amount of light.
Figure 2: Left Sensor
3

If the sun shines in the center, the two center sensors will receive the most amount of light.
Figure 3: Center Sensors

If the sun shines more to the right, the most right will get most of the sunlight.
Figure 4: Right Sensor
4

Whichever location brings in the most light can be considered the location of where the sun is
most closely located at. The motor will turn the blind using the corresponding steps to the
position with the most light. The whole process of taking and comparing the values from the four
sensors repeat over again; closing if there is no longer enough light to bring in.

Figure 5: Blinds

blinds
sensor

Stepper motor
5

MATERIALS AND EQUIPMENTS

The materials used in the automated blind are listed in Table 1.

Table 1: List of Materials

Quantity Part Num. Description Cost


4 Green LEDs $0.40
1 Stepping motor $17.95
Analog-to-digital
4 ADC0804 converter $7.96
1 MM74HC138 3-to-8 line decoder $0.17
5 103 Ceramic capacitor $0.17
1 Blind $15.63
Wires
6 General diodes
1 Triple power supply
1 ULN2003 Current driver $0.69
Resistors $0.01
2 Banana-to-banana cord
Total expense $42.98*

*Price does not include power supply, general diodes and wires.

Basic information of ADC

The ADC (Analog-to-Digital Converter) converts a single analog signal into a digital signal
based upon the percentage of a reference voltage that the output is. Thus we can take the input
voltage, divide it by the reference voltage and multiply it by 256 (eight outputs) to receive the
digital output in increments of 1/256.

Figure 6: ADC Pinout

Source: Alldatasheet.com
6

Four ADC sensors were used to take in the varying sunlight values based upon their locations.
One ADC sensor is located at 22.50; one at 67.50; one at 112.50; and one at 157.50. Only one
ADC is actively sending the data to our microprocessor at a time. A decoder is used to activate
the desired ADC chip. This output is taken into a microprocessor which then compares the value
with the other ADC outputs.

Basic information of reversed-bias LED

When a normal Light Emitting Diode is set in reversed bias it will act as a phototransistor.
Whenever light is focused upon the LED, the current will flow freely through the diode at
different voltages based upon the amount of light the LED is absorbing. The more light focused
upon the LED, the more voltage the LED will let pass freely through it. This gives us a point of
reference and comparison. Reversed-bias LEDs are used as phototransistor in the automated
blind. When a LED is reversed-bias, the depletion zone widens. When the atoms inside the LED
absorb the light, the energy band inside the atom raises. But instead of releasing the energy
through light, like it usually does, it releases electrons.

Basic information of 3-to-8 line decoder

A 3-to-8 line decoder takes in three inputs to select one of eight outputs. The three inputs are
binary values (0 and 1) which would result in a value from 0 through 7 which then selects the
corresponding output (output 0 – output 7) to be set at a low state. The outputs of the decoder
are active-low. The outputs of the decoder can then be used to enable the chips connected to
them.

The decoder was used in this project to select one of four ADC to send their digital outputs to the
microprocessor. To do this, the decoder is sent a binary value that signifies the desired ADC
chip. Then the decoder will send a low state to the ADC’s chip select pin. The ADC chip select
pin is active-low.

Figure 7: 3-to-8 Decoder Pinout (MM74HC138M)

Source: Alldatasheet.com
7

Table 2: Truth table. This table shows the value of the inputs of the decoder that select the corresponding ADC
chip.
S0 S1 S2 Y0(ADC1) Y1(ADC2) Y2(ADC3) Y3(ADC4)
0 0 0 0 1 1 1
0 0 1 1 0 1 1
0 1 0 1 1 0 1
0 1 1 1 1 1 0

Basic information of stepping motor

The stepping motor is a four-phase stepper motor. This means that the stepper motor has four
stator windings with a center-tapped common. This common allows the motor to change the
current direction within each of the two coils which changes the polarity of the stator.

The stepper motor used is a 4.7 V motor with 1.5° angle step. To determine the required number
of steps to turn the rotor to a desired position, the following formula was used:
Steps = Desired Angle / Angle step (Specified by the motor).

This stepper motor has a four step sequence as displayed below.

Figure 8: Stepper Motor Sequence

Clockwise Step # Winding A Winding B Winding C Winding D Dec # Counter-clockwise


1 1 0 0 1 9
2 1 1 0 0 C
3 0 1 1 0 6
4 0 0 1 1 3

Basic information of ULN2003

The ULN2003 is the stepper motor’s driver. It takes in the datas from Port B. The ULN2003
inverses the inputs. After that, each bit is sent to its own Darlington pair, where the voltage is
stepped up to the voltage desired to run the stepper motor.
Figure 9: ULN2003 Pin out

Source: Alldatasheet.com
8

PROGRAMMING AND INTERFACING APPROACH

Flowchart

Initialized char stepper = 0x33H


Initialized ADC

Initialized blind to position 1

Read values from LEDs

Set greater = sensor_1


Set Position = 1

Greater < sensor_2

True

Set greater = sensor_2


Set new_position = 2 False

Greater < sensor_3

True

Set greater = sensor_3


Set new_position = 3 False

Greater < sensor_4 False

Set greater = sensor_4


True Difference = position – new_position
Set new_position = 3
9

Switch( difference)

0 1, -1 2, -2 3, -3 Default

Print “position 1” Print “position 2” Print “position 3” Print “position 4” Print “position 4”
Steps = 120 Steps = 241 Steps = 482 Steps = 723 Steps = 723

Position = new_position

Do while loop

While(steps !=0 &&


difference <=0)

True

Send stepper value to Port B


Rotate value to right once

False
Steps = steps - 1

While(steps !=0 &&


difference >=0)

True False
10

Send stepper value to Port B


Rotate value to the left once

Steps = steps - 1

False

True
Do while loop While keyboard is not
pressed

False

Difference = positon - 1

Switch( difference)

0 1, -1 2, -2 3, -3 Default

Steps = 120 Steps = 361 Steps = 600 Steps = 860 Steps = 0

While steps != 0

True False
While loop

Send stepper value to Port B


11

Rotate stepper value to the light


once

While loop

Steps = steps - 1
False

End propram
12

Hardware

Figure 10: ADC connection to decoder. Figure 11 shows how the 3-to-8 decoder is connected to each
ADC chip select and Port C.

PORT A
Data

__ 20
CS CLK R
__ 1 Vcc1 19
330 ohm
RD DB0
___ 2 18
WR DB1
3 17
CLK IN DB2
____ 4 16
INTR DB3
10nF 5 ADC0804 15
Vin(+) DB4
6 14
Vin(-) DB5
7 13
5V GND DB6
8 12
Vref/2 DB7 (MSB)
9 GND 11
0.47 uF 10

__ 20
CS CLK R
__ 1 Vcc1 19 330 ohm
RD DB0
___ 2 18
WR DB1
3 17
PORT C CLK IN DB2
____ 4 16
INTR DB3
5 ADC0804 15
10 nF Vin(+) DB4
6 14
Out6
S1 Vcc Vin(-) DB5
1 9 16 7 13
S2 Out0 GND DB6
2 15 8 12
S3 MM74HCT138 Out1 5V Vref/2 DB7 (MSB)
3 14 9 GND 11
___ 0.47 uF
G2A Out2 10
___ 4 13
G2B Out3
5 12
012 G1
6 11
Out4

Out7 Out5
7 GND 10
8 0 1 2 3 4 5 6 7

__ 20
CS CLK R
__ 1 Vcc1 19
330 ohm
RD DB0
___ 2 18
WR DB1
3 17
CLK IN DB2
____ 4 16
10 nF INTR DB3
5 ADC0804 15
Vin(+) DB4
6 14
5V Vin(-) DB5
7 13
GND DB6
8 12
Vref/2 DB7 (MSB)
0.47 uF 9 GND 11

10

__ 20
CS CLK R
__ 1 Vcc1 19
330 ohm
RD DB0
___ 2 18
WR DB1
3 17
CLK IN DB2
____ 4 16
INTR DB3
10 nF 5 15
Vin(+) DB4
6 14
Vin(-) DB5
5V 7 13
GND DB6
8 12
Vref/2 DB7 (MSB)
9 GND 11
0.47 uF
10
13

It shows how Port B is connected to the inputs


Figure 11: ULN2003 connection to the stepper motor.
of the ULN2003. The ULN2003 is connected to the stepper motor.

Figure 12: Circuit


14

SOFTWARE CODE

#include <windows.h> // header for Sleep


#include <iostream.h>
#include <iomanip.h>
#include <conio.h>
#include "mdedriverdll.h"

This portion links the necessary header files to our project.

void main()
{
int iwork;
unsigned char sensor_1 = 0, sensor_2 = 0, sensor_3 = 0, sensor_4 = 0,
greater = 0;
int position = 1, new_position, difference, steps = 120;
unsigned char stepper = 0x33;

This portion enters the main then initializes all the variables used in our
program.

iwork = MDEOpenLPTPort(0x378); // initialize driver


MDEConfigPort(0x378, 0x90);

cout << setiosflags(ios::unitbuf);

This Porstion initializes the ports.

// initialized ADC
MDEOutPC(0x378, 0x00); // send the value
cout << '1';
Sleep(6000); // delay

MDEOutPC(0x378, 0x01);
cout << '2';
Sleep(6000);
// send the value
MDEOutPC(0x378, 0x02); // send the value
cout << '3';
Sleep(6000);

MDEOutPC(0x378, 0x03); // send the value


cout << '4';
Sleep(6000); // delay
15

// clear screen
system ("cls");

This portion initializes the ADC and clears the screen afterwards.

// initialized blind to position 1- 22.5 degree


MDEOutPB(0x378, 0xff);

MDEOutPB(0x378,stepper);
Sleep(10);
MDEOutPB(0x378,0x00);
Sleep(10);

while(steps !=0){
MDEOutPB(0x378,stepper);
Sleep(10);
MDEOutPB(0x378,0x00);
Sleep(10);

_asm{
mov al, stepper
ROR al,1
mov stepper,al

steps = steps - 1;
}

This portion initializes the blinds to position 1(or 22.5 degree). One of the
stepper motor values 33(in hex) is sent to port B. Then we rotated the value
and it became 99(in hex).

do
{

//cout << '1';


MDEOutPC(0x378, 0x00); // send the value
Sleep(50);
sensor_1 = MDEInPA(0x378);
Sleep(50); // delay

// cout << '2';


MDEOutPC(0x378, 0x01);
Sleep(50);
sensor_2 = MDEInPA(0x378);
Sleep(100);

// cout << '3'; // send the value


MDEOutPC(0x378, 0x02); // send the value
Sleep(50);
sensor_3 = MDEInPA(0x378);
16

Sleep(50);

// cout << '4';


MDEOutPC(0x378, 0x03); // send the value
Sleep(50);
sensor_4 = MDEInPA(0x378);
Sleep( 50); // delay

This portion takes in the data from the ADC converters.

greater = sensor_1;
new_position = 1;

if(greater < sensor_2){


greater = sensor_2;
new_position = 2;
}

else if(greater < sensor_3){


greater = sensor_3;
new_position = 3;
}

else if(greater < sensor_4){


greater = sensor_4;
new_position = 4;
}
//cout << "Enter value ";
//cin >> new_position;

This portion checks what position the stepper motor should be in.

difference = position - new_position;

switch( difference){
case 0:
cout << "position 1\n";
break;
case 1:
case -1:
steps = 241;
cout << "position 2\n";
break;
case 2:
case -2:
steps = 482;
cout << "position 3\n";
break;
17

case 3:
case -3:
steps = 723;
cout << "position 4\n";
break;

default:
steps = 0;
break;

} //end switch

This portion assigns the actual value of steps the stepper motor should
receive.

position = new_position;

while(steps !=0 && difference <= 0){

MDEOutPB(0x378,stepper);
Sleep(10);
MDEOutPB(0x378,0x00);
Sleep(10);

_asm{
mov al, stepper
ROR al,1
mov stepper,al

} //end asm

steps = steps - 1;
} //end while

while(steps !=0 && difference >= 0){

MDEOutPB(0x378,stepper);
Sleep(10);
MDEOutPB(0x378,0x00);
Sleep(10);
_asm{
mov al, stepper
ROL al,1
mov stepper,al

} //end asm

steps = steps - 1;

This portion moves the stepper motor to the right location.


18

} //end while
} while (!kbhit()); //end while (!kbhit())

// closed blind completely


difference = position - 1;

switch( difference){
case 0:
steps = 120;
break;
case 1:
case -1:
steps = 361;
break;
case 2:
case -2:
steps = 600;
break;
case 3:
case -3:
steps = 860;
break;

default:
steps = 0;
break;
} //end switch

while( steps != 0){


MDEOutPB(0x378,stepper);
Sleep(10);
MDEOutPB(0x378,0x00);
Sleep(10);

_asm{
mov al, stepper
ROL al,1
mov stepper,al

}
steps = steps - 1;

This portion moves the motor to the closed position(0 degrees) when the
keyboard is hit.

} //end while

MDECloseDriver(); // close the driver


}

This portions closes the port and ends the program.


19

RESULTS

The results we got were as proposed. The lights sensors would send the value through the ADC
to the microprocessor. The Microprocessor would then interpret these values and determine
which sensor is absorbing the most light. The microprocessor would then send determine the
amount of steps required to reach the desired point. Then the microprocessor would output the
values to the ULN2003 which would then output to the stepper motor. This process would then
enable the blinds to move to the desired position and repeat the process above.

The initial proposal as initially proposed, except we decided to replace the photodiodes with a
reversed bias LED, which in fact was more sensitive compared to the other photodiodes that we
obtained.

CONCLUSION

From this project we learned many important and pertinent facts concerning electronic devices
and microprocessor. This experience helped strengthen our knowledge of the curriculum covered
in this course. We, the group, will now be able to walk away with a strong knowledge in the
design of electronic circuits using microprocessors and interfacing various devices. Among
those devices includes the use of a strong stepper motor.
20

Work Cited

“ADC0804 : 8-Bit, Microprocessor- Compatible, A/D Converters.” Intersil Corporation. 1999.


http://pdf1.alldatasheet.com/datasheet-pdf/view/66283/INTERSIL/ADC0804.html.

“ULN2003 : SEVEN DARLINGTON.” STMICROELECTRONICS. 2002.


http://pdf1.alldatasheet.com/datasheet-
pdf/view/25575/STMICROELECTRONICS/ULN2003.html.

“MM74HCT138N : 3-to-8 Line Decoder.” Fairchild Semiconductor Coporation. 1999.


http://pdf1.alldatasheet.com/datasheet-pdf/view/53791/FAIRCHILD/MM74HCT138N.html
21

APPENDIX