Bluetooth Home Automation
Bluetooth Home Automation
Done by:
Introduction
Bluetooth is a radio standard and communications protocol primarily designed for low
power consumption, with a short range (power-class-dependent: 1 meter, 10 meters,
100 meters) based on low-cost transceiver microchips in each device.
Bluetooth lets these devices communicate with each other when they are in range. The
devices use a radio communications system, so they do not have to be in line of sight
of each other, and can even be in other rooms, as long as the received transmission is
powerful enough.
Maximum Permitted Power
Range
(mW/dBm)
(approximate)
Class 1 100 mW (20 dBm)
~100 meters
Class 2 2.5 mW (4 dBm)
~10 meters
Class 3 1 mW (0 dBm)
~1 meter
Class
Components:
Lights:
In our home we put 4 lights, we can turn them on & off separately, connecting them
relay which separate the source of them ULN2003 for driving relay, of course the
controlling is 4 pic pins by giving output high on them.
DC motors:
We control three motors in two direction each to represent the movements of doors
and windows , need 2 pins each, 2 relays, driving from ULN.
The other implement of motor is a FAN so it is one direction motor with several
speeds, for this aim we need to use ccp1( PIN 17) to control duty cycle for the signal
we give to the motor, no external component is needed.
P1 = -5 / 2.2 V
P2 = - (Vin P1)
Vout = P3 = P2 x 3.3
LMN335 package of 4 IC's:
From above we used 2 external power supply, because this chip need Vout + 1.5 volt
at pin 4, Vout 1.5 at pin 11 at least, 15 & -15 as maximum.
LCD:
We connect LCD to our project for displaying relevant data.
Bluetooth module:
Bluetooth 2.0 serial / audio transceiver with auto-connect modes and command
interface (DIL).
Pin Connections
Power ground reference.
Vdd 3.3V - 5V power supply (DIL version)
3.3V power supply (SO version)
Pin
ATN
ESC
CTS
DNC
NC
Reset
RTS
RxD
TxD
Vss
Vdd
Name Description
Attention output: In Auto-Slave and Auto-Master modes, output is high if
connected, low if unconnected. In command mode, output is high if
serial data on RxD is from a remote device, low if a command mode
response.
input: A low to high transition causes the module to revert to the mode
where it
accepts commands rather than transmits transparent data.
Clear To Send: Flow control input to LinkMatik 2.0. When low, LinkMatik 2.0
will output data on the TxD line.
Do not connect
Not connected
Reset Low to operate, high for at least 10ms to reset
Flow control output from LinkMatik 2.0. When high, do not send data to
LinkMatik 2.0.
Serial data input to LinkMatik 2.0.
Serial data output from LinkMatik 2.0.
Power ground reference.
3.3V - 5V power supply (DIL version)
Serial Connections
The serial data default baud rate is 9600 baud standard active low format with 8
data bits, no parity bit and 1 stop bit. Hardware flow control is supported. If no
flow control is required, RTS should be connected to CTS.
We implement this No Flow Control.
Operating Modes
There are three operating modes for LinkMatik 2.0:
Auto-Slave Mode, where LinkMatik 2.0 allows other devices to connect to it we
work in this mode.
Auto-Master Mode, where LinkMatik 2.0 tries to connect to devices it is paired
with.
Command Mode, where LinkMatik accepts instructions from the host.
Command mode is
also used for:
Configuring Auto-Slave and Auto-Master settings such as baud rates
Audio modes
Connections to multiple devices
LinkMatik is shipped in Auto-Slave mode with the PIN code 9999 at the first time.
Schematic:
Software Application
Our application is J2ME mobile application using midlet application.
It searches for all Bluetooth devices around it for a distance nearly 10m.
Then it will search for all services for a device that you select.
The following functions are used for search for Bluetooth devices and services.
printString("devicesFound" +bluetoothDevices.size());
} catch (Exception e) {
printString("Exception (b4): " + e);
}
}
urlConn=servRecord[i].getConnectionURL(ServiceRecord.NOAUTHENTICATE_NOENCR
YPT, false);
service_append(urlConn);
}
printString("services discovered");
}
public void serviceSearchCompleted(int transID, int respCode) {
service_show();
}
public void inquiryCompleted(int discType) {
switch (discType) {
case DiscoveryListener.INQUIRY_TERMINATED:
printString("Search cancelled");
break;
case DiscoveryListener.INQUIRY_ERROR:
printString("Bluetooth error");
break;
case DiscoveryListener.INQUIRY_COMPLETED:
printString("before calling searchServices..1");
try {
printString("before calling searchServices..2");
menue_show();
} catch (Exception exception) {
printString("search services not called");
}
printString("Device search complete");
break;
default:
printString("Unanticipated result: " + discType);
}
}
Class Connect :
class Connect extends Thread {
Midl m;
String urlConn;
public Connect(Midl m ,String urlConn)
{
this.m =m;
this.urlConn=urlConn;
}
public void run()
{
try
{
m.service=(StreamConnection)Connector.open(urlConn);
int n=0;
int ch;
byte[] imgData = null;
m.output = m.service.openDataOutputStream();
String mssg ="m";
m.output.write(mssg.getBytes());
m.output.flush();
// Tracer.outln("write", text);
m.input = m.service.openDataInputStream();
while ((n = m.input.read()) != -1) {
m.RX_msg=m.RX_msg+(""+(char)n);
System.out.println("from midlet fn"+m.RX_msg);
}
// m.home.setString(msg);
m.home.repaint();
// m.input.close();
}
catch (IOException e2) {
// printString("exception") ;
}
}
Then Graphics Interface for home is displayed after connection is completed.
g.setStrokeStyle(Graphics.DOTTED);
g.setColor(0x000000);
switch (keyCode) {