You are on page 1of 105

Whirlpool Dispenser Cup Challenge

Michigan State University


Senior Design - ECE 480 - Team Eight
Spring 2015
Project Sponsor:
Whirlpool Corporation
Project Facilitator:
Dean Aslam
Team Members:
Daniel Sun
Connor Grossman
Daniel Gomez
Gao Xin
Hongyi Shen

Executive Summary
The new Whirlpool dispenser cup does not only differentiate between powder
and liquid detergent as well as liquid bleach and fabric softener, it also adds a new user
interface via LEDs. This makes the system not only user-friendly, but efficient. Telling
the difference in the cups contents allows the system to optimize energy, and water
usage. Our team, ECE 480 Design Team Eight will provide a prototype of this dispenser
cup design. The system interacts with three sensors, one for each cup, it is robust,
accurate and resistant to moisture, ambient light and vibration originating from the
washing process. The final manufacturing cost of the dispenser cup is less than $4.00.
Whirlpool is a company that has always strived for innovation and sustainability.
With the interaction between Whirlpool, Michigan State University and ECE 480 Design
Team Eight, Whirlpool continues to show that its primary concern is their customers, not
only will they provide a quality product, but they will make this product easy to use while
also being energy and water efficient.

Acknowledgements
On behalf of ECE 480 Design Team Eight, we would like to thank the following people
that have helped us in succeeding to achieve our goals for this project:
Our sponsors from Whirlpool Corporation, Jason Savage and Jeff Landrey for their
guidance, advice and support in the learning and development of our project as well as
the industry
Our facilitator, Dr. Dean Aslam, for his guidance, critique and creativeness that has
solved many issues that we have come across
MSU ECE Technical Services: Mr. Brian Wright and Mrs. Roxanne Peacock, for
supplying and ordering parts along with providing testing equipment

Table of Contents:
Chapter 1 - Introduction ..6
1.1
Whirlpool Project - Dispenser Cup 6
1.2

Whirlpool Corporation .6

1.3

Advantages of Dispenser Cup ...7

Chapter 2 - Exploring solutions and Selecting one .8


2.1

Analysis with FAST Diagram .8

2.2

Analysis with House of Quality .9

2.3

LED/Sensor/Cup Design ..12

2.4

Budget Planning and Final Cost per Unit ..13

2.5

Project Timeline: Gantt chart ...15

Chapter 3 - Technical Description .17


3.1

Light Selection ..17

3.1.1 R e d G r e e n B l u e ( R G B ) L E D 1 8
3.1.2 S u p e r B r i g h t R e d L E D . . 1 9
3.2

Microcontroller Selection ..20

3.2.1 E Z 4 3 0 - R F 2 5 0 0 . . 2 0
3.2.2 C C 2 5 0 0 T r a n s c e i v e r w i t h M S P 4 3 0 2 1
3.2.3 A t m e g a 1 2 8 R F A 1 m i c r o c o n t r o l l e r 2 2
3.2.4 A t m e l S t u d i o . . . 2 3
3.3

Dispenser Cup 3D Model .20

3.3.1 S i e m e n s N X 9 . 0 . 2 4
3.3.2 Testing Dispenser Cup Model .24
3.3.3 First Design Prototype ..30
3.3.4 F i n a l 3 D C u p D e s i g n . 3 4
3.4

Sensor Selection ...38

3.4.1 E l e c t r i c a l O p t i c a l S e n s o r . . 3 8
3.4.2 C h e m i r e s i s t o r s . . . 3 9
3.4.3 P h o t o r e s i s t o r s 4 1
3.5

Power Supply Selection 44

3.5.1 S o l a r C e l l a n d R e c h a r g e a b l e B a t t e r y . . 4 4
3.6

Data Communication 45

3.6.1 U S B . 4 5
3.6.2 W i - F i . . . 4 6
Chapter 4 - Data Tests 47
4.1

Sensor Testing ...47

4.2

Photoresistor Testing 47

4.3

LED Color Testing . . 4 8

Chapter 5 - Dispenser Cup: Final Summary ....49


5.1

Summary .49

5.2

Lessons Learned ..50

5.3

Further Improvements ..51

Chapter 6 - Appendix 1 ......53


6.1

Technical and Non-Technical Roles ..53

6.2

Daniel Sun ..54

6.3

Connor Grossman .54

6.4

Daniel Gomez ....55

6.5

Hong Yi Shen ..55

6.6

Gao Xin ....56

Chapter 7 - Appendix 2 .57


7.1

Ref erences .. 57

Chapter 8 - Appendix 3 ..58


8.1

Parts Identification ..58

8.2

Programming Screen ....63

8.3

Testing the Code .65

8.4

Circuit Calculations ..105

Chapter 1 - Introduction
1.1 Whirlpool Project - Dispenser Cup
Dispenser Cup Contents Detection is the project that Whirlpool has given to
design team eight. Through this project, the team needs to create a dispenser cup that
is able to power itself and also communicate with the appliance without any contact
pads or harnesses. The cup must also support six LEDS, a microcontroller, dispenser
cup sensors and any communication device that the team uses. The cup also has to be
robust to high humidity, temperature (99% humidity with condescension) and vibration.
The entire system should not cost over $4 in manufacturing cost. These are the
requirements proposed by Whirlpool.
1.2 Whirlpool Corporation
Whirlpool Corporation is one of the largest washing machine manufacturers. Its
headquartered is in Benton Charter which is a township in Michigan. The Company
was founded on November 11, 1911. At the very beginning, it was a small company
that produced electric, motor driven, wringer washers. With the science and technology
developing rapidly, most families chose to use a washing machine at home instead of
doing laundry outside washing by hand or driving to the laundromat. So the rigid
demand of having a household washing machine increased rapidly. Whirlpool growing
fast and becoming one of Fortune 500 company, having an annual revenue of about
19 billion dollars. They have more than 70 manufacturing and technology research
centers in the world. However a new problem also came up, which is how to use the
least energy to wash the clothes clean. Being energy efficient and to be
environmentally friendly are two big problems for the manufacturer. In addition, with
the fossil energy being scarce, the government and many environmental protection
organizations are pressing this issue. Energy Star is an international standard for
energy efficient consumer, it was created in 1992 by the Environmental Protection
Agency and the Department of Energy. It aims to encourage the manufacturer to
design the most energy efficient product. We can see the Energy Star label on most of
whirlpool products on the market.The label shows how much energy and money it can
6

save a customer every year. For the customer, they take this into their consideration
when they choose the product. Now, many companies like whirlpool are willing to fund
the research to find a more economically feasible way to reduce energy cost.

1.3 Advantages of Dispenser Cup


Whirlpool has been known for being a energy efficient company. There are many
aspects of the dispenser cup that will hold up to their value. When there is no cycle
selected the dispenser cup system will go into the low power state. The low power state
will be more energy efficient and environmentally friendly. With the implementation of
content sensor in the dispenser cups, there will be no residue within the cup and that is
another aspect of saving resources. The dispenser cup will also tell user the amount of
detergent, softener, and bleach to pour in. This will let the user know that they are not
over pouring or under pouring the materials. These aspects of the dispenser cups is
environmentally friendly and energy efficient. This is the reason that dispenser cups are
being invested into and hopefully used heavily in the next couple of years due to the
growing market of household appliances.

Chapter 2 - Exploring solutions and Selecting One


2.1 FAST Diagram Analysis with Fast Diagram
The Function Analysis System Technique (FAST) Diagram shown in figure 2.1
demonstrates how design team eight initiated its system for the whirlpool team. On the
left is the goal of this project which is to start a cycle of a washing machine. The way it
gets there is starting from the far right. The user selects a cycle on the washing machine
which then is transmitted wirelessly via microcontroller to the other board. After the
microcontroller receives the information the LEDS should light up on the cup indicating
which cup should be filled. The user then will add materials to the cup which starts the
sensing cycle. The cup will sense whether the material that is poured in was indeed the
material that is suppose to be poured in. If the material that is poured in is correct, the
LED will shine up as green, if it is shines up as red it means that the user has poured in
the wrong content in the cup. Assuming the right content was poured in, the dispenser
cup system will send back a signal to the main washing machine system which allows
the cycle to be started.

Figure 2.1 FAST Diagram of System Goals


8

Team eight uses mainly three components for this project: mechanical, electrical
and software. The mechanical devices includes the dispenser cup itself and all the other
materials that the team used for testing. The electrical devices includes the
microcontrollers, LEDs and the photoresistors. The software devices include the
programming of the microcontroller and an interface which user can select certain
cycles to test the program. These are the concepts that team eight is able to prove at
the end of this project.

2.2 Analysis with House of Quality


By creating a house of quality, our team was able to prioritize the customers
wants, which then help us focus on what mattered most to the costumers. Our house of
quality can be seen in figure 2.2.2 and the legend for the house of quality is seen in
figure 2.2.1.

Figure 2.2.1 House of quality legend

10

Figure 2.2.2 House of quality analysis

11

The house of quality analysis has prioritized our customer wants in this order (highest to
lowest):
Accurate Sensor
Detecting liquid detergent
Detecting powered detergent
Detecting Fabric Softener
Low Cost System
Time for Wireless Communication
Robust and Compact Size
2.3 LED/Sensor/Cup Design
Design team eight has designed the cup to be robust to vibrations and
temperatures and have met the requirements for dispenser cup. The team decided to
put three LEDs on the top layer of the dispenser cup to notify the user that which
content they should be pouring in. The other three LEDs will be implanted within the
dispenser cup and will only light up when materials have been poured in. These LEDs
will serve as a light source for the photoresistor to read. The team is basing this
technology on the thought that the LEDs light will emit different strengths through the
different materials. For example, more light will go through the detergent instead of the
softener. Therefore having difference in those values would help determine what are the
materials that were poured in. After the dispenser cup determines that it is the right
material that has been poured in, then the light would shut off and the cycle would
begin. Therefore with three different cups there will be three different photoresistors on
the cap of each cup. The team has selected to place the LED on the bottom of the cup
and the photoresistor on top implanted in the cap. This is because the team is scared
that photoresistors are not chemical proof and therefore cannot be submerged within
materials. We would want to, however, have them on two sides of the cup to enable
correct readings regardless of the amount of material the user has poured in.

12

2.4 Budget Planning and Final Cost Per Unit


