Web Home Automation Using Bluetooth Communication With 8051 Microcontroller
Web Home Automation Using Bluetooth Communication With 8051 Microcontroller
Web Home Automation Using Bluetooth Communication With 8051 Microcontroller
This report includes all detailed information of this honor research. Readers can do the exact same research by following the instruction given in the report.
Table of Contents
Table of Contents..............................................................................................2 Overview.......................................................................................................... 3 Equipment..................................................................................................... 3 Schematics.................................................................................................... 4 Construction..................................................................................................... 6 Building the Circuit........................................................................................7 Software........................................................................................................ 7 Interfacing the BGB203..................................................................................9 Measuring Ambient Room Temperature.......................................................10 Connecting to the PC......................................................................................11 Bluetooth Configuration...............................................................................11 Web Interface using ASP.NET.......................................................................16 Conclusion...................................................................................................... 17 Future Uses..................................................................................................17 Future Use Case 2........................................................................................19 Overall evaluation........................................................................................19
Terminal
Lighting
Laptop
T
Embedded Bluetooth Bluetooth Module IIS Server In Laptop WRL-08474 w/ ASP.NET(Broadcom 370 Mini Card) Temperature C8051F005 Monitor Development Board
Cell phone
...
PDA
Overview
This project aims to create a platform that allows the home owner to get information about home temperatures and control lighting entirely through a web-based interface. On one end, a home PC is set to run an ASP.NET web server that sends commands to the 8051 microcontroller via a Bluetooth Serial Port Profile (SPP). On the other end, the microcontroller interfaces with a Philips BGB203 Bluetooth module using UART. The microcontroller calculates room temperature through the built-in 12-bit ADC using a thermistor, and also controls the status of various household lights. Commands from the PC can tell the microcontroller to turn on or off lights and receive feedback about the state of any light or the room temperature from the microcontroller.
Equipment
(1) Silicon Labs C8051F005SDK Evaluation Board with USB Debug Adapter (1) SparkFun WRL-08474 Bluetooth SMD Module based on Philips BGB203 (1) LB21J1M Fenwal Electronics Thermistor (3) 4.7kOhm resistors (1) Bluetooth receiver (Broadcom 370 Mini Card) (1) Bluetooth enabled Laptop (1) RadioShack Wire Wrapping Tool (1) RadioShack Solder Tool Kit
3|Page
Schematics
As shown in the figure, the following two figures are schematics of the project. They have to two parts. The first one is the Analog I/O terminal block connection. As it is showed in the figure, two jumpers will be placed on pin 5 & 7 and pin 4 & 8 respectively.
4|Page
A n a l o g
C 8 0 5 1 F 0 0 5 - D K V R E F D A C 0 D A C 1 A I N 0 A I N 1 A I N 2 A I N 3 A I N 4 A I N 5 A I N 6 A I N 7 8 5 6 7 8 1 1 1 2 1 3 1 4 1 7 1 8
t o
A l l
D i g i t a l
u n c o n n e c t e d P o w e P i n s r ( 3 . 3
C o n v e r s
h a n g V ) i n
t h e
4 . 7
. 7 K
T h e
r m
i s
t 4o .r 7 K
5|Page
B l u e t o o t h
C 8 0 5 1 F 0 0 5 A V D D V D D V D D D G N D D G N D D G N D 1 1 3 1 3 3 9 4 1 4 2
M o d u l e
A l l
a n d
M i c r o c o n t r o l l e
P i n s h a n g i n t h e
u n c o n n e c t e d S p a r k F u n W R L - 0 8 4 7 4
5 7 8 9 1 0
R E S E T P C M _ C L K
S P I _ C S 2B 3 S P I _ C L 6K
S P I _ M O S 2I P C M _ S Y N C S P I _ M I S 2O 4 P C M _ I N P C M _ O U T U A R T _ R X U A R T _ T X U A R T _ R T S U A R T _ C T S P I O _ 21 9 P I O _ 32 0 P I O _ 42 2 P I O _ 52 1 P I O _ 63 P I O _ 74
D A C 0 D A C 1 A G N D A G N D C 8 0 5 1 F 0 0 5 F P 0 . 0 P 0 . 1 P 0 . 2 P 0 . 3 P 0 . 4 P 0 . 5 P 0 . 6 P 0 . 7
4 8 5 0 4 5 4 7 1 7 1 8 1 5 1 6 1 3 1 4 1 1 1 2
1 3 1 4 1 5 1 6
1 1 1 1 2 2 5 2 7 2 8 2 9
V D D G N D G N D G N D G N D G N D G N D
A N T
2 6
Construction
Physically, the whole project can basically be divided into three major parts. The first one is the microcontroller. Here, it is the Silicon Lab C8051F005 development board. The second part includes two things. One is the Bluetooth module connected to the microcontroller board, the other is the Bluetooth embedded in the laptop. They are in charge of communicating wirelessly. The final part is the web server in the laptop or in the Internet. Overall, the first part is all hardware; the second part is a combination of hardware and software; the last part is whole software. Due to the difference between their features, different constructions need to be used to implement their functions. 6|Page
Software
This device requires use of the microcontrollers UART and ADC subsystems. The software needs to initialize these systems and also setup the Bluetooth module through the UART interface using the BGB203s AT command set. First we will take a look at the ADC initialization. Set the BIASE bit to enable the ADC. The C8051F005 already contains an internal 1.2V voltage reference which we can use by setting the REFBE bit. The internal reference goes through a gain 2 buffer amplifier for an input range from -2.43V to 2.43V. Set ADC conversion to start upon write of 1 to the ADBUSY bit in the ADC0CN control register. Remember to enable the ADC end-of-conversion interrupt, bit 1 on the EIE2 register. Periodic readings of the thermistor are triggered by Timer 3 interrupt, which sets ADBUSY. We initialize the reload value such that an interrupt is triggered approximately every second. The Timer 3 ISR simply clears the interrupt flag and sets ADBUSY. To enable the UART, the CrossBar needs to be configured so that TX and RX are assigned to port I/O pins. The exact pins depend on what other functionality is enabled, but in this setup TX is assigned to P0.0 and RX to P0.1. This is done by setting the UARTEN bit in the XBR0 register. Additionally, the TX pin needs to be set to push-pull in the PRT0CF register. The RX pin is
7|Page
automatically set to open drain when the UART is enabled regardless of what is in PRT0CF. Next we need to set the baud rate. The baud clock in this case is derived from Timer 2 running in Baud Clock Generator mode. The Bluetooth module can communicate at most standard baud rates. However, the internal oscillator on the C8051F005 runs at a speed of 16MHz, which is not cleanly divisible into these standard speeds. You can purchase external oscillators such as those that run at 11.059MHz in order to access a wider range of communication speeds. We can calculate the baud rate with the following equation:
11.059MHz error 0% 0% 0% 0% 0%
As you can see, the 11.0592MHz clock allows for faster UART communication even though it is slower than the internal oscillator. Additionally, the internal oscillator does not run at exactly 16MHz, so you may need to try a couple of reload values before hitting on one that works for your microcontroller. Lastly, we need to implement the UART ISR called when either RI or TI flags are set. The RI is the receive interrupt set when the microcontroller has finished receiving a byte of data in the SBUF register. The TI is the transmit interrupt which is set when a byte of data has finished transmitting. Since RI and TI both trigger the same interrupt, the ISR must handle both cases. On a receive interrupt, the software clears the RI flag and attempts to place the received byte into a buffer array. If the buffer is full, the data is simply lost. 8|Page
In case of a transmit interrupt, the software clears the TI flag and checks is there is more data in the transmit buffer. If it is empty, the software clears TXBUSY, a variable that keeps track of whether the microcontroller is in a transmit sequence, and exits the ISR. If there is more data, the next byte in the buffer is written to SBUF which automatically initiates a transmission.
Disable security mode such that pairing is unnecessary AT+BTFLS Stores current configuration into Flash AT+BTSRV=2 Starts the Bluetooth SPP server At this point, it is ready to communicate with the PC from the microcontroller. Once the PC establishes an SPP connection, any data sent from the 8051 will show up on a virtual serial port on the PC, and vice versa.
10 | P a g e
The ADC samples an unknown input by using a small capacitor. It continuously tracks the voltage level of the input. When it is ready to perform a conversion, the ADC cuts off connection to the input and holds the charge that represents the analog level. This is commonly referred to as a sample and hold circuit. The ADC uses a technique called successive approximation. It utilizes a 12-bit DAC and a comparator. The ADC gets clocked 12 times by the system clock. Each cycle determines the value of one bit, starting with the most significant. For example, on the first clock cycle, the most significant bit of the DAC is set and its voltage compared to the input. If the voltage of the input is higher than the DAC output, then we know the most significant bit should be one. Otherwise, that bit should be 0. An ADC interrupt is triggered at the end of each conversion. The ISR takes the new reading and adds it to an accumulator variable. Every 8 readings, the accumulator is averaged and the averaged value stored in the global variable result. Such an averaging filter helps reduce the effect of noise and produce a more stable temperature reading.
Connecting to the PC
The Bluetooth module embedded in the laptop will be used when communicating with microcontroller board. A local server will be set up to create the interface between users and the machine. Users can have full control by sending commands in the web browser which is the most direct way for most people to use.
Bluetooth Configuration
Bluetooth will be used as SPP in the computer. Without any other softwares help, the Bluetooth module located in the microcontroller board can be found and paired using Windows Vista OSs Bluetooth service. The following are the detailed steps showing how to connect the Bluetooth module using Windows Vistas service. Step 1: Open Bluetooth option and start searching findable Bluetooth devices.
11 | P a g e
Step 2: As shown above, a Bluetooth device named SparkFun-BT is found. This is the one locates in the microcontroller board. Right click the icon and enter the properties option.
12 | P a g e
Step 3: In the service tab of the properties option, click the serial port checkbox. Then a pop up window will show up to indicate that the driver for this specific device is installing.
Step 4: As shown above, the Bluetooth is linked as COM8. When the installation of driver is completed, the Bluetooth module will show up in the paired devices list showed in the following.
13 | P a g e
Step 5: When the connection is connected for the first time, a notification pop-up window will show up to notify the users for security concern. This message needs to be clicked to allow the connection.
Step 6: For security concerns, a pairing code needs to be entered to pair the device. Initial code 0000 will pass the test.
14 | P a g e
Step 7: When the following window is shown, then the configuration for the Bluetooth has successfully completed. Further use will not require repeating the process.
15 | P a g e
16 | P a g e
Conclusion
Future Uses
This project is just a prototype to exemplify a platform that allows the home owners to manage their homes and get feedback information entirely through a web-based interface. However, it can actually implement much more functions than turning LED on and off. Since the hardware prototype had been constructed, little modification needs to be made in the web interface and microcontroller terminal to implement extended uses. The hardware for implementing the extended functions can be easily connected to the microcontroller terminal. The software interface can also be easily updated according to the new functions requirement. The following figure shows a practical model that how it can be used in real life as a commercial product.
17 | P a g e
Implementation: An infrared detector will be connected to 8051 microcontroller terminal. The infrared generator will be embedded in the door while the receiver is embedded in the frame. When door is closed, the detector 18 | P a g e
can detect the infrared signal and the state of the door can be determined. But once the door is open, the detector cannot detect any infrared signal and signal to be sent to 8051 microcontroller to update the state of the door (opened or closed) to the webpage interface. Any change of the state of the door can be notified to the house owners portable devices to let them know the latest state of the house.
Overall evaluation
8051 microcontroller was invented almost 30 years ago by Intel. It is still used nowadays because it is powerful enough to implement some complicated functions. In this particular project, the 8051 microcontroller is in charge of everything including the UART communication, the analog to digital conversion calculation and the LED controlling. Using the powerful analog to digital I/O on the development tool, many extended functions can be implemented easily. The coverage of Internet access is in an incredibly wide range now. Besides the traditional Internet access methods such as DSL and Dial-up, people are using 3G, EDGE, and Wi-Fi wireless technologies to have access to the Internet. This can dramatically expand the web user interface platforms from traditional PC terminals to any Internet enabled portable devices. In other words, the wide coverage and usage of the Internet enhances the usability and reliability of the project.
19 | P a g e
The use of Bluetooth wireless communication helps simplify the installation process in the house. People do not have to hook the appliances and the microcontroller terminal up. This can significantly help the house owner keep their living places tidy and organized. Again, since all the connections are wireless, extended functions can be very easily implemented with little modification.
20 | P a g e