Download Project 1 – Problem 1

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Nanogenerator wikipedia , lookup

Night vision device wikipedia , lookup

Ohm's law wikipedia , lookup

Rectiverter wikipedia , lookup

Immunity-aware programming wikipedia , lookup

Resistive opto-isolator wikipedia , lookup

Charlieplexing wikipedia , lookup

Opto-isolator wikipedia , lookup

Transcript
Abstract
The purpose of this product is to create an extremely energy efficient ceiling
light/fan. This is accomplished using modern microcontroller implementation and a
variety of sensors and actuators. The main aspect of the device is its ability to operate,
without any human intervention, put itself in a mode that is most economical: no wastage.
Introduction
In recent times, energy has become quite an issue, and ways in which to save
energy are becoming very important in all new devices created. Perhaps it’s the fact that
it is rare to find any home without high power devices, or simply that oil prices are on the
rise. No matter what the reason is, the necessity for everything to be energy efficient has
become extremely important. One thing that has been kept, for the most part, manual
over the years is lighting, except for the automatic on/off incorporated into many new
systems. When tied into a ceiling fan fixture, it becomes very practical to make this hot
item more economically feasible. There are two main ideas that are used to accomplish
the task at hand in this product. The first deals with adjusting the light level based on the
current lighting condition. The second deals with adjusting the fan speed based on the
temperature. By realizing that people can end up staying in a room all day and do not
always remember or care to adjust the lighting or fan speed, it was determined that this
can save energy and therefore money for consumers. Since in the day there is often
enough light outside and at night it is not that hot, adjustments can be made without
making the customer uncomfortable. Of course there are a number of other features such
as automatic on/off based on occupancy, fire sensing and alerting ability and safe
protection.
Implementation
The prototype of this device was made by using a Basic Stamp as a brain to
control the fixture by means of the PBasic programming language. Branching out from
the brain there are a number of secondary circuits to control a variety of functions. For
the light, a DS1804 digital potentiometer is used in conjunction with an amplifying
circuit as well as a relay for the on/off function. For the fan a DS 1804 is used to control
the pulse rate of a 555 timer which powers the fan through a MOSFET. For sensing
purposes a DS1620 is used for temperature sensing and a photo resistor/ capacitor pair for
light level sensing. To determine the occupancy of people, two infrared phototransistors
and a single infrared LED is employed to determine direction of movement.
Hardware Specifications
The hardware for this product is pretty complicated in the fact that there are a lot
of complex aspects that have to be considered. However, by using the microcontroller,
this is not too much of an issue. The schematic for the circuitry is displayed in the
appendix (3).
Light Sensor – The light sensor consists of a photo resistor and capacitor pair. As the
resistance value changes, the time constant (RxC) value changes. The capacitor value
used is .05 micro Farads in series with the photo resistor. The bridge between the two is
connected thorough a current limiting 470 ohm resistor to pin 11 of the Basic stamp. The
other end of the photo resistor is connected to ground, while the other end of the
capacitor is connected to positive 5 volts.
Occupancy Detection – The occupancy detection circuit incorporates two infrared
phototransistors and a single infrared Light Emitting Diode. Both of the phototransistors
are connected in the same fashion. Positive 5 volts connects to the collector, while the
emitter is connected to ground through a 10 k Ohm resistor. The bridge of the resistor
and emitter are connected through a 470 ohm current limiting resistor to the Basic Stamp
(pin 14 and pin 15). The IR LED is simply connected through a 100 ohm resistor to 5
volts and ground, pointed at the two phototransistors. With this configuration, a blockage
of the phototransistor means a low to the basic stamp.
Light Control – The light control mechanism is created using a digital potentiometer, a
transistor and a relay with a transistor and diode attached. The digital potentiometer
(DS1804) is the part that does the analog control of the light. It is connected in a voltage
divider circuit with a 1 Mega Ohm resistor, as well as a 4.7 k ohm resistor connected in
parallel. This supplies a variable voltage to the base of a JFET that has its collector at 5
volts and its emitter connected in series through the relay to drive the light. The relay
(with a current spike protecting diode connected in parallel) is turned on and off by a BJT
that has a base voltage (0V or 5V) given by pin 5 of the basic stamp. The increment and
Up/Down inputs are given by pins 10 and 9 on the Basic Stamp respectively. As for the
reset, it is done using a selector circuit (explained later) so that the number of pins used
can be optimized. Pin 8 on the DS1804 is connected to 5 volts. Pin 4 is connected to
ground. Pin 5 is connected to the other resistor to make the divider circuit.
Temperature Sensor – The temperature sensor simply uses the DS1620 temperature
transducer to change the current temperature to a series of voltage pulses corresponding
to the number value of the temperature. Pin 8 of this is connected to both positive 5 volts
and through a .1 micro Farad capacitor to ground. Pin 4 is connected directly to ground.
The data and clock pins (1 and 2) are connected to the Basic Stamp pins 8 and 7
respectively. The reset pin, pin 3 is connected to the Basic Stamp via the selector circuit.
Fan Control – The fan control is accomplished by utilizing a 555 timer, DC1804
(potentiometer) and a MOSFET. Here, the main analog control is accomplished by using
the digital potentiometer; this is connected as a resistor for the 555 timer. Pin 6 of the
DS1804 is connected through a 15 k ohm resistor to pin 7 of the 555, which is shorted to
pin 2. Pin 5 and pin 8 on the pot are both connected to positive 5 volts. Pin 4 is
connected to ground and pin 7 to the selector circuit. The increment and Up/Down pins
(1 and 2) are connected to pins 10 and 9 respectively on the Basic Stamp. The 555 timer
has its pin 1 grounded and its pin 8 at positive 5 volts. Pin 2 and pin 6 are connected by a
short together while also being connected through a .01 micro Farad capacitor to ground.
The reset (pin 4 is connected to the Basic Stamp via pin 6 on the BS2. The output of the
555 (pin 3) is connected through a 1 k ohm resistor to the gate of the MOSFET. The
source is connected to ground, while the drain is connected to the motor that is connected
to positive 12 volts on the other end. And of course, there is a diode in parallel with the
motor to prevent any inductive kickback.
Selector Circuit – The selector circuit is a way that was used in order to save pins on the
microcontroller. This became an important aspect of making the system efficient, it was
quickly determined that the only way to add some more features was to decrease the
amount of pins used. By making either a high or low from a single B.S. pin (pin 4),
different IC’s can be made to listen or ignore: very useful. This was done by using two
inverter circuits connected together (in our case actual NAND circuits with all inputs
bridged together). First, the signal from the BS2 was inverted; this goes to the fan circuit
digital pot. Then, this signal was inverted again, basically a buffer, this was fed to the
light circuit digital pot. and to the temperature transducer reset pin. Therefore, a high at
pin 4 of the basic stamp would enable the digital potentiometer controlling the light,
while a low at pin 4 would enable the digital potentiometer controlling the fan and the
temperature sensor(DS 1620).
User input – The user input is given by two buttons. One is for the light control and one
is for the fan control. With each, there are three levels for automatic control and two for
manual control. Each button is configured in normally open and active low mode (best
for least errors): a press at the button gives a low to the corresponding pin of the Basic
Stamp. One end of the button is connected to ground, while the other end is connected to
positive 5 volts through a 1 k ohm resistor and also to pins 12 and 13 on the Basic Stamp
through a 470 ohm current limiting resistor.
Fire detection and alarming - This circuitry is utilizing the existing temperature sensing
circuitry and an additional circuitry composed of a piezoelectric buzzer. Pin 3 of the basic
stamp is used and connected to the positive end of the buzzer. The negative end of the
buzzer was connected to the ground.
Electrocution protection – The safety protection feature is realized by implementing a
capacitance proximity sensor. The circuit is basically a RC circuit which connects to an
input pin on the basic stamp. The resistor selected has a value of 10 MΩ. The capacitor is
constructed such that one plate is made of a sheet of aluminum attached to the ceiling
where the fan/light device is, and another plate is human being who tries to touch the
light or fan.
Hardware Functionality
This system was designed so that it would function mainly by using a
microcontroller, which was intensively programmed. However the systems controlled
and the sensors used represent a major part of the system and are hardware, so the
functionality of these aspects are discussed here.
The light sensing circuitry controls the hardware that creates the optimum light
output level. As light values are sampled from the outside world, the values obtained are
compared to the value of light desired, and more or less current is allowed to flow
through the approximately 13 ohm light bulb by changing the value of the digital
potentiometer. The relay is turned on and off depending on the condition of occupancy
and manual override. If the button is pressed to be put in the 5th mode, the relay is
deactivated and the light is turned off. Also, if the occupancy detector says nobody is
inside the room, the relay is again deactivated. By using two phototransistors, the
direction of movement can be determined, and thus a counter can be established to
determine if there are people in the room. There are five user input modes. The first
three set three different light level conditions to be kept constant by the system. The 4th
is an override that makes the light stay at full power no matter what the current light level
in the room and the 5th turns off the light.
The temperature sensing circuitry controls the hardware that maintains the
optimum fan speed level. The fan speed is controlled using pulse width modulation. By
obtaining the current temperature value in the room and comparing it to how the fan
should react to different temperatures, based on the user input, the fan speed is increased
or decreased by means of changing the pulse duration by altering the digital
potentiometer value. By turning off the 555 timer (deactivating the reset pin), the fan can
be turned completely off. This is done if there is nobody in the room, the user manually
turns it off by the button or there is a fire [turning the fan off if there is a fire to prevent
spreading by those means (Prof. Kapila)]. The fan has 5 levels chosen by the button.
The first sets a range for the fan to be full blast at a lower temperature, the second at a
higher temperature and the third at an even higher temperature. The speed is controlled
based on the temperature depending on the mode it is in. The 4th level simply puts the
fan into its high state, while the 5th turns it off.
The selector circuit is made so that when one circuit is operational, the other is
ignoring the input it is getting from the data pins.
The fire detection and alarming circuit is configured that when there is a fire, the
light will start blinking and the buzzer will start making high pitched noise. The
temperature sensing circuitry is constantly checking the temperature. When the
temperature measured is higher than the alarming temperature predefined by the
programmer, the light circuit and the buzzer circuit will be activated. A button is also
associated so that when it is pressed, the buzzer would stop producing sound and the light
would stop blinking. The system would then go into its original state, which constantly
waits for the entrance of people.
The safety protection feature of this device was designed to prevent human being
from being electrocuted. Whenever a person’s part of body is in a danger range which is
determined by the programmer, the power to the system will be disconnected by turning
off the 555 timer and the reed relay.
Software Specifications
The software for this system is an extremely important aspect; it is what allows
such a difficult task to be made simple without the need to use vast amounts of electronic
circuitry. The software used for the prototype is what came with the Basic Stamp, the
PBasic programming language. The program is not very advanced, but it does the job.
There are a number of special functions that were used for this task.
The Rctime command is one such function. It is a command that calculates the
amount of time a specified pin takes to change state. Basically, it calculates the time for
the pin to go from a logic low to a logic high state or vice versa. In the function, the pin,
end state and output variable must be given when using the command.
Another function that was used was the serial in/out command. This command
translates a stream of binary pulses into a numerical value. This is when it is used as
shiftin (gets an input of pulses). When used to output pulses (shiftout), it operates in the
opposite manner. The values that must be given to the command are the in/out pin to be
used, the clock pin, in what order the pulses will be sent and the variable or value to be
sent or received.
Another function used is the For Loop. This function simply repeats a specified
task, what is in the loop, over and over for a specified amount of times. The values that
are given to the function are the start and stop count for the number of cycles to run.
Although these are a few of the more advanced functions utilized, there are a
number of simple functions that were used that if not there would make it quite
impossible to accomplish the task at hand. On top of this, an important thing that is
worth mentioning is the effort that was put into making the program shorter and run
faster and more efficiently. It might sometimes seem as if a lot was done in certain
places, however it is determined that these actions are necessary to make the system work
to its best capability. Often, it is necessary to determine the best size for each variable
declared; saving space while still keeping efficiency was a key.
Software Functionality
Since it is the brains of the entire operations, it is simple to realize that a lot of
time went into the design and implementation of the program. Problems were often
sought out and solutions found. Not to mention much had to be accounted for in order to
make the program operate fast enough so that the buttons and occupancy sensor would
instantly pick up any new activity. The program was split up into blocks in order to make
it easier to understand and therefore easier to improve upon it. The main program is
displayed in the appendix (1) and the secondary statistical program is also displayed there
(2).
Variable Declaration – Here all the variables were declared. The majority of these were
given names so that the value they store can be easily grasped. Also, the amount of space
that is allocated to each variable is important. If it is not necessary to use a word (16 bits),
then one should not be used. Often variables as small as a nibble, only four bits, were
used.
Light Automation – This is the part in which the subroutine to make the lighting system
smart was put into operation. What is done here is to first look at what level of lighting
the user has defined. Based on this, a certain light level (amount of light that is to be
present in the room) is obtained. This value is then compared with that of the current
light level in the room, received through the RCtime function from the light sensing
circuit. Depending on if the current light level is too bright or to dim, within a range, the
output light will be adjusted to reach that light level specified by utilizing a for loop to
control the digital pot connected to the light circuit. This subroutine is within a main
loop and therefore is continuously active.
Fan Automation – This part of the program is what automates the fan control and makes
it operate as a smart system. The entire algorithm depends on what temperature range the
current condition is in. After this is determined, based on the temperature, obtained by
the DS1620 while using the shiftin and shiftout commands, a value to change the fan
speed to is obtained. Using a comparison of the previous value to this new value based
on the range of the digital potentiometer, the speed of the motor is altered using a For
Loop to increment or decrement the resistance level of the DS1804. In this subroutine,
much effort is taken in order to minimize the use of redundant operations, such as going
through loops that are not necessary. The usefulness of past values should be quite
evident in this block.
Light Controlling Button – In this block the way in which the user is to gain control over
the system and give his/her input into the system is displayed. Simply seeing a button
press, forces the program to wait for the user to let go over the button in which case the
mode of the lighting condition is increased by one. It was debated of whether using some
sort of button debouncing algorithm was necessary. However, with the fact that without
any such algorithm the program ran fine, it became evident that it would be unnecessary
and foolish to use. Perhaps it deals with the fact that the tact switches used are of good
quality, or that the PBasic programming language is not fast enough to see the bounce
anyway. No matter what the reason might be, no errors were attributed to button bounce
and therefore there was no reason to deal with it. Once the lighting mode is changed, the
level variable must be changed appropriately and anything else that is to be done must be
done. This new value is used to control the light value when it comes back around in the
loop.
Fan Control – This is the part of the program that allows the user to control the range in
which the fan operates. It also sets the new values that are also based on temperature for
the fan speed to seek out. First, of course the button must be pressed and released. Once
this happens, the program changes the mode of the fan, which in turn alters the speed at
which the fan rotates. Since this value also depends on the temperature, in an attempt to
conserve lines of code, the program is made to run through this subroutine regardless of
whether the button is pressed or not. The only difference is that if it is not pressed, the
mode is not changed.
Occupancy Detection – The occupancy detection is done with the utilization of a
sophisticated algorithm that determines the direction of motion of a person. A counter is
made to keep track of the number of people in the room. Using a plethora of loops, it can
be made to work beautifully. First, the sensor sees which phototransistor is blocked first,
then waits until it is unblocked. After that, it waits until the next phototransistor is
blocked and then unblocked. This gives direction with a low occurrence of error.
Storing this in a counter and realizing when all people have left or somebody has entered
enables the program to act accordingly. An entrance by a person into the unoccupied
room causes the light to go on to a default middle state as well as initializing all variables
because the beginning of the adventure has just begun. Leaving the room forces
everything to turn off, thus saving energy. After this, the waiting procedure starts
looping again and waiting for any activity to occur.
Fire detection and alarming – As described above, the temperature sensing procedure is
constantly running no matter if there is any person in the room. When the conditional
statement which is used to compare the current temperature with the predefined
dangerous temperature is true, fire alarming routine will be activated. The routine
includes the constant blinking of the light, which is realized by altering the level of
resistance in the digital potentiometer inside a for loop; the creation of high pitch noise
by the buzzer, which is implemented by setting the pin controlling it to high, and the
alarm override procedure which continuously checks if the overriding button is pressed.
If the button is pressed, program will jump out of the loop and resume normal operation.
Otherwise, the alarming features will keep in effect.
Safety protection – Whether the distance between the human body and the light/fan
system is considered safe or dangerous depends on the RCtime value obtained. Each
value is compared to the predefined value acquired under the condition prone to
electrocution. If the current RCtime value is smaller or equal to the predefined value, the
program will branch to a place where 555 timer and reed relay are turn off.
Statistical Temperature Data – Another feature that has been installed is one in which a
number of samples of the temperature are taken. This data can be used for manipulation
and to show the trend of temperatures over time. It was chosen not to make the main
program more complicated by allowing the user to read the data, so this function is
displayed in a separate piece of code. The data is however read in the main program,
there is just no way to retrieve it, this is what the second program is for. The second
program just obtains a set of temperature values over a period of time. When the user
presses the predefined button, the average is displayed on the screen.
Analysis
In the prototype, all components were selected based on their necessities,
functionalities, compatibility, and cost efficiency. As for the Occupancy detection, the
main reason for the IR detector/emitter was chosen mainly because of cost. The job,
detection of occupancy, is easily accomplished with reasonable results using IR
detectors/emitters. Infrared was chosen as it would not be seen and interference would
not be as common as would be from a visible light circuit. The digital potentiometers
were used due to its ease of implementation, as well as its low cost and no need for
complex circuitry. For the light it was used to control the voltage into the base of a JFET
transistor. The JFET was chosen because since no current is drawn there does not have
to be any calculations of voltage drops into the light. At first a BJT was used, but the
results were not that good. As for the relay, a reed relay was used, because of the limited
current through it, cheapness and longevity of life due to lacking of may mechanical parts.
As for the motor, PWM was used. This saves energy and allows the motor to always
operate in its ideal mode. To do this a 555 timer was used, as to not tie up the functions
of the Basic Stamp and a Power MOSFET was used because it draws no current and can
handle quite a bit of current. As for the light sensing circuit, it might be wondered why a
photo resistor is used in stead of the quicker photo diode. The main reason for this is
price, photo resistors are significantly cheaper. Also, since the point of the product is not
to deal with fast changing ambient levels, the necessity of a very fast quick circuit is not
necessary.
Mathematical Analysis
Mathematically, the circuit might seem very complex. However, since many
integrated circuits are used, an in depth analysis of these was not necessary and therefore
is not done. The main thing that had to be taken into account though was the amount of
current drawn or sunk by each pin and all pins in total. For each button, the maximum
current that will be sunk through the Basic Stamp is 2.5 mA. This was determined using
Ohms Law, V=IR. Here I = V/R = 5 / 2000. For light meter the maximum current that is
output or input to or from the Basic Stamp is 11 mA. This is again determined by Ohms
Law, I = 5 / 470. The only other place where a significant amount of current leaves or
enters the Basic Stamp is the Infrared photo transistors (occupancy detection). Here the
maximum current that can be sunk is 5 Volts / 1 k Ohms = 5 mA. All of these values are
well within the Basic Stamps ability to handle current. 20 mA for a single pin and 40 mA
for a group of 8 pins. The rest of the circuit elements either do not connect to the Basic
Stamp directly or are IC’s (these draw very little current from the pins connected to the
Basic Stamp). Of course resistors were added in places to make sure that current does
not go to high, however it was not done so stringently.
The power consumed by the prototype was determined by using the formula
Power = Voltage * Current. The power consumed by just the Basic Stamp and circuit,
the light and fan are off, is (80 * 10^ -3) Amps * 5 Volts = .4 Watts. With the light on a
low condition, this goes to (223.4 * 10^-3) Amps * 5 Volts = 1.1 Watts. With the light
on a high condition, the power becomes (293.9 * 10^-3) Amps * 5 Volts = 1.5 Watts.
The Fan is what takes the most power and its readings are as follows. With the fan on a
low condition, .36 Amps are used making the Power = .36 Amps* 12 Volts = 4.32 Watts.
With the power on a high condition this becomes .56 Amps * 12 Volts = 6.72 Watts. So,
it can be concluded that when the prototype has everything on, 6.72 Watts + 1.5 Watts =
8.22 Watts is used. This is not that much for a prototype and most of it is from the fan
and some from the light. The circuitry barely uses any Power.
Results
The Prototype works as designed to and it works quite well. Everything that is
supposed to happen happens. When someone enters the room, the light turns on. The
light and fan operate as instructed to by the buttons. The light and fan also operate
automatically as they are supposed to. As the temperature increases the fan speed
increases and as the external light increases, the light output from the light decreases. In
addition, when there is a fire in the room (intense heat) the fan turns off and the light
blinks along with a buzzer ringing. The approximate price list for the prototype is as
follows. Keep in mind that some items were on hand, such as power supplies, and
therefore are not on the list.
Basic Stamp with Board of Education kit
($100)
DC Fan
($20)
Light
DS1804, Digital Potentiometer
($1)
($2 X 2)
555 Timer
($2)
DC1620 Temperature Sensor
($2)
Power MOSFET
($2)
Reed Relay
($1)
Infrared LED
Infrared Phototransistor
Photoresistor
($2)
($1X2)
($1)
BJT and JFET
($2)
Other Components
($5)
-------------------------------------------------------------------------------------------------Total Cost
( $144)
Actual Product
The actual product will have all the features of the prototype, but will be put
together in a nice package that is very aesthetically appealing. The final product will not
cost much more than ceiling fan/lights currently on the market today. The price for a
good ceiling fan/light is approximately $175. We have come to the conclusion that our
product will cost the consumer around $200. This will be done by using a PIC
microcontroller directly and buying electronics in bulk. This will lower the price and
make the fan very affordable. Although, the product will cost a little more, in the long
run much money will be saved and it will most certainly be worth it; that is the scheme
for which we plan to advertise for the sale of our product. This product is extremely
marketable because it can be used by the average consumer, as well as big corporations;
everybody wishes to save money and uses light. This product can be used in all climates.
Obviously, the lighting feature can be used by anyone no matter where they might be
located. It might be argued that in a hotter climate where air conditioning is prevalent, a
fan might not be necessary. This, however is not always the case because some people
like a breeze no matter what and even some might not always want to use A/C. With
these conclusions and the fact that the finished product will have many user defined
levels, this smart ceiling fan/light combination will have a use and a market everwhere.
Conclusion
Since energy is a major issue in the present day, it was determined that
making a often used product more energy efficient would be very promising. The
product chosen was a simple ceiling fan/light combination that has found its way into
many homes. Using the simple yet modern concept of mechatronics and microcontroller
incorporation, this was easily accomplished. Many ideas for saving energy and adding
safety to the system were taken into account. Such ideas as the auto turn off occupancy
detection and electrocution protection were installed. For the prototype, this was all
housed in an open box made out of plastic, painted and shaped to mimic a room; however
it is not to scale. The prototype shows that the concept defiantly works. The only
problems with the prototype is the fact that the sensor tends to be right under the light
(the room is to small) and there are some loose wires in places and the fact that some
components come loose every once in a while. The wire and component problem deals
with the fact that this is only a prototype and not hardwired, for the actual product things
would be soldered together in a more permanent fashion. This product just touches the
surface of incorporating microcontrollers into the home. Using the idea of making
average household devices energy efficient, there are many things out there to be
improved upon.
Appendix
(1)
'{$STAMP BS2}
'Variable declaration and initilization (outside the main loop)
'****************************************************************************************
********************
light var word
x var byte
temp var byte
sensor
fromIC var byte
sensor
set var word
set_prev var word
counter_l var nib
pressed
counter_f var nib
pressed
level var word
temp_h var byte
temp_l var byte
counter var byte
ent_er var byte
lea_er var byte
big_count var word
safety var byte
safety_counter var byte
'variable to store values from RCTIME (photoresistor)
'a dummy variable
'variable to store modified values from the temperature
'variable to store unmodified values from the temperature
'current resistance level of the digital potentiometer
'previous resistance level of the digital potentiometer
'count the number of times the botton for the light is
'count the number of times the botton for the fan is
'level
'upper
'lower
'count
of light intensity the light is trying to reach
boundary of the temperature setting
boundary of the temperature setting
the number of people in the room
alarm_override var bit
log var byte(4)
ptr var nib
for ptr = 0 to 3
log(ptr) = 0
next
'initialize temp statistical variable
ptr=0
alarm_override = 0
counter=0
counter_f=5
set = 11
‘initialize pointer variable for the statistics
‘make fire alarm override variable reset (alarm will sound)
output 4
output 10
output 9
output 5
output 7
output 8
output 6
input 14
input 15
input 12
input 0
'reset pin for DS 1804
'increment pin for DS 1804
'up/down pin for DS 1804
'pin to control the relay
'pin for the temperature sensor
'pin for the temperature sensor
'pin controlling the 555 timer
'the right infrared LED
'the left infrared LED
'botton controlling the light
'botton controlling the fan
high 4
low 6
low 9
for x=1 to 99
high 10
low 10
next
'turn on the DS 1804 controlling
'turn on the 555 timer
'initialize the DS 1804 to its lowest resistance
high 9
'initialize the resistance level for the fan at full blast
for x = 1 to 11
high 10
low 10
next
'****************************************************************************************
**
'Light Automation
'****************************************************************************************
***
flow_0:
after ‘
activates
low 2
‘rctime for electrocution sensor
pause 2
rctime 2,0,safety
debug ? safety
safety_counter=0
if safety>60 then flow_3
if counter>0 AND counter_l <> 5 then relay_engage ‘makes sure light turns on
‘electrocution sensor
continue3:
high 4
shiftout 8,7,lsbfirst,[238]
low 4
'initialize the temperature IC
high 4
shiftout 8,7,lsbfirst,[170]
shiftin 8,7,lsbpre,[fromIC]
low 4
temp =fromIC/2
'get ready to send data
'send data to basic stamp
debug ? temp
'DISPLAY
if alarm_override = 1 then keep_going
'if the manual alarm override is
if temp > 80 then flow_3
'go to fire alarming mode
activated
keep_going:
big_count = big_count + 1
‘counter for fire alarm override reset
and ‘
‘
‘statistical temperature data
storage
if big_count >= 500 then alarm_override_reset
stat_temp:
if big_count >= 500 then write_data
continue2:
debug ? counter, cr
debug ? level, cr
if counter=0 then flow_3
back to
'DISPLAY
'DISPLAY
'no one is in the room, skip fan and light automation, go
‘infrared
'obstruction detection
high 11
pause 5
low 4
rctime 11,1,light
debug ?light
'Discharge the capacitor at the beginning
'activates the DS1804 controlling the light
if counter_l = 4 then flow_1
'at mode 4(full light), therefore, skip light automation
if light<(level-20) then decrease
if light>(level+20) then increase
goto flow_1
decrease:
high 9
for x=1 to 3
high 10
low 10
next
goto flow_1
increase:
low 9
for x=1 to 3
high 10
low 10
next
goto flow_1
flow_1:
'****************************************************************************************
**
'Button controlling the fan
'****************************************************************************************
***
second:
if in0=0 then manual_adjust_2 'check for the button press
goto fan_adjustment
'if no button press is detected, do nothing to the fan
'but still keep checking the room temperature
manual_adjust_2:
if in0=0 then manual_adjust_2 'check for the release of the button to complete
a valid ‘button press
counter_f=counter_f+1
'counter value is the current mode
'Fan Adjustment
fan_adjustment:
set_prev=set
debug ?set_prev
debug ?counter_f, cr
high 4
shiftout 8,7,lsbfirst,[170]
shiftin 8,7,lsbpre,[fromIC]
low 4
'DISPLAY
'DISPLAY
'get ready to send data
'send data to basic stamp
temp =fromIC/2
debug ? temp, cr
if
if
if
if
if
if
counter_f=1
counter_f=2
counter_f=3
counter_f=4
counter_f=5
counter_f=6
then
then
then
then
then
then
slowest
faster
fast
set_is_ninenine
set_is_eleven
reset_f
reset_f:
counter_f=1
the first mode
goto slowest
'if the counter is more than 6, go to
slowest:
temp_h=35
temp_l=25
if temp<25 then set_is_eleven 'if the temp is greater than temp_h, just turn on
if temp>35 then set_is_ninenine
'the fan to full blast
set= (88*temp-2190)/10
debug ?temp_h
'DISPLAY
debug ?temp_l
'DISPLAY
debug ?set
'DISPLAY
goto flow_4
faster:
temp_h=30
temp_l=20
if temp<20 then set_is_eleven
if temp>30 then set_is_ninenine
temp_l, just turn off the fan
set= (88*temp-1750)/10
debug ?temp_h
'DISPLAY
debug ?temp_l
'DISPLAY
debug ?set
goto flow_4
'if the temp is less than
'DISPLAY
fast:
temp_h = 25
temp_l = 15
if temp<15 then set_is_eleven
if temp>25 then set_is_ninenine
set= (88*temp-1310)/10
debug ?temp_h
debug ?temp_l
debug ?set
goto flow_4
'DISPLAY
'DISPLAY
'DISPLAY
set_is_eleven:
low 6
set=11
goto flow_4
set_is_ninenine:
high 6
set=99
goto flow_4
'***********************************************************************************
'Fan Automation
'**********************************************************************************
flow_4:
high 4
'activate the DS1804 controlling the fan
adjust:
if
if
if
if
set = set_prev then flow_2 'no temperature change, do nothing
set = 11 then halt
set = 99 then full
set_prev<=set then raise_speed
high 6
low 9
for x= 1 to set_prev-set
high 10
low 10
next
goto flow_2
raise_speed:
high 6
high 9
for x=1 to set-set_prev
high 10
low 10
next
goto flow_2
full:
high 6
high 9
for x=1 to 99
high 10
low 10
next
goto flow_2
halt:
low 6
low 9
for x=1 to 99
high 10
low 10
next
for x = 1 to 11
high 10
low 10
next
goto flow_2
flow_2:
'****************************************************************************************
***
'Button to control the light
'****************************************************************************************
***
if in12=0 then manual_adjust
goto flow_3
manual_adjust:
if in12=0 then manual_adjust
counter_l=counter_l+1
debug ? counter_l
if
if
if
if
if
if
counter_l=1
counter_l=2
counter_l=3
counter_l=4
counter_l=5
counter_l=6
then
then
then
then
then
then
dimmest
brighter
brightest
stay_bright
off_l
reset_l
reset_l:
counter_l=1
goto dimmest
dimmest:
high 5
'turn on the relay
level = 35000
goto flow_3
brighter:
level=9000
goto flow_3
brightest:
level=5000
goto flow_3
stay_bright:
low 4
low 9
for x=1 to 99
high 10
low 10
next
goto flow_3
'leave the light on at full intensity
off_l:
low 5
'turn off the relay, therefore turn off
the light
goto flow_3
flow_3:
debug ? safety
'****************************************************************************************
******
'Infrared detection
'****************************************************************************************
******
debug ? big_count
if in14=0 then wait_1
'check for entry of a person
at the first receiver
goto go_on
wait_1:
debug ? in14
if in14=0 then wait_1
'wait until the person unblocks the
first receiver
ent_er=0
wait_2:
debug ? in14
ent_er=ent_er+1
'a time counter used in case the person is
standing in front
if ent_er > 50 then enter
'the second receiver and not leaving. when time
expires,
‘
‘just
'increment the counter
if in15=1 then wait_2
'check for entry of the person at the second
receiver receiver
wait_3:
if in15=0 then wait_3
receiver
goto enter
go_on:
if
if
if
if
'wait until the person unblocks the second
in15=0 then wait_4
alarm_override = 1 then flow_0
temp>80 then flow_6
safety>70 then safety_protection
goto flow_0
wait_4:
'when a person leaves the room, the mechanism of checking
debug ? in15
'him out is the same as the one of checking him in
if in15=0 then wait_4
lea_er = 0
wait_5:
lea_er=lea_er+1
'a similar time counter used when a person is leaving
if lea_er > 50 then leave
if in14=1 then wait_5
wait_6:
if in14=0 then wait_6
goto leave
enter:
counter=counter+1
if counter=1 then activate
if alarm_override = 1 then flow_0
if temp>80 then flow_6
if safety>70 then safety_protection
goto flow_0
activate:
high 5
'activate the relay
counter_l=2
'initialization of mode for fan and
light
counter_f=5
level = 6000
set=1
low 4
low 9
initialize the
resistance
‘
'the pulses cause the DS1804 to go "down",
‘DS1804 to have minimal
for x = 1 to 99
high 10
low 10
next
if alarm_override = 1 then flow_0
if temp > 80 then flow_6
if safety>70 then safety_protection
goto flow_0
leave:
if counter=0 then continue
counter=counter-1
continue:
if counter=0 then deactivate
'to prevent counter to go below zero
if alarm_override = 1 then flow_0
if temp>80 then flow_6
if safety>70 then safety_protection
goto flow_0
deactivate:
low 5
low 6
if alarm_override = 1 then flow_0
if temp>80 then flow_6
if safety>70 then safety_protection
goto flow_0
'****************************************************************************************
*********
'Fire Alarm Scheme
'****************************************************************************************
*********
flow_6:
if in12=0 then button1_press
debug ? in12
goto alarm
button1_press:
if in12=0 then button1_press
alarm_override = 1
low 5
debug ? alarm_override
goto flow_0
alarm:
big_count = 0
low 6
blinking of light
'combined with the code below, accomplish
low 4
high 5
high 9
for x=1 to 99
high 10
low 10
next
freqout 3,1000,4000
'make alarming noise
low 9
for x=1 to 99
high 10
low 10
next
pause 1000
debug ? counter
goto flow_0
alarm_override_reset:
alarm_override = 0
goto stat_temp
'****************************************************************************************
**
'Statistic
'****************************************************************************************
**
write_data:
Stamp
big_count=0
if ptr > 3 then continue
high 4
shiftout 8,7,lsbfirst,[170]
shiftin 8,7,lsbpre,[fromIC]
low 4
temp =fromIC/2
log(ptr)=temp
ptr = ptr+1
‘writes temperature data to the Basic
'get ready to send data
'send data to basic stamp
goto continue2
'**********************************************************************
'Safety Protection
'**********************************************************************
safety_protection:
safety_loop:
safety_counter = safety_counter +1
low 2
pause 2
rctime 2,0,safety
if safety>70 then safety_loop
if safety_counter < 8 then flow_0
low 5
low 6
goto flow_0
'turn off relay
'turn off 555
relay_engage:
high 5
goto continue3
(2)
'{$STAMP BS2}
ptr var nib
variables
tempavg var byte
temptot var word
temp var byte
big_count var word
fromIC var byte
big_count=0
log var byte(4)
'initialize all
ptr=0
main:
big_count = big_count+1
high 4
shiftout 8,7,lsbfirst,[238]
temperature IC
low 4
if ptr > 3 then
'initialize the
continue
'prevents array
overflow
debug ? big_count
high 4
shiftout 8,7,lsbfirst,[170]
'get ready to send
data
shiftin 8,7,lsbpre,[fromIC]
low 4
temp=fromIC/2
'send data to basic stamp
if big_count => 200 then write_data
when data is written
continue:
if in12 = 1 then main
button1_press:
data
if in12=0 then button1_press
temptot = 0
'counter to control
'if button is pressed display
for ptr = 0 to 3
temptot=temptot+log(ptr)
next
tempavg=temptot/4
'gets total of all data
'averages the total
debug ? tempavg
write_data:
'puts data into
variable
log(ptr) = temp
neccesary variables
ptr = ptr+1
big_count=0
goto continue
'resets and increments
Mechatronics
Final Project
Smart Ceiling Fan/Light Combination
ME 3484 - Group 4
Michael Roberts
&
Yang Xiao