At the beginning of this project, the group was handed a $500 budget to spend
on any resources that the group might use to finish this project. The group mostly spent
the budget on purchasing washing chemicals such as Detergents, Softener and Bleach.
Other costs included sensors and different type of LEDS. The most important purchase
was to buy the microcontroller that could perform the wireless communications. Good
budget planning was essential to giving the team room to invest and test different
methods of finishing this project. This team was still able to finish the project under the
$500 budget and still have leftover. The expenses of this team is fully detailed in the
below table.

Components

Quantity

Cost

Shipping

Total

20 Pcs 50-100K ohm

$4.22

$0.0

$4.22

Solar Cell

$6.95

$0.0

$6.95

Super Bright Red 5mm LED

$2.98

$5.95

$8.93

RGB LED, 50 pack

$9.95

$0.0

$9.95

TI eZ430-RF2500

$116.28

$0.0

$116.28

Tide original HE Detergent

$9.94

$0.0

$9.94

Downy Ultra liquid fabric

$7.98

$0.0

$7.98

Photoresistor

4000

softener

13

Tide Plus Bleach Alternative

$13.99

$5.99

$19.98

TI CC2500

$4.03

$4.09

$12.14

Energizer Power Plus NiMH

$12.19

$0.0

$12.19

$1.0

$0.0

$1.0

3D print Cup

$23.79

$0.0

$23.79

3D print Final Dispenser Cup

$40.00

$0.0

$40.00

SparkFun ATmega128RFA1

$171.780

$7.98

$179.76

AA Rechargeable batteries
DECS 3D print of a battery
case

micro-controller
$453.11

Total

Table 2.4 Project Cost


Team eight has demonstrated the costs it takes to accomplish the goal. The
team does suggest that this cost is due to purchasing pieces with low quantity. The
team do believe if these materials were bought in bulk the cost would go down
significantly. The estimated manufacturing should be relatively cheap. The cost will
heavily depend on what material the cup will be made out of and which microcontroller
is used. Photoresistors and LEDs could be purchased with a very cheap price when
they come in a bulk.
With the bulk price, the team believes that the cost can make it to under $4.
Please look at Figure 2.4 for more details.

14

Figure 2.4 Manufacturing Cost of Dispenser Cup


2.5 Project Timeline: Gantt chart
Figure 2.5 is the Gantt chart for design team eight. Team eight realizes that being
on time is just as important as being under budget and being resourceful. From this
gantt chart the team wanted to first define the project task. From there on the team
moved on to sensor testing, software resource decision, power supply design, hardware
development, software development, and finally full dispenser cup emulator which
combines everything together. The Gantt chart listed dates on when a goal would be
started and when it should be accomplished. The design team followed this schedule
strictly and had all these tasks done on time. There are more detail tasks shown in
Figure 2.5.

15

Figure 2.5 Team Eight Gantt Chart

16

Chapter 3 - Technical Description


3.1 Light Selection
One half of the light sensor is the light source, in our case the light source is a
light emitting diode (LED). A LED is a two lead semiconductor light source consisting of
a P-N junction that only lets current flow in one direction. Since current can only flow in
one direction it has the ability to change alternating current into direct current. The light
is created by the movement of electrons across a semiconductor by a phenomenon
called electroluminescence. The light is electromagnetic radiation as the electrons flow
through the semiconductor; this electromagnetic radiation is what the human eye picks
up as visible light. The electromagnetic radiation is in the form of photons.
When dealing with a light sensor, the selection of the light is a very important part
of the design. The intensity and the color of the light have extreme effects on the photo
resistor. These effects are due to cadmium sulfide which is the photoconductive
material in the photo resistor. Cadmium sulfide is more conductive with increased
intensity of the light and more sensitive to certain colors of light (figure 3.1.1). These
factors all contribute to the accuracy of our sensor making it extremely important to
choose the best intensity and color for our design.

17

Figure 3.1.1 Color Sensitivity of Cadmium Sulfide

3.1.1 Red Green Blue (RGB) LED


This type of LED is a little different than a tradition LED. It contains a total of four
pins (figure 3.1.1.1). The colors (red, green and blue) each have their own cathode pin
and they all share a common anode. This type of LED was ideal for testing different
colors and how they affected the reading from our photoresistor. Beside testing the
primary colors red, greens and blue, they could also mixed to provide different colors
across a wide range of different brightnesses. The precision to produce an accurate
color really helped the team to determine which color was optimum to determine
between fabric softener, liquid and powder detergent.

18

Figure 3.1.1.1 RGB LED Pins

3.1.2 Super Bright LED


The super bright LED emitted a red light which in the case of emitting light
through a material has some beneficial properties. Red light has a wavelength around
650 nm making it the longest wavelength among colors in the visible light spectrum.
This long wavelength gives it the ability to move quicker through objects, in turn, making
it bend less sharply. The combination of the LED and photoresistor are both
inexpensive, durable and energy efficient making it ideal for our project.
Even though this seems like the ideal LED for our project some of these
properties actually worked against team eight. The illumination characteristics of our
photoresistor says that the resistance decreases rapidly as light intensity increases
(figure 3.1.2.1). Therefore, when nothing is present is when the photoresistor will be at
its lowest resistance producing a lower voltage then when materials are poured into the
cup. The extreme brightness of the LED would emit strongly through the opaque liquids
giving the voltages for liquid detergent and fabric softener very similar readings making
it more difficult to program the microcontroller to distinguish between the different
materials.

19

Figure 3.1.2.1 Intensity vs. Resistance for CdS photocell

3.2 Microcontroller Selection


At the beginning of this project, the selection of the microcontroller is an big issue
for the team. The project requirements insisted on having wireless communication and
the team proposes that they either uses a microcontroller along with a transceiver or a
built in wireless function within microcontrollers. Below the team explores the
possibilities and the final decision that has been made by the team eight.

3.2.1 EZ430-RF2500
One of the possibility that the team proposes is using the EZ430-RF2500
microcontroller. The purchase of EZ430-RF2500 comes with two boards and a tutorial
manual. These two boards are identical and have 20 pins and a microcontroller. It has
built in wireless communication which allows one board to communicate with the other.
If one board is the main inserted as the main system, the other board will be placed
within our circuit. This microcontroller is selected due to the wireless communication
built within. Although this microcontroller is costly, the team decided to use it for the
testing stage of the project. With this microcontroller the team is able to light up the
LEDS for the cup with the three different colors. However the main issue with this

20

microcontroller that it is hard to program and very expensive. Therefore the team began
to explore other options that might be a better fit to this project.

Figure 3.2.1 EZ430-RF2500 Microcontroller

3.2.2 CC2500 Transceiver with MSP430


Another possibility that team eight proposed was using any MSP430
microcontroller tagged along with CC2500 Transceiver. The CC2500 transceiver acts as
a wireless communication device which is pivotal to the project requirements. MSP430
microcontrollers have been used in the ECE480 lab courses and is relatively easy to
program. The team is able to program MSP430G2553 to light up the LEDS however the
most important concept of wireless communication is not implemented. That is the
reason the team suggested to combine the MSP430s with CC2500. CC2500 is a
transceiver that costs $4.03 each. A transceiver could both transmit data and receive
data. Therefore, if the team programed the transceiver along with the CC2500 it could
lower the manufacturing price and also achieve the project goal. Figure 3.2.2.1 and
Figure 3.2.2.2 are photos of CC2500 transceiver and MSP430G2553.

21

Figure 3.2.2.1/2 MSP430G2553 Microcontroller (1) along with CC2500 Transceiver (2)

3.2.3 Atmega 128RFA1 microcontroller


Due to the limitation of MSP430, the team has a back up plan which is using 2 of
Atmega 128RFA1.
Atmega 128RFA1 is an AVR microcontroller with the wireless transceiver
embedded. One of microcontroller will be embedded within an usb port to connected
with computer or ALU (figure 3.2.3.1). Another one will be embedded with the dispenser
cup (figure 3.2.3.2). The detail of whole communication system and control system will
be introduced at section 3.6.

Figure 3.2.3.1

22

Figure 3.2.3.2

3.2.4 Atmel Studio


Atmel Studio is a software developed by Atmel. It can support most of
microcontroller of Atmel products in both C and C++. As it said on its website Atmel
Studio 6 is the integrated development platform (IDP) for developing and debugging
Atmel ARM Cortex-M and Atmel AVR microcontroller (MCU) based applications.
The Atmel Studio 6 IDP gives you a seamless and easy-to-use environment to write,
build and debug your applications written in C/C++ or assembly code. Atmel Studio 6 is
free of charge and is integrated with the Atmel Software Framework (ASF)a large
library of free source code with 1,600 ARM and AVR project examples. ASF
strengthens the IDP by providing, in the same environment, access to ready-to-use
code that minimizes much of the low-level design required for projects. Use the IDP for
our wide variety of AVR and ARM Cortex-M processor-based MCUs, including our
broadened portfolio of Atmel SAM3 ARM Cortex-M3 and M4 Flash devices. Since our
Atmega 128rfa1 is one of their AVR micro-controller and the software is free, it is the
best software to do the coding and debugging.

23

3.3 Dispenser Cup 3D Model


In order to meet all the requirements from the customer, the dispenser cup has to
be able to communicate with the washer wirelessly and the LEDs has to be used to
assist the user to employ the dispenser cup. In addition, the dispenser is removeable
and can be reassembled after cleansing. To use the dispenser cup model to test for the
project, a cup lid will be needed to insert the photoresistor. The bottom center of each
cup has a hole for inserting LED. After pouring material into the cup, the voltage across
the photoresistor can be measured by closing the cup lid and connecting the
photoresistor to the circuit.

3.3.1 Siemens NX 9.0


Siemens NX 9.0 has been to used to design the dispenser cup and all other
parts. Based on Ms. Xins previous experience on using Siemens NX 9.0 to design 3D
print model, she used the NX software to design the dispenser cup model, testing cup
and the battery case for the group.

3.3.2 Testing Dispenser Cup Model


Before printing out the model, a testing dispenser cup had been designed, which
contains one cup and one lid. In the center of the cup, LED can be inserted and
photoresistor can be inserted in the center of the lid.

24

Figure 3.3.2-1 Testing Cup

25

Figure 3.3.2-2 Testing Cup

Figure 3.3.2-3 Testing Cup Lid

26

Figure 3.3.2-4 Top View of the Testing Cup

Figure 3.3.2-5 Isometric View of the Testing Cup

27

Figure 3.3.2-6 Bottom View of the Testing Cup

Figure 3.3.2-7 Top View of the Lid

28

Figure 3.3.2-8 Isometric View of the Lid

29

3.3.3 First Design Prototype


The initial design of the dispenser cup has been designed to have three layers
with different functions, which can be assembled together and compose the dispenser
cup as a whole.

