Home :: News archive

News Archive

Bluetooth Controlled Relays

We often have enquiries from people wanting to control something from their mobile phone so here's a small tutorial describing a way to turn some relays on and off in our popular KTA-223 device using Bluetooth and an Android Phone, while it may be possible to do the same with an IOS or other device it may not be as simple and is not in the scope of this tutorial.

Things you'll need

First off let's go through some of the things that you'll need to get this project going

Configuring the Bluetooth Module

Before the Bluetooth Module can be used as a serial device it needs to be configured, plug it into the WIR-045 XBee Explorer using the SFC-005 Cerberus USB Cable and run a terminal emulation program (such as RealTerm) on the computer, point it to the serial port of the XBee Explorer.

A few commands as follows are needed,

  1. $$$ -enters command mode
  2. S~,0<CR> -Configure for SPP mode
  3. SU,9600<CR> -sets baudrate to 9600
  4. R,1<CR> -save and reboot with new settings

Note: <CR> is the carriage return character.

Putting the Hardware Together

  1. Take the Relayduino out of it's case
  2. Solder in a set of SFA-001 Arduino Stackable Headers
  3. If you have a v12 PCB you will need to cut a track as shown in the photo
  4. Add the 10k resistor as shown in the next photo
  5. Solder the other set of SFA-001 Arduino Stackable Headers to the ARD-091 XBee Shield
  6. Install the Auto Reset Jumper inside the KTA-223
  7. Plug the shield into the KTA-223 and the SFR-400 Bluetooth Module into the shield
  8. Reassemble the KTA-223

Now that the hardware is assembled we can work on making the software on the mobile phone talk to the KTA-223

Modifying the KTA-223 Arduino Sketch

The KTA-223 Arduino Sketch needs to be modified as the mobile phone software we will use cannot send the carriage return character that the KTA-223 looks for by default.

To do this, download the KTA-223 Arduino Sketch from here then open it in the Arduino editor and then find and change the line if (Rxchar == 13) to if (Rxchar == '!')

Compile and load the Sketch into the KTA-223.

Installing and Configuring the Android Software

There are a number of free bluetooth to serial programs that could be used for the same purpose but for this tutorial "Bluetooth Serial Controller" by "NEXT PROTOTYPES" is the one we use. Go to the "Play Store" on your Android Device and install it.

Once it is installed it needs to be configured.

Go to "Preferences->Button->Name" and then edit the text for each button, we have used R1 ON and R1 OFF for turning Relay 1 on and off, repeat for all the relays/buttons you wish to use, of course you can name them whatever you would like.

The next step is to configure the string that will be sent each time the button on the screen is pressed.
Go to "Preferences->Button->Command" and then edit the command for each button, for the R1 ON button we use the command @00ON1! for the R1 OFF we use the command @00OF1!.

Repeat for all the buttons you want to use. The command structure requires an @ symbol at the start, a 2 digit address (we use 00 as the wildcard address) a 2 letter command (ON to turn relays on and OF to turn relays off), one digit for the relay number (1-8 or 0 for all relays) and finally the exclamation mark ! to terminate the command.


You should now be at the point were we can control the relays from Bluetooth once we make a connection to the Bluetooth Module.

  1. Power up the KTA-223
  2. On the Android Device go to "Settings->Bluetooth->Search For Devices"
  3. A device "FireFly-XXXX" should be visible, where XXXX are the last 4 letters or numbers of the Bluetooth Modules MAC address
  4. Pair with the FireFly Module, you don't need to worry about the pairing code
  5. Run the Bluetooth Serial Controller software and tap "Connect"
  6. Select the FireFly Module and the status should change to connected
  7. Press some of the buttons to turn the relays on and off, you should now be done and ready to connect the relays to something practical like your sprinkler system

Next Time

While this is an easy way to control the relays from a mobile device it has some limitations:

  • Only for Android
  • Must be within Bluetooth range
  • Must reconnect if connection lost
  • No relay status back from KTA-223

Stay tuned for another upcoming tutorial where we will address these issues by using a WiFi module instead of a Bluetooth module and utilise all the IO of the KTA-223.

Stay tuned for more updates by subscribing to our News RSS and our New Products RSS using your favourite RSS reader.