Figure 3.3.2-9 Assembled Dispenser Cup

In the first layer, there are three cups for detergent, bleach and softener
respectively. Also, there are three LEDs besides each cup. The application of the LEDs
is to tell the customer which cup needs to be filled and what should be put in the cup.
For example, when the detergent cup needs to be filled, the LED besides the cup will
turn to blue. When the cup is filled with the correct material and amount, the LED will
turn to green, otherwise the LED will be red.

30

Figure 3.3.2-10 First Layer of the Dispenser Cup


In order to decrease the waste of detergent/bleach/softener, a unflat cup bottom
has been designed as the second layer.

Figure 3.3.2-11 Top View of the Second Layer of the Dispenser Cup

31

Figure 3.3.2-12 Bottom View of the Second Layer of the Dispenser Cup

The bottom layer is to store the microcontroller, battery and other circuits. There
is also a common path for detergent/bleach/softener to go through to main part of the
washer.
To stabilize the dispenser cup, bars have been design in the second and bottom
layer. There are rectangular shaped bar holes at the bottom of the first and second layer
for bars to insert in.

32

Figure 3.3.2-13 Top View of the Bottom Layer of the Dispenser Cup

The storage place is to store the microcontroller, power supply circuit and
battery. The LEDs of the first layer will be directly connected to the circuit from the
bottom layer. To keep the electrical circuit and microcontroller out of water, the storage
place and the detergent/bleach/softener path has been separated.

33

Figure 3.3.2-14 Side View of the Bottom Layer of the Dispenser Cup

3.3.4 Final 3D Cup Design


However, based on the available budget of the group, the cost for printing out the
dispenser cup as designed as above is not applicable. After meeting with the Whirlpool
Co., a new dispenser cup needs to be designed, that no storage place for the circuit will
be needed since the cup is only a prototype. To decrease the cost for printing, different
layers needs to be eliminated and only the first layer was remained.
The modified cup only has two parts: cup and lid. There are three cups for
detergent, softener and bleach. Also, three LEDs have been added besides each cup.
In the bottom center of each cup, there is a hole that LED can be inserted, which will be
used as part of the testing procedure.

34

Figure 3.3.4-1 Final Design of the Dispenser Cup

35

Figure 3.3.4-2 Top View of the Modified Dispenser Cup


As for the lid, there are three holes for photo resistors to insert in to measure the
voltage across it when the LED has been turned on.

36

Figure 3.3.4-3 Final Design Cup Lid

Figure 3.3.4-3 Isometric View of the Modified Dispenser Cup Lid

37

3.4 Sensor Selection


The most feasible and effective way to detect contents in a dispenser cup has
been deemed to be a light sensor, with the light source at the bottom of the cup and a
light detecting source at the top. When emitting a light through a liquid or powder
detergent it will cause a change in the intensity of the light, which can be detected and
therefore tell the washing machine that the dispenser cup is filled. Not only is the design
of a light sensor simple but it can be very reliable and accurate for the needs of this
project. With the intensity of the light changing once contents are added to the cup, the
light sensor will cause a change in the voltage at the load. This change in voltage was
noticeable through testing, which makes the integration of a microcontroller to sense
this change possible. The design of a light sensor can also be used in the rough
conditions (vibrations and temperatures) of the washing machine which is a key factor in
choosing this route.
This, however, was not the only option that we explored. Through research and
advice there are multiple ways that fabric softener, liquid and powder detergent
effectively detected.
3.4.2 Electro-optic Sensor
The basic principle behind an electro-optic sensor is to take light and turn it into
readable data. The data this sensor is measuring is the quantity or intensity of light.
Many common uses for these are lamps that can turn on and off depending on the
amount of light, position sensors and velocity measurement. An electro-optic sensor
consist of three main components: optic sensor, a light source and an electric trigger.
To begin, an optic sensor is a light source and sensor all in an optical fiber.
Within the optic fiber is a LED to shine through the fiber, in which, the fiber has
properties to reflect most of the original light to the other end of the fiber. At the other of
the fiber is a small circuit that consists of a transistor and a resistor (figure 3.4.2.1). The
transistor has a certain current transfer ratio. Depending on the range of voltages the
measure device (microcontroller) this, along current transfer ratio, will determine the
value of the pull-up resistor. The second part of an electro-optic sensor, is the LED that
is used to emit light throughout the entire fiber. The final part of the electro-optic sensor

38

is the electric trigger. The electric trigger is usually a separate device that you used to
measure current through the pull-up resistor. In our case, the microcontroller is the
electric trigger to constantly measure the current at the logic output of the sensor. The
current value depending on the amount of light will determine a logic high (1) or low (0).

Figure 3.4.2.1 Sensor schematic


For our project accuracy is big requirement we want the sensor to be as reliable
as possible. The electro-optic sensor does provide very accurate highs and lows. It is
also relatively low cost and easy to implement into our dispenser cup design. The
reason for not choosing this sensor to provide these really accurate highs and lows you
need to have really specific values for all the parts within the sensor. These sensor are
mostly used to detect very small changes when we are trying to detect a larger changes
in light.

3.4.2 Chemiresistors
This is one of the alternative solutions that the design team proposed. The way it
works is that it takes the chemicals that are within the detergents/softener and bleach.
Having these touching the base of the chemiresistor would then produce an electrical

39

current. Different materials create different electrical currents and the user gets to
monitor those currents. With this being said, the team then could determine what
material is currently being sensed through the chemiresistor and then the team could
determine what to do with the data given. For example the team could decide to light up
the LED into the red light to show that it is the wrong material. Another way is that the
LED could be turned into green to show that it is the right material that has been poured
in the cup. This is an alternative sensor that is suggested because it is also quite cheap
in cost. Refer to Figure 3.4.2 for the way that Chemiresistors work graphically.

Figure 3.4.2 The way Chemiresistors work

40

3.4.3 Photoresistor
The light sensing concept consists of emitting light through the contents inside
the dispenser cup. In mind of keeping our design simple and cost effective, we decided
to go with a LED as our light source and a photoresistor as our light detector (figure
3.4.3.1). Using this design the only components needed are: two different resistors, a
photoresistor, a LED and a voltage supply. Only needing five total components can
keep the total cost to a minimum and also gives us the chance to experiment with
different parts and values for this design. With the design of this sensor being very
straight forwards it provides very accurate readings with minimal failure. A very accurate
sensor is detrimental to the customer since the washing machine is used in rough
condition. Violent vibrations, residual moisture, temperature flux and chemical corrosion
are the external factors that can possibly cause our sensor to fail. By using the
suggested design, these factors will have an insignificant effect on our light source and
photoresistor in detecting a change in the intensity of light.

Figure 3.4.3.1 Photoresistor Sensor Diagram

The device sensing the light is the photoresistor. The light from the LED is
essentially what the photoresistor is constantly monitoring and is told to the user by the

41

changing value of its resistance. Well how and why is light effecting the resistor? The
answer to that is photoconductivity; this is the driving principle behind the photoresistor.
Photoconductivity is the electrical phenomenon in which a material becomes more
electrically conductive due to the absorption of electromagnetic radiation (light). The
next question may be what material of the resistor gives it the photoconductive
properties? The material that makes this possible is an inorganic chemical called
cadmium sulfide (CdS). This chemical is intrinsic when undoped, meaning that photons
excite the valence electrons across the band gap to become conductive electrons.
When light strikes the surface of the cadmium sulfide the electrons get a boost in
energy and they hop across the band gap of 2.4 volts and move freely (figure 3.4.3.2).
In the graph you can see the x-axis the electric potential and the y-axis is the energy of
the photons in cadmium sulfide. At 2.4 volts the photon's energy is excited and the
value of it increases rapidly. In addition to the electron roaming free, it also creates a
hole that is technically positively charged and wants to be filled by an electron making
the composition of the material impure and causes the conductivity to rise. In terms of
the resistor, current can flow easily through it, making a very low resistance in light and
a very high resistance in the dark. The cadmium sulfide is made into a thin track the
runs across the electrodes and then connects to the terminals of the resistor (figure
3.4.3.3). This makes the photoresistor a passive element meaning it doesn't have a P-N
junction.

42

Figure 3.4.3.2 CdS (Volts vs. Energy)

Figure 3.4.3.3 Structure of a Photoresistor


One of the key properties is the how the frequency of the light affects its
conductivity. It just so happens that cadmium sulfide is most conductive in visible light
with a peak sensitivity between 560-600 nm, which is lighter shades of blue or green
light.

43

3.5 Power Supply Section


One of the main design requirements was to supply the power wirelessly. First it
was necessary to calculate how much voltage and current were needed to power all the
necessary components. First it was needed to consider that the microcontroller, one of
the main components, needs between 3.3-3.6V to function correctly, for the voltage
divider section of the sensor another 3.3V would be needed, and lastly to power each
green LED 2.2V and around 20 mA of currents would be needed.
At the end it was deemed that one source of 3.3V and around 60mA of current
would be necessary. This power supply would be located in the main system, or the
washing machine, and it is required to transmit this power wirelessly. The most common
method to wirelessly transmit power is through induction. Induction is a fairly easy
method to implement, two coils are needed, and one is the sending coil and is where
the power is applied. When current flows through the coil it will create and
electromagnetic field that will propagate and touch the other coil. The other coil is the
receiving coil, when this coil is hit by the electromagnetic waves it will induct both
current and voltage which will propagate through the circuit. However, with induction
about 50% of the power is loss during propagation, so the coils would have to be very
big for the power to be transmitted even short distances. As the design will be
implemented in the small space of a dispenser cup this method did not seem so
feasible.
3.5.1 Solar Cell and Rechargeable Battery
The selected method to power the dispenser cup was to use a rechargeable
battery and a solar cell that would recharge said battery. While this method cannot be
considered wireless power, it would make the dispenser cup self-powered which is the
ultimate goal. The schematic of the circuit is shown below on figure 3.5.1.1. As
previously mention the battery would have to be a 3.3V battery, which can provide at
least 60mA of current. When the battery was chosen, it was determined that the current
provided was more than 60mA, this problem was easily solved by placing resistors that
limit the current that goes through the LED, and so, preventing the burning of the LEDs.

44

Figure 3.5.1.1 Battery charger


The second main component is the solar panel, the one used is a 6V solar panel. This
means that on optimal conditions it will produce 6V. When the design was tested it was
measured that with minimal ambient light the solar panel produced 3.8-4.6V. This range
is higher than the 3.3V battery, as the solar panel voltage is higher than the battery this
means that the voltage drop will occur in the battery, charging it. However, when there
is no light the solar panel will not produce any voltage, so the battery would try to
discharge through the solar panel. To impede this, a zener diode was placed, the zener
diode will not allow the battery to discharge through the solar panel.

3.6 Data Communication


The data communication is one of the important part. The communication system
is consist by two part of data communication: wire communication and wireless
communication.

3.6.1 wire communication


As we have shown in figure 3.2.3.1, one of the microcontrollers is embedded with
the USB to make it easy to communicate with the computer or ALU. Since the USB port
is very common right now, USB maybe the best choice of wired communication. To

45

communicate with the computer, X-CTU is a necessary tool for serial port to transceive
and receive data. With the help of hardware (USB port and microcontroller) and the
software (X-CTU), we can easily communicate between computer and microcontroller
3.6.2 Wireless communication
Since the computer is not wired with the microcontroller on the dispenser cup
directly, wireless communication between the two microcontroller is necessary. The
whole communication system will be implemented like this: 1. The user enters the cycle
number into the computer. 2. The computer will transfer the cycle number to the
microcontroller through USB port. 3. The microcontroller on USB will transfer the data
to the microcontroller on dispenser cup wirelessly. 4. The microcontroller on the
dispenser cup get the information and control everything directly. so the whole system
will be shown in figure 3.6.2

Figure 3.6.2

46

Chapter 4 - Data Tests


4.1 Sensor Testing
To start off, accuracy and efficiency were the two main principles of the sensor
that we were designing. Testing was used throughout the course to perfect the sensor
of our design. Establishing which light would provide us with a distinct range of voltages
could help ensure that the sensor would be able to determine between liquid and
powdered detergent and fabric softener. This data can then be used with our
microcontroller to aid the microcontroller if the right material is in the right cup.
4.2 Photoresistor Testing
Initial testing was done on the photoresistor would function properly for what we
were planning to implement it for. We used the lab multimeter to measure the resistance
of the photoresistor, this was done by attaching one of the leads to each end. We
determine to test the resistor in ambient light, complete darkness and in an empty cup it
the LED shining on it (base resistance). These results are seen in table 4.2, the resistor
is highest when it is in complete darkness or minimal light exposure and then has the
least resistance value when sitting in ambient light. The base resistance value was
much closer to the ambient light value but was slightly higher indicate that the LED was
not as bright as the ambient light.

Photoresistor values
Light Intensity

Covered

Base (inside
unfilled dispenser
cup)

Ambient

Resistance (ohms)

160K

26.7K

16.7K

Table 4.2

47

4.3 LED color testing


Once the configuration and Photoresistor values were determined, team eight
could conduct test to decide which color would be best suited for this project. We used a
RGB LED was used to test multiple colors and keep the testing consistent. Power
supplies were used to ensure that we were testing with the same conditions to provide
us with some concrete values to use for the microcontroller. Using the RGB we testing
the colors red, green and blue. First the different colors were used to test the base
voltage when no contents were in the cups. Once that was done we tested the color
when liquid detergent, powdered detergent and fabric softener was place into the cup.
These results are shown in table 4.4.

RGB

Color
R

0.49

0.30

0.38

Liquid detergent (V) 0.61

0.38

0.45

Liquid Powder (V)

1.1

1.1

1.1

Fabric softener (V)

0.58

0.34

0.43

Base (V)

Table 4.3

48

Chapter 5 - Dispenser Cup: Final Summary


5.1 Summary
Team eight has created a dispenser cup that is powered on its own and also has
wireless communications with the main system. This cup can also detect materials such
as powder detergent, liquid detergent, softener and bleach. The design team has
achieved the various goals that were proposed by whirlpool and has even furthermore
improved on it.
There are many challenges throughout this project that whirlpool posed. One of
the challenge is the wireless communication. Wireless communication is a really hard
concept because the parts that the team tested with are expensive and would not meet
the budget constraint which is to be under four dollars. The first prototype stage the
team used the MSP430G2553 to light up the six LEDS that is presented on the cup.
The team is able to light them up in different orders enabling the user to know which
contents to pour in the cup. However this did not have any wireless communication to
the system. Therefore the team implemented Atmega128RFA1 which has the wireless
aspect. The team is able to successful program this microcontroller and ensure that one
of the project goals were met.
The second challenge the team encountered is sensing the material that is within
the cup. Whirlpool wishes that the team could build off last semesters project however
the team did not receive last semesters prototype and had to rebuild the sensor
system. The team decided to use photoresistor along with LEDs to determine the
material inside the cup. One issue the team had is that the photoresistor is extremely
sensitive to light. This issue is due to the fact that the team did not have a very
controlled environment and different light sources caused different readings. Although it
is not very controlled however after reading the correct values the team is still able to
accomplish what the dispenser cup needs to do. Design team eight is very glad that
they have been given the opportunity to work on this project and know that they are
helping Whirlpool and the customers of Whirlpool to a better washing machine system.
Figure 5.1 shows the final product and the LEDS lighting up.

49

Figure 5.1 Full Dispenser Cup system

5.2 Lessons Learned


Always have a backup plan (prototyping, parts)
Have flexible dates and stay on schedule
Having a controlled environment for testing is important
Electrical parts are delicate, and applying too much voltage/current could
damage the equipments
Working as a team is faster than working as an individual
Prototype testing is important to see where the improvements could be made
Presentations enhance not only presenting skills but requires one to fully
understand the subject at hand
Communications with superiors and peer is the key to success

50

5.3 Further Improvements


Although the team has accomplished the given task at hand, the team believes
there are still further improvements that could be made to further enhance the strength
in technology of the dispenser cup. In this section the team will further explore these
improvements that will be suggested for the future.
One of the improvement that the team suggested is to use rechargeable button
cells. The reason is that the team currently uses a rechargeable battery that has quite
some size. As we begin to package our final prototype, the team noticed that it might be
troublesome with this large battery. Therefore the team suggests that rechargeable
button cells could occupy less space and also achieve the same goal. The way that this
is done is stacking the button cells or arranging them in such an order to achieve certain
voltage/current. This way it could potentially occupy less space and gives greater
amount of resources for the dispenser cup. Button cells are also cheaper when it comes
to budget issues. This guarantees a lower cost that will probably yield a larger outcome.
Another improvement that the team suggested is using creating a unique PCB for
the dispenser cups. The reasoning behind this is that there were too many wires and
and also the breadboard that the team currently uses also occupies quite an amount of
space. Therefore having a PCB designed specifically for dispenser cups and having all
the connections ready to go would make the dispenser cup more efficient and easy to
implement.
Another improvement that the team suggests is finding solar cells that are more
light sensitive. The team tried to use one dollar calculator solar cells however soon to
realize they are fake and not useable. The team had already bought a solar cell before
hand however it only provided around 4.5V which is enough for our battery because we
had switched to a 3.3V battery. However the team suggests getting a larger solar cell
could help with the dispenser cup power incase there are other requirements that may
be needed in the future.
The last improvement suggestion is to enhance the detection device. The team
has realized that the photoresistor is very sensitive to light. Due to an relatively
uncontrolled environment it was hard for our programming/testing crew to successfully
figure out the range to detect either detergent, softener or bleach. This is due to that the

51

photoresistor is very sensitive to light and readings could differentiate based on where
the cup is located at the time. Therefore the team strongly suggests a better sensor with
a more controlled environment could enhance the quality of the dispenser cup.

52

Chapter 6 - Appendix 1

Left to Right: Daniel Gomez, Connor Grossman, Gao Xin, Hongyi Shen, Daniel Sun

6.1 Technical and Non Technical Roles


At the beginning of this course, ECE 480, the team was assigned different roles
for each individual. As they course of the semester went on new roles came up relating
to our project and we assigned according to everyones skill set. Below are the roles
that were assigned to the team members.

53

6.2 Daniel Sun


Daniel Suns Technical role is the senior design team manager. He is also
responsible for the selection of resistor values for our circuit designs for sensors and
power supplies. The placement of the sensors within the cup and photoresistor is also
decided by Daniel. Daniel decided to test with LEDs and Photoresistors to get the
readings for the microcontroller enable to program the microcontroller. Programming the
microcontroller requires values from photoresistor to determine whether the material
that is poured in the cup is indeed what is needed to be poured in the cup. Daniel Also
organized all the meetings for the group and kept the group on schedule.
Besides being the team manager, Daniel also bought most of the materials that
were needed to built the prototype and create the final product. He has set up great
meetings with the team and planning ahead and always keeping the team on schedule.
6.3 Connor Grossman
Connors first given role at the beginning of the project was document
preparation. His responsibility with this was edit and revises all documents that were
prepared over the course. He was the last person to look at the document before
submitting them to make sure grammar was correct and to make sure every section
was as detailed as possible. Another task that came along with this was working on and
checking over assignments that were turned in during the semester.
As the project progressed Connor took the role of designing and testing of the
sensor. This included testing different colors of light to ensure the most accurate
reading from the microcontroller. Initially Connor decided that a base voltage (without
material in cup) would be around 2 volts so that when material was poured in the
voltage would rise around 3 voltage, this would be a sufficient difference for the project.
Later it was discover that the microcontroller could only read up to 1.6 voltage. The
base voltage needed to be adjusted so this constraint would be accounted for, the base
voltage was then moved around 0.30 volts to make sure that any reading wouldnt
exceed 1.6 volts. Connor planned and conducted all testing for the sensor and used this
data to make decisions about the sensor.

54

Along with these task, Mr. Grossman also took a lead role with phone conference
calls with Jason and Jeff that included speaking and explaining progress of team eight.
Connor was the main source of communication with Whirlpool and was in charge of
relaying information to them.
6.4 Daniel Gomez
Mr. Gomez technical role is the microcontroller programmer and presentation
manager. Mr. Gomez has investigated the optimal configuration of the microcontroller
for interfacing with the dispenser cup and how to implement the wireless communication
with the main system of the washing machine. The effects of sample-and-hold time and
reference voltage configurations of the Analog-to-Digital converter have been
extensively tested by him. Mr. Shen and Mr. Gomez have collaborated to establish the
best protocol for the wireless communications and the sensor interfacing. The
microcontroller programming for serial communication configuration and protocol were
researched and implemented by him.
The second role of Mr. Gomez is Lab Coordinator, Mr Gomez was in charge of
ordering all the parts necessary for the prototype. Mr Gomez was in charge of setting
meetings with the facilitator and he also help with the design of the sensor and power
supply.
6.5 Hong Yi Shen
Mr. Shens technical role is the microcontroller programmer. Based on Mr.
Shens previous working experience on programming the microcontroller for many
robot. Mr. Shen is familiar with the Atmega128rfa1 microcontroller. He configured
wireless communication, UART, Analog to Digital converter, LED control for
Atmega128rfa1. He work with other teammates closely, to make sure the the program
can be used by the configured code. In addition, Mr. Shen also in charge to weld the
brand new microcontroller with the chips. Due to the limitation of the microcontroller
port, for example, there are only 8 pin for Analog to Digital and some other pins have
limitation functions like transceive and receive so he arranged the pin for LEDs was also
done by Mr.Shen.

55

As the presentation preparer, Mr. Shen and Daniel Sun invited other members to
make powerpoints online and after everyone finish their own part, he make up the team
to do the practice and make sure the time is not too long or too short. If necessary, he
will discuss with the team to adjust some parts.

6.6 Gao Xin


Ms. Xins technical role in the team is the designer of the 3D Print Dispenser Cup
Model and the website manager. She used the Siemens NX 9.0 to design the dispenser
cup. The initial design of the disperser cup has three layers that can assemble together
as the whole Dispenser Cup system, which has different functions and features for each
layer. The first layer has three cups for detergent, softener and bleach with LEDs
besides each cup. The LED turns to red when customer put the wrong material into the
cup. For example, when pour the bleach into the detergent cup, the LED will turn to
Red. LED turns to green meaning the material is poured into the correct cup. The
second layer has some storage place for the circuit. And the third layer contains the
common path for all three cups and the storage place. However, based on the project
budget, the initial design does meet the satisfaction, which means a modified design will
be needed.
The modified design is much simpler than the initial design, since the storage
place for the microcontroller and other parts of the circuits do not need to be count into
consideration at this point. The modified cup has only one layers, that contains three
cups for detergent, softener and bleach, which also has three LEDs beside each cup.
As the web manager, Ms. Xin also created a team website that has all the
information about the project. Ms. Xin updated the website every week with images,
videos and report documents.

56

Chapter 7 - Appendix 2
7.1 References
http://www.johnloomis.org/ece445/topics/egginc/pt_app.html
http://www.radioelectronics.com/info/data/semicond/phototransistor/photo_transistor.php
http://en.wikipedia.org/wiki/Photodiode
http://www.teccogroup.com/LED-Rope-light-p404.html
http://en.wikipedia.org/wiki/LED_lamp
http://naturescreationsinc.com/alternative-systems/led-lighting/
http://en.wikipedia.org/wiki/Analog-to-digital_converter
http://www.radio-electronics.com/info/data/resistor/ldr/light_dependent_resistor.php
http://en.wikipedia.org/wiki/Universal_asynchronous_receiver/transmitter
http://kids.britannica.com/comptons/art-53789/Photoresistor
http://www.edn.com/design/analog/4368794/Simple-night-light-uses-a-photoresistor-todetect-dusk
http://www.education.rec.ri.cmu.edu/content/electronics/boe/light_sensor/1.html
http://nguyenmarysci4.tumblr.com/post/45739083253/what-the-led-how-it-does-it-work
Electro-optical Senor Wikipedia. Wikimedia Foundation Inc., 4 Feb. 2015. Web. 13
Mar. 2015.
What is an Optical Sensor? wiseGEEK. Conjecture Corperation, 12 Mar. 2015. Web.
13 Mar.

2015.

Ball, Stuart. Exploring optical and magnetic sensors. Embedded. 17 Jun. 2003. Web.
13 Mar. 2015.
Cadmium Sulfide Wikipedia. Wikimedia Foundation Inc., 22 Feb. 2015. Web. 24 Mar.
2015.

57

Chapter 8 - Appendix 3
8.1 Parts Identification

Figure 8.1-1 Rechargeable button Cell

Figure 8.1-2 9v Rechargeable Battery

58

Figure 8.1-3 First Prototype Cup

59

Figure 8.1-4 RGB LED

Figure 8.1-5 Photoresistor

60

Figure 8.1-6 Solar Cell

61

Figure 8.1-7 Materials From left to right (Bleach, Detergent, Softener, Detergent,
Bleach)

62

8.2 Programming Screen


atmel studio 6.2 (programming software)

63

X-CTU 5.2.8.6 ( serial port tool)

64

8.3 Testing the Code


1. head file radio.h (from sparkfun.com)
/*
* radio.h
*
* Created on: Jan 15, 2012
*

Author: ratmandu

*/
#ifndef RADIO_H_
#define RADIO_H_
#define TRX_MAX_FRAME_SIZE 127
#define TRX_FIFO_SIZE 128
#define TRX_WAIT_BEFORE
//#define TRX_WAIT_AFTER
#define SHORT_ADDR_L 0xFE
#define SHORT_ADDR_H 0xED
#define RADIO_CHANNEL 20
#define PAN_ADDR 0xACDC
#define MAC_ADDR_0 0x01
#define MAC_ADDR_1 0x23
#define MAC_ADDR_2 0x45
#define MAC_ADDR_3 0x67
#define MAC_ADDR_4 0x89
#define MAC_ADDR_5 0xab
#define MAC_ADDR_6 0xcd
#define MAC_ADDR_7 0xef
65

#define modifyReg(var, mask, value) (var = ((var & ~mask) | (value & mask)))
// Transceiver state status
#define TRX_STATUS_MASK
0x1f
enum
{
STATUS_BUSY_RX = 0x01,
STATUS_BUSY_TX = 0x02,
STATUS_RX_ON = 0x06,
STATUS_TRX_OFF = 0x08,
STATUS_PLL_ON = 0x09,
STATUS_SLEEP = 0x0f,
STATUS_BUSY_RX_AACK = 0x11,
STATUS_BUSY_TX_ARET = 0x12,
STATUS_RX_AACK_ON = 0x16,
STATUS_TX_ARET_ON = 0x19,
STATUS_STATE_TRANSITION_IN_PROGRESS = 0x1f
};
// Transceiver state change commands
enum
{
STATE_NOP = 0x00,
STATE_TX_START = 0x02,
STATE_FORCE_TRX_OFF = 0x03,
STATE_FORCE_PLL_ON = 0x04,
STATE_RX_ON = 0x06,
STATE_TRX_OFF = 0x08,
STATE_PLL_ON = 0x09,

66

STATE_RX_AACK_ON = 0x16,
STATE_TX_ARET_ON = 0x19
};
#define PHY_RSSI_MASK
#define PHY_RSSI_RANDOM_MASK
#define TRX_BUF(i)

0x1f
0x60
_SFR_MEM8(0x180 + i)

#define ReadBit(var, bit) (((var) & (1 << (bit))) != 0)


static volatile uint8_t rssi;
static uint8_t* frameData[125];
static uint8_t frameLength;
enum
{
VERSION_A = 2, // A and B are both 2 according to the data sheet
VERSION_B = 2,
VERSION_C = 3,
VERSION_D = 4
};
uint8_t currentlyTransmitting;
void trx_radioInit();
void trx_setChannel(uint8_t channel);
void trx_send(void* data, uint8_t len);
void trx_calibrate();
void trx_setTXPower(uint8_t power);
void trx_setRXSensitivity(uint8_t level);
void trx_setTRXState(uint8_t state);
void trx_enterTRXSleep();
67

void trx_leaveTRXSleep();
void trx_setPANID(uint16_t panid);
void trx_setShortAddress(uint16_t shortaddr);
void trx_setExtAddress(uint8_t* extaddr);
void trx_waitWhile(uint8_t status);
void trx_getExtAddress(uint8_t* addr);
uint16_t trx_getShortAddress();
uint16_t trx_getPANID();
uint8_t trx_isSleeping();
uint8_t trx_getTRXState();
uint8_t trx_getRandomNumber();
uint8_t trx_getRSSI();

#endif /* RADIO_H_ */
2. head file serial.h (from sparkfun.com)
/*
* serial.h
*
* Created on: Jan 29, 2012
*

Author: ratmandu

*/
#ifndef SERIAL_H_
#define SERIAL_H_
#define SERIAL_0_RX_BUF_LEN

256

#define SERIAL_1_RX_BUF_LEN 256

68

char serial0RxBuf[SERIAL_0_RX_BUF_LEN];
char serial1RxBuf[SERIAL_1_RX_BUF_LEN];
uint8_t bytesInSerial0RxBuf;
uint8_t bytesInSerial1RxBuf;
uint8_t buffer0ReadLoc, buffer0WriteLoc;
uint8_t buffer1ReadLoc, buffer1WriteLoc;
void initSerial0(uint32_t baud);
void initSerial1(uint32_t baud);
void serial0PutChar(unsigned char data);
void serial1PutChar(unsigned char data);
void serial0PutString(unsigned char *str);
void serial1PutString(unsigned char *str);
void initSerial0RxBuf(void);
void initSerial1RxBuf(void);
void writeToBuffer0(unsigned char data);
void writeToBuffer1(unsigned char data);
unsigned char readFromBuffer0(uint8_t *bufsize);
unsigned char readFromBuffer1(uint8_t *bufsize);
void buf0SkipTo(unsigned char data);
void buf1SkipTo(unsigned char data);
uint8_t buf0Size(void);
uint8_t buf1Size(void);
void USART0_RX_vect(void);
void USART1_RX_vect(void);

#endif /* SERIAL_H_ */

3. head file trx.h (written by Xinyu Zhao)


69

/*
this head file include most of basic function of wireless function
*/
#ifndef TRX_H_INCLUDED
#define TRX_H_INCLUDED
#define SERIAL_0_RX_BUF_LEN

256

#define SERIAL_1_RX_BUF_LEN 256


//////////////////////////////////////////////////////////////////////////////////
//seiral.h
char serial0RxBuf[SERIAL_0_RX_BUF_LEN];
char serial1RxBuf[SERIAL_1_RX_BUF_LEN];
uint8_t bytesInSerial0RxBuf;
uint8_t bytesInSerial1RxBuf;
uint8_t buffer0ReadLoc, buffer0WriteLoc;
uint8_t buffer1ReadLoc, buffer1WriteLoc;
void initSerial0(uint32_t baud);
void initSerial1(uint32_t baud);
void serial0PutChar(unsigned char data);
void serial1PutChar(unsigned char data);
void serial0PutString(unsigned char *str);
void serial1PutString(unsigned char *str);
void initSerial0RxBuf(void);
void initSerial1RxBuf(void);
void writeToBuffer0(unsigned char data);
void writeToBuffer1(unsigned char data);
unsigned char readFromBuffer0(uint8_t *bufsize);
unsigned char readFromBuffer1(uint8_t *bufsize);
void buf0SkipTo(unsigned char data);

70

void buf1SkipTo(unsigned char data);


uint8_t buf0Size(void);
uint8_t buf1Size(void);
void USART0_RX_vect(void);
void USART1_RX_vect(void);
/////////////////////////////////////////////////////////////////////////////////////
//radio.h
#define TRX_MAX_FRAME_SIZE 127
#define TRX_FIFO_SIZE 128
#define TRX_WAIT_BEFORE
//#define TRX_WAIT_AFTER
#define SHORT_ADDR_L 0xFE
#define SHORT_ADDR_H 0xED
#define RADIO_CHANNEL 20
#define PAN_ADDR 0xACDC
#define MAC_ADDR_0 0x01
#define MAC_ADDR_1 0x23
#define MAC_ADDR_2 0x45
#define MAC_ADDR_3 0x67
#define MAC_ADDR_4 0x89
#define MAC_ADDR_5 0xab
#define MAC_ADDR_6 0xcd
#define MAC_ADDR_7 0xef
#define modifyReg(var, mask, value) (var = ((var & ~mask) | (value & mask)))
// Transceiver state status

71

#define TRX_STATUS_MASK
0x1f
enum
{
STATUS_BUSY_RX = 0x01,
STATUS_BUSY_TX = 0x02,
STATUS_RX_ON = 0x06,
STATUS_TRX_OFF = 0x08,
STATUS_PLL_ON = 0x09,
STATUS_SLEEP = 0x0f,
STATUS_BUSY_RX_AACK = 0x11,
STATUS_BUSY_TX_ARET = 0x12,
STATUS_RX_AACK_ON = 0x16,
STATUS_TX_ARET_ON = 0x19,
STATUS_STATE_TRANSITION_IN_PROGRESS = 0x1f
};
// Transceiver state change commands
enum
{
STATE_NOP = 0x00,
STATE_TX_START = 0x02,
STATE_FORCE_TRX_OFF = 0x03,
STATE_FORCE_PLL_ON = 0x04,
STATE_RX_ON = 0x06,
STATE_TRX_OFF = 0x08,
STATE_PLL_ON = 0x09,
STATE_RX_AACK_ON = 0x16,
STATE_TX_ARET_ON = 0x19
};

72

#define PHY_RSSI_MASK
#define PHY_RSSI_RANDOM_MASK

0x1f
0x60

#define TRX_BUF(i)

_SFR_MEM8(0x180 + i)

#define ReadBit(var, bit) (((var) & (1 << (bit))) != 0)


static volatile uint8_t rssi;
static uint8_t* frameData[125];
static uint8_t frameLength;
enum
{
VERSION_A = 2, // A and B are both 2 according to the data sheet
VERSION_B = 2,
VERSION_C = 3,
VERSION_D = 4
};
uint8_t currentlyTransmitting;
void trx_radioInit();
void trx_setChannel(uint8_t channel);
void trx_send(void* data, uint8_t len);
void trx_calibrate();
void trx_setTXPower(uint8_t power);
void trx_setRXSensitivity(uint8_t level);
void trx_setTRXState(uint8_t state);
void trx_enterTRXSleep();
void trx_leaveTRXSleep();
void trx_setPANID(uint16_t panid);
void trx_setShortAddress(uint16_t shortaddr);
void trx_setExtAddress(uint8_t* extaddr);
73

void trx_waitWhile(uint8_t status);


void trx_getExtAddress(uint8_t* addr);
uint16_t trx_getShortAddress();
uint16_t trx_getPANID();
uint8_t trx_isSleeping();
uint8_t trx_getTRXState();
uint8_t trx_getRandomNumber();
uint8_t trx_getRSSI();
//////////////////////////////////////////////////////////////////////////////
//Define the frame buffer of the Atmega128rfa1(use for RF transmission)
#define MMIO_REG(mem_addr, type) (*(volatile type *)(mem_addr))
#define TRX_FRAME_BUFFER(index) MMIO_REG(0x180 + (index), uint8_t) //Note:
Frame buffer of Atmega128rfa1 has 255 bytes
#define sbi(var, mask) ((var) |= (uint8_t)(1 << mask)) //set a bit (bit = 1)
#define cbi(var, mask) ((var) &= (uint8_t)~(1 << mask)) //clear a bit (bit = 0)
void trx_setChannel(uint8_t channel)

//function to select radio channel

{
PHY_CC_CCA = ((PHY_CC_CCA & ~0x1F) | (channel & 0x1F));
}
void trx_calibrate()

//calibrate transceiver

{
FTN_CTRL |= (1 << FTN_START);
PLL_CF |= (1 << PLL_CF_START);
PLL_DCU |= (1 << PLL_DCU_START);
}
void trx_setTXPower(uint8_t power) // transmit power control
{
74

PHY_TX_PWR = ((PHY_TX_PWR & ~0x0F) | (power & 0x0F));


}
void trx_setRXSensitivity(uint8_t level) //Receiver sensitivity control
{
RX_SYN = ((RX_SYN & ~0x0F) | (level & 0x0F));
}
void trx_setTRXState(uint8_t state) //set transceiver state
{
while ((TRX_STATUS & 0x1F) == 0x1F) //check if state change complete
;
TRX_STATE = state;
}
void trx_enterTRXSleep()

//enter TRX-OFF state

{
trx_setTRXState(STATE_TRX_OFF);
}
void trx_leaveTRXSleep()

//enter RX_ON state

{
trx_setTRXState(STATE_RX_ON);
}
void trx_setPANID(uint16_t panid) //set PANID for both low and high addresses
{
PAN_ID_0 = (panid & 0xFF);
PAN_ID_1 = ((panid >> 8) &0xFF);
}
void trx_setShortAddress(uint16_t shortaddr) //set the low and high short addresses
75

{
SHORT_ADDR_0 = (shortaddr & 0xFF);
SHORT_ADDR_1 = (shortaddr >>8) &0xFF;
}
void trx_setExtAddr(uint8_t* extaddr)

//set IEEE address

{
IEEE_ADDR_0 = extaddr[0];
IEEE_ADDR_1 = extaddr[1];
IEEE_ADDR_2 = extaddr[2];
IEEE_ADDR_3 = extaddr[3];
IEEE_ADDR_4 = extaddr[4];
IEEE_ADDR_5 = extaddr[5];
IEEE_ADDR_6 = extaddr[6];
IEEE_ADDR_7 = extaddr[7];
}
void trx_waitWhile(uint8_t status)

//wait till state change complete

{
while (trx_getTRXState() == status)
{
;
}
}
uint16_t trx_getShortAddress()

//read the short addresses

{
uint16_t shortAddr;
shortAddr = (SHORT_ADDR_H << 8);
shortAddr |= SHORT_ADDR_L;
return shortAddr;

76

}
uint16_t trx_getPANID()

//read the PANID

{
uint16_t panID;
panID = (PAN_ID_1 << 8);
panID |= PAN_ID_0;
return panID;
}
void trx_getExtAddr(uint8_t* addr)

//read IEEE addresses

{
addr[0] = IEEE_ADDR_0;
addr[1] = IEEE_ADDR_1;
addr[2] = IEEE_ADDR_2;
addr[3] = IEEE_ADDR_3;
addr[4] = IEEE_ADDR_4;
addr[5] = IEEE_ADDR_5;
addr[6] = IEEE_ADDR_6;
addr[7] = IEEE_ADDR_7;
}
uint8_t trx_isSleeping()

//check if transceiver is on sleeping state

{
if (trx_getTRXState() == STATUS_SLEEP)
return 1;
else
return 0;
}
uint8_t trx_getTRXState()

//return transceiver state

77

{
return (TRX_STATUS & TRX_STATUS_MASK);
}
uint8_t trx_getRSSI()

// read PSSI

{
return PHY_RSSI & PHY_RSSI_MASK;
}

/*=================================================================
=================================*/
//function for data array transmit:
//write into frame buffer and transmit data from frame buffer
void trx_send_data(uint8_t command)
{
// make sure we aren't receiving anything, wait till RX_BUSY finished
trx_waitWhile(STATUS_BUSY_RX);
// turn on PLL and prepare for transmission ( change to PLL_O11N state)
trx_setTRXState(STATE_PLL_ON);
//write data into frame buffer
//Note: To send more than one byte data, write them into the rest byte of the
frame buffer (total 255)
TRX_FRAME_BUFFER(1)=command;

//TRX_BUF(i+1) = 't';

//last bit is written 't'!

while (trx_getTRXState() != STATUS_PLL_ON) //wait till PLL_ON state change


complete

78

;
// start transmission
trx_setTRXState(STATE_TX_START);
}
#endif

4. code for the microcontroller on the usb port. C.file (edit by Hongyi Shen)
/*
* com.c
*
* Created: 4/20/2015 5:39:37 PM
* Author: shenhon2
*/

#define F_CPU 16000000UL

#include <avr/io.h>
#include <stdio.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include <avr/power.h>
#include <util/atomic.h>
#include <string.h>
#include "trx.h"

//h. file

define basic function and constant about wireless

communication

//RF communication's function defined

79

//=====================================
//uint8_t currentlyTransmitting;
void trx_radioInit();
//=======================================================

//printf function define


static int uart_putchar(char c, FILE *stream);
uint8_t uart_getchar(void);
static FILE mystdout = FDEV_SETUP_STREAM(uart_putchar, NULL,
_FDEV_SETUP_WRITE);

uint8_t command_recieved=0;
int main(void)
{
OSCCAL=0b10001100;

// set

calibration byte
//setup I/O port
//1 = output, 0 = input
DDRD = 0b11111011; //PORTD (RX on PD2)
clock_prescale_set(clock_div_1_rc);
initSerial1(921600);
//

initSerial1RxBuf();

trx_radioInit();

//set up the clock with division factor of 1

//initiate usart with baud rate of 921600


//initiate the buffer
//initiate the radio transceiver

printf("commander setup completes, ready for input robotic control


command!\n");
sei();

//set global interrupt

flag here
printf("Cycle 1: Detergent & Bleach\n");
printf("Cycle 2: Detergent & Softener\n");
80

printf("Cycle 3: Detergent \n");


printf("Cycle 4: Detergent & Bleach & Softener\n");
printf("Please enter the cycle number: ");
while(1)

//wait until next

interrupt coming
{
}
}
//RF function description
//=================================================================
===============//
void trx_radioInit() //initiate transceiver
{
cbi(SCCR0, SCCKSEL);

//clear SCCKSEL bit to 0 because when

trx coming into sleep mode it will automatically set as 1. but we need it as 0 when it
wake up
uint8_t addr[8];
addr[0] = MAC_ADDR_0;

//distribute mac address

addr[1] = MAC_ADDR_1;
addr[2] = MAC_ADDR_2;
addr[3] = MAC_ADDR_3;
addr[4] = MAC_ADDR_4;
addr[5] = MAC_ADDR_5;
addr[6] = MAC_ADDR_6;
addr[7] = MAC_ADDR_7;
IRQ_STATUS |= (1 << TX_END) | (1 << RX_END) | (1 << RX_START);
//pending interrupt request

81

IRQ_MASK |= (1 << TX_END_EN) | (1 << RX_END_EN) | (1 <<


RX_START_EN); //enable interrupt
trx_setTRXState(STATE_FORCE_TRX_OFF);

//enter TRX_OFF state

while (trx_getTRXState() != STATUS_TRX_OFF); //wait till state change


complete
trx_setExtAddr(addr);
trx_setChannel(RADIO_CHANNEL);
trx_setPANID(PAN_ADDR);

//select channel 20
//giving panid address

trx_setTRXState(STATE_RX_ON);

//enter RX_ON state

while (trx_getTRXState() != STATUS_RX_ON);

//wait till state change

complete
trx_calibrate();
_delay_ms(500);
printf("RF transciever setup!!!\n");
}

//**************************************************************************************************
**//
//function for usart
//initial seiall which work for buad rate as 921600
void initSerial1(uint32_t baud)
{
uint32_t baudreg;
baudreg = (F_CPU/baud/8-1);
UBRR1H = (uint8_t)((baudreg >> 8) & 0xFF);
UBRR1L = (uint8_t)(baudreg & 0xFF);
//UCSR1A = 0x00;
82

sbi(UCSR1A,U2X1);
UCSR1B = (1<<TXEN1) | (1<<RXEN1)|(1<<RXCIE1); //activate RX interrupt
UCSR1C = 0x06; //asynchronous, no parity,
stdout = &mystdout; //Required for printf init
printf("Serial communication setup!!!\n");
}
static int uart_putchar(char c, FILE *stream)
{
if (c == '\n') uart_putchar('\r', stream);
loop_until_bit_is_set(UCSR1A, UDRE1);
UDR1 = c;
return 0;
}
uint8_t uart_getchar(void)
{
while( !(UCSR1A & (1<<RXC1)) );
return(UDR1);
}

//interrupt rountine
ISR(TRX24_TX_END_vect)

//RX_ON interrupt

{
trx_setTRXState(STATE_RX_ON);
}

83

ISR(TRX24_RX_END_vect)

//Read frame buffer data interrupt

{
if (ReadBit(PHY_RSSI, RX_CRC_VALID) == 0)
{
return;
}
command_recieved = TRX_FRAME_BUFFER(0);
//printf("data is %c\n",command_recieved);
}
ISR(TRX24_RX_START_vect)
{
rssi = PHY_RSSI;
}

ISR(USART1_RX_vect) //Interrupt for serial communication


{
uint8_t keypress;
keypress=UDR1;
printf("\n");
printf("The cycle number is : %c\n", keypress);
trx_send_data(keypress);
printf("data has been sent out\n");
printf("Cycle 1: Detergent & Bleach\n");
printf("Cycle 2: Detergent & Softener\n");
printf("Cycle 3: Detergent \n");
printf("Cycle 4: Detergent & Bleach & Softener\n");
printf("Please enter the cycle number: ");
}
84

5. code for the microcontroller embedded with dispenser cup. C.file (edit by Hongyi
Shen)
/*
* cup.c
*
* Created: 4/20/2015 5:35:16 PM
* Author: shenhon2
*/

//Useful constant define


//================================
#define F_CPU 16000000UL //CPU frequency
#include <avr/io.h>
#include <stdio.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include <avr/power.h>
#include <util/atomic.h>
#include <string.h>
#include "trx.h"

//h. file

define basic function and constant about wireless

communication
//RF communication's function defined
//=====================================
//uint8_t currentlyTransmitting;
void trx_radioInit(); //initialize the RF transceiver
//=======================================================
//serial communication function

85

void initSerial1(uint32_t baud); //initialize the serial communication


void initSerial1RxBuf(void);
//printf function define
static int uart_putchar(char c, FILE *stream);
uint8_t uart_getchar(void);
static FILE mystdout = FDEV_SETUP_STREAM(uart_putchar, NULL,
_FDEV_SETUP_WRITE);
//function of adc reader
uint16_t readd();
uint16_t reads();
uint16_t readb();
//function of clear lights
void nolight();
uint8_t TEMP1;
uint8_t TEMP2;
uint16_t TEMP;
uint16_t output;
int main(void)
{
OSCCAL=0b10001100;

// set calibration byte

///sbi(PORTB,PORTB1);
clock_prescale_set(clock_div_1_rc); //set up the clock with division factor of 1
initSerial1(921600);

//initiate the usart with 921600 baud rate

(serial communication)
DDRB |= 0b11111111;
DDRE |= 0b11111111;
DDRF |= 0b11110000;
DDRG |= 0b11100100;
initSerial1RxBuf();

//initiate the rx buffer

86

trx_radioInit();

//initiate the RF transceiver

sei();//turn on the global interrupt


//set adc
cbi(PRR0,PRADC);
cbi(DDRC,DDC0);
ADMUX=0b11000000;

//bit7:6 select voltage reference 1.6V, MUX5 in

ADCSRB and bit 4:0 selects Analog Channel (single ended input ADC0)
ADCSRA=0b10000001;

//bit7 ADC enable; Bits 2:0 ADC Prescaler

Select Bits;
ADCSRC=0b00000111; //Bits 7:6 ADC Track-and-Hold Time (ADTHT);
Bits 4:0 C ADSUT4:0: ADC Start-up Time (ADSUT): startup time = 4(ADSUT+1),
minimum 20 s
cbi(ADCSRB,MUX5); //mux5 need to be 0, mux 5 is part of mux0:5
while(1)
{/*
ADCSRA = (1<<ADEN) + (1<<ADSC) + (2<<ADPS0); //enable adc
do
{} while( (ADCSRA & (1<<ADSC))); //wait adc complete
ADCSRA = 0x00;
TEMP1=ADCL;
TEMP2=ADCH;
TEMP = (ADCH << 8) + ADCL;
printf("\n %d ",TEMP1);
printf("\n %d ",TEMP2);
printf("\n %d ",TEMP);
*/
}
87

return 1;

//If it gets here, error happens!

}
//function of read data
uint16_t readd()
{
//initialize F0 as adc single read port
cbi(PRR0,PRADC);
cbi(DDRC,DDC0);
ADMUX=0b11000000;

//bit7:6 select voltage reference 1.6V, MUX5 in

ADCSRB and bit 4:0 selects Analog Channel (single ended input ADC0)
ADCSRA=0b10000001;

//bit7 ADC enable; Bits 2:0 ADC Prescaler

Select Bits;
ADCSRC=0b00000111; //Bits 7:6 ADC Track-and-Hold Time (ADTHT);
Bits 4:0 C ADSUT4:0: ADC Start-up Time (ADSUT): startup time = 4(ADSUT+1),
minimum 20 s
cbi(ADCSRB,MUX5); //mux5 need to be 0, mux 5 is part of mux0:5
//start read
ADCSRA = (1<<ADEN) + (1<<ADSC) + (2<<ADPS0); //enable adc
do
{} while( (ADCSRA & (1<<ADSC))); //wait adc complete
ADCSRA = 0x00;
TEMP1=ADCL;
TEMP2=ADCH;
TEMP = (ADCH << 8) + ADCL;
trx_send_data(TEMP);
printf("\n %d ",TEMP);
cbi(ADCSRA,ADEN);

88

sbi(PRR0,PRADC);
_delay_ms(20);
return TEMP;
}
uint16_t reads()
{
//initialize F1 as adc single read port
cbi(PRR0,PRADC);
cbi(DDRC,DDC0);
ADMUX=0b11000001;

//bit7:6 select voltage reference 1.6V, MUX5 in

ADCSRB and bit 4:0 selects Analog Channel (single ended input ADC0)
ADCSRA=0b10000001;

//bit7 ADC enable; Bits 2:0 ADC Prescaler

Select Bits;
ADCSRC=0b00000111; //Bits 7:6 ADC Track-and-Hold Time (ADTHT);
Bits 4:0 C ADSUT4:0: ADC Start-up Time (ADSUT): startup time = 4(ADSUT+1),
minimum 20 s
cbi(ADCSRB,MUX5); //mux5 need to be 0, mux 5 is part of mux0:5
//start read
ADCSRA = (1<<ADEN) + (1<<ADSC) + (2<<ADPS0); //enable adc
do
{} while( (ADCSRA & (1<<ADSC))); //wait adc complete
ADCSRA = 0x00;
TEMP1=ADCL;
TEMP2=ADCH;
TEMP = (ADCH << 8) + ADCL;
trx_send_data(TEMP);
printf("\n %d ",TEMP);

89

cbi(ADCSRA,ADEN);
sbi(PRR0,PRADC);
_delay_ms(20);
return TEMP;
}
uint16_t readb()
{
//initialize F2 as adc single read port
cbi(PRR0,PRADC);
cbi(DDRC,DDC0);
ADMUX=0b11000010;

//bit7:6 select voltage reference 1.6V, MUX5 in

ADCSRB and bit 4:0 selects Analog Channel (single ended input ADC0)
ADCSRA=0b10000001;

//bit7 ADC enable; Bits 2:0 ADC Prescaler

Select Bits;
ADCSRC=0b00000111; //Bits 7:6 ADC Track-and-Hold Time (ADTHT);
Bits 4:0 C ADSUT4:0: ADC Start-up Time (ADSUT): startup time = 4(ADSUT+1),
minimum 20 s
cbi(ADCSRB,MUX5); //mux5 need to be 0, mux 5 is part of mux0:5
//start read
ADCSRA = (1<<ADEN) + (1<<ADSC) + (2<<ADPS0); //enable adc
do
{} while( (ADCSRA & (1<<ADSC))); //wait adc complete
ADCSRA = 0x00;
TEMP1=ADCL;
TEMP2=ADCH;
TEMP = (ADCH << 8) + ADCL;
trx_send_data(TEMP);
90

printf("\n %d ",TEMP);
cbi(ADCSRA,ADEN);
sbi(PRR0,PRADC);
_delay_ms(20);
return TEMP;
}

//RF function Definition


//=================================
void trx_radioInit() //initiate transceiver
{
cbi(SCCR0, SCCKSEL);
XOSC_CTRL|=(0x02);
uint8_t addr[8];
addr[0] = MAC_ADDR_0;

//distribute mac address

addr[1] = MAC_ADDR_1;
addr[2] = MAC_ADDR_2;
addr[3] = MAC_ADDR_3;
addr[4] = MAC_ADDR_4;
addr[5] = MAC_ADDR_5;
addr[6] = MAC_ADDR_6;
addr[7] = MAC_ADDR_7;
IRQ_STATUS |= (1 << TX_END) | (1 << RX_END) | (1 << RX_START);
//pending interrupt request
IRQ_MASK |= (1 << TX_END_EN) | (1 << RX_END_EN) | (1 <<
RX_START_EN); //enable interrupt
trx_setTRXState(STATE_FORCE_TRX_OFF);

//enter TRX_OFF state

91

while (trx_getTRXState() != STATUS_TRX_OFF); //wait till state change


complete
trx_setExtAddr(addr);
trx_setChannel(RADIO_CHANNEL);
trx_setPANID(PAN_ADDR);

//select channel 20
//giving panid address

trx_setTRXState(STATE_RX_ON);

//enter RX_ON state

while (trx_getTRXState() != STATUS_RX_ON);

//wait till state change

complete
trx_calibrate();
printf("RF transceiver initialization succeeds!\n");
}
void nolight()
{
PORTE &= 0b00000011;
PORTB &= 0b00011111;
PORTF &= 0b00011111;
}
//***********************************//
//function definition for serial communication
//initial seiall which work for buad rate as 921600
void initSerial1(uint32_t baud)
{
uint32_t baudreg;
baudreg = (F_CPU/baud/8-1);
UBRR1H = (uint8_t)((baudreg >> 8) & 0xFF);
UBRR1L = (uint8_t)(baudreg & 0xFF);
//UCSR1A = 0x00;
sbi(UCSR1A,U2X1);

92

UCSR1B = (1<<TXEN1) | (1<<RXEN1)|(1<<RXCIE1); //activate RX interrupt


UCSR1C = 0x06; //asynchronous, no parity,
stdout = &mystdout; //Required for printf init
printf("Serial communication setup!!!\n");
}
void initSerial1RxBuf() {
memset(&serial1RxBuf, 0, SERIAL_1_RX_BUF_LEN);
bytesInSerial1RxBuf = 0;
buffer1ReadLoc = 0;
buffer1WriteLoc = 0;
}

//====================================================
static int uart_putchar(char c, FILE *stream)
{
if (c == '\n') uart_putchar('\r', stream);
loop_until_bit_is_set(UCSR1A, UDRE1);
UDR1 = c;
return 0;
}
uint8_t uart_getchar(void)
{
while( !(UCSR1A & (1<<RXC1)) );
return(UDR1);
}
//==========================================================
ISR(TRX24_TX_END_vect)

//RX_ON interrupt
93

{
trx_setTRXState(STATE_RX_ON);
}
ISR(TRX24_RX_END_vect)

//Read frame buffer data interrupt

{
if (ReadBit(PHY_RSSI, RX_CRC_VALID) == 0)
{
return;
}
uint8_t command_recieved;
command_recieved=TRX_FRAME_BUFFER(0);//read the data in frame buffer,
received by RF transmission
//following part is just an example: control the light.
//they can be edited on different port and pin or add different code to realize
different function
/* Determine the control command */

switch (command_recieved)
{
case 0x31:

//Turn on the LED connected to PB1


//'1' on the keyboard: turn on the LED on PB1

nolight();
//Detergent
sbi(PORTE,PORTE7);
sbi(PORTF,PORTF5);
_delay_ms(10000);
94

cbi(PORTE,PORTE7);
output=readd();
if ((output<=195)&(output >=160))
{
sbi(PORTE,PORTE6);
}
else if((output<155)&(output>160))
{
output=readd();
if ((output<195)&(output >=160))
{
sbi(PORTE,PORTE6);
}
else
{
sbi(PORTE,PORTE5);
}
}
else
{
sbi(PORTE,PORTE5);
}
_delay_ms(2000);
nolight();
_delay_ms(2000);

//Bleach
sbi(PORTB,PORTB7);
sbi(PORTF,PORTF7);
_delay_ms(10000);

95

cbi(PORTB,PORTB7);
output=readb();
if ((output<=160)&(output >=140))
{
sbi(PORTB,PORTB6);
}
else if((output<140)&(output>120))
{
output=readb();
if ((output<140)&(output >=130))
{
sbi(PORTB,PORTB6);
}
else
{
sbi(PORTB,PORTB5);
}
}
else
{
sbi(PORTB,PORTB5);
}
_delay_ms(2000);
nolight();
_delay_ms(2000);

break;
case 0x32:

//Turn off the LED connected to PB1


96

//'2' on the keyboard: turn off the LED on PB2


nolight();
//Detergent
//Detergent
sbi(PORTE,PORTE7);
sbi(PORTF,PORTF5);
_delay_ms(10000);
cbi(PORTE,PORTE7);
output=readd();
if ((output<=195)&(output >=160))
{
sbi(PORTE,PORTE6);
}
else if((output<155)&(output>160))
{
output=readd();
if ((output<195)&(output >=160))
{
sbi(PORTE,PORTE6);
}
else
{
sbi(PORTE,PORTE5);
}
}
else
{
sbi(PORTE,PORTE5);
}
_delay_ms(2000);

97

nolight();
_delay_ms(2000);

// softener
sbi(PORTE,PORTE4);
sbi(PORTF,PORTF6);
_delay_ms(10000);
cbi(PORTE,PORTE4);
output=reads();
if ((output<=195)&(output >=180))
{
sbi(PORTE,PORTE3);
}
else if((output<180)&(output>160))
{
output=reads();
if ((output<180)&(output >=170))
{
sbi(PORTE,PORTE3);
}
else
{
sbi(PORTE,PORTE2);
}
}
else
{
sbi(PORTE,PORTE2);
}
_delay_ms(2000);

98

nolight();
_delay_ms(2000);
break;
case 0x33:

//Turn off the LED connected to PB1

//'3' on the keyboard: turn off the LED on PB2


nolight();
//Detergent
sbi(PORTE,PORTE7);
sbi(PORTF,PORTF5);
_delay_ms(10000);
cbi(PORTE,PORTE7);
output=readd();
if ((output<=195)&(output >=160))
{
sbi(PORTE,PORTE6);
}
else if((output<155)&(output>160))
{
output=readd();
if ((output<195)&(output >=160))
{
sbi(PORTE,PORTE6);
}
else
{
sbi(PORTE,PORTE5);
}
}

99

else
{
sbi(PORTE,PORTE5);
}
_delay_ms(2000);
nolight();
_delay_ms(2000);
break;
case 0x34:

//Turn on the LED connected to PB1

//'4' on the keyboard: turn on the LED on PB1


nolight();
//Detergent
sbi(PORTE,PORTE7);
sbi(PORTF,PORTF5);
_delay_ms(10000);
cbi(PORTE,PORTE7);
output=readd();
if ((output<=195)&(output >=160))
{
sbi(PORTE,PORTE6);
}
else if((output<155)&(output>160))
{
output=readd();
if ((output<195)&(output >=160))
{
sbi(PORTE,PORTE6);
}
else

100

{
sbi(PORTE,PORTE5);
}
}
else
{
sbi(PORTE,PORTE5);
}
_delay_ms(2000);
nolight();
_delay_ms(2000);
// softener
sbi(PORTE,PORTE4);
sbi(PORTF,PORTF6);
_delay_ms(10000);
cbi(PORTE,PORTE4);
output=reads();
if ((output<=195)&(output >=180))
{
sbi(PORTE,PORTE3);
}
else if((output<180)&(output>160))
{
output=reads();
if ((output<180)&(output >=170))
{
sbi(PORTE,PORTE3);
}
else
{

101

sbi(PORTE,PORTE2);
}
}
else
{
sbi(PORTE,PORTE2);
}
_delay_ms(2000);
nolight();
_delay_ms(2000);
//Bleach
sbi(PORTB,PORTB7);
sbi(PORTF,PORTF7);
_delay_ms(10000);
cbi(PORTB,PORTB7);
output=readb();
if ((output<=160)&(output >=140))
{
sbi(PORTB,PORTB6);
}
else if((output<140)&(output>120))
{
output=readb();
if ((output<140)&(output >=130))
{
sbi(PORTB,PORTB6);
}
else
{
sbi(PORTB,PORTB5);

102

}
}
else
{
sbi(PORTB,PORTB5);
}
_delay_ms(2000);
nolight();
_delay_ms(2000);
break;
case 0x35:

//Turn on the LED connected to PB1

//'4' on the keyboard: turn on the LED on PB1


nolight();
sbi(PORTF,PORTF5);
_delay_ms(10);
readd();
break;
case 0x36:

//Turn on the LED connected to PB1

//'4' on the keyboard: turn on the LED on PB1


nolight();
sbi(PORTF,PORTF6);
_delay_ms(10);
reads();
break;
case 0x37:

//Turn on the LED connected to PB1

//'4' on the keyboard: turn on the LED on PB1


nolight();
sbi(PORTF,PORTF7);
_delay_ms(10);

103

readb();
break;
default:
break;
}
printf("get the char is %c\n",command_recieved);//
//trx_send_data(command_recieved);
}
ISR(TRX24_RX_START_vect)
{
rssi = PHY_RSSI;
}

104

8.4 Circuit Calculations


Selecting a pull-up resistor would help control what the base voltage of the
sensor. The first thing was to measure the resistance of the photoresistor when there
was an empty cup, this came out to be around 26 kohm. The next to things were pick a
source voltage and a base output voltage. Picking a source voltage of 3.3V was very
simple due to the fact that the microcontroller has a 3.3V output pin. Next was to select
a base output voltage for the sensor. We know that the microcontroller could only
measure between 0 and 1.6V and that the voltage would rise once the material was
poured into the cup. We decided that 0.3V would be a good base voltage that wouldnt
exceed 1.6 V once materials were added. To solve for this resistor value the voltage
divider equation was used:

Once the values were substituted the equation looked like this:

0.3 = 3.3

26

+ 26

Using basic algebraic principle, you can easily solve for R which is 260K. We opted to
use a resistor with the value of 270k because it could be provided for free through the
ECE 480 lab.

105