Armed with a Smartphone you can surf the Web, send emails, text, chat, download and listen to music, take and post photos and video clips, listen and view TV stations, navigate, place bets and yes, even make phone calls to anywhere on the globe. Tens of thousands of Apps are also available to make the Smartphone the most universal, configurable control and communication device ever created. It is not surprising that there are also Apps which allow you to control the newer generation of home WLAN-equipped A/V equipment. The WLAN interface allows signals from the phone to be routed through to control the equipment directly without the need for additional hardware. Older A/V equipment generally only have the more traditional IR remote control interface and Smartphones still have no built-in IR transmitter.
The vital bit of kit missing here is an intelligent adapter that can on one side communicate with the phone using Bluetooth and on the other, transmit IR signals to control the A/V equipment. Intelligence, in this context generally means that a device has the ability to ‘learn’ a sequence of commands. This, of course, implies that a learn process is necessary. The adapter needs to know the particular variant of remote control that is in use and which button controls which feature of the controlled equipment. Simple, low cost universal remote controllers are pre-programmed with thousands of different command sets for all the different makes of equipment. They are generally only able to control a few basic commands like PLAY or STOP. It is not possible to edit the commands and a learn function is only possible with the more expensive types of universal remote controller. Some of the better types are able to execute macros which involve a sequence of commands (e.g. Watch a DVD = switch on a DVD player, TV, AV receiver, then configure the correct video and audio channel). This procedure is also possible with the Bluetooth-IR adapter described here. The newer, better quality (and more pricey!) type of universal remote controllers can now be conveniently programmed using a PC. To cut down on the software expenditure for this project we decided against this approach. In this design, the adapter is programmed by reading the IR signals directly from the original remote controller.
This means that the IR remote transmitter is placed in front of the IR adapter’s receiver and the command transfer. How this is exactly accomplished will be covered in more detail later, first, we will take a closer look at the hardware.
A radio-linked controller
The circuit diagram given in Figure 1 indicates that there really isn’t too much hardware used in the adapter design. It basically consists of a small Atmel type ATmega88 microcontroller together with some peripheral components:
A 24C512 EEPROM with 512 kBit memory and I2C interface to store the programmed codes.
• An infrared receiver module type TSOP32236
• Two IR transmitter diodes type TSAL6200 driven by a ULN2803 driver chip.
• A two-character 7 segment display with an HC595 8-bit shift register to show the programmed codes and program status.
• Three pushbuttons UP, DOWN and ENTER, for programming and operating.
• In-System-Programming interface K1.
• A relay with changeover contacts driven by the peripheral driver chip.
• Voltage regulators for +5 V and 3.3 V
You have probably seen all of these features many times before in many other circuits, however the real star of the show here is the BTM-222 Bluetooth module from Rayson. A description of the module is contained in the data sheet . The module is small, portable, easy to program and above all (around $10 a pop) affordable. In time, as we move to a more wireless future, all peripherals will probably communicate using devices like this. The BTM-222 is a class 1 device giving it a range of up to 300 ft. As you can see from its block diagram in Figure 2 it includes many serial interfaces and from these the UART must be favorite for microcontroller communications. Data throughput of the UART (and the USB interface) in the BTM-222 is guaranteed at the full data rate of 921 Kbit/s. The BTM-222 UART used with a microcontroller requires hardly any additional components. The communication parameters are factory set to the standard 8N1 setting:
• Baud rate 19,200 Baud
• 8 data bits
• No parity
• 1 stop bit
The microcontroller only needs to open the corresponding UART channel. As required, parameters and other properties of the module can be accessed using the so-called ‘AT command’ set of instructions. More information on this aspect is contained in the BTM-222 data sheet . The settings are stored in an internal flash memory. The ‘blue’ core of the module is clocked by an internal 16 MHz oscillator. The output signal is fed to a balun and then to an RF power amplifier producing a signal of +18 dBm at the aerial. For signal reception the BTM-222 switches the received signal to a low-noise amplifier block (LNA) followed by a band-pass filter to reduce out-of-band signal interference. The BTM-222 does not require any external aerial; a short length of PCB track can be used. Here we have used a short piece of wire. The module provides some status output signals: the data status (LED D5 on pin 11) and the connection link status (LED D6 on pin 13) are both used in the circuit. There is also an operating voltage status indicator output from pin 14 but we have not used it in this application.
BTM222 set up:
Initially, the Bluetooth module needs to be configured with the correct parameters. First, remove jumpers JP2 and JP3 to disconnect communications with the microcontroller. Connect the BTM-222 to a PC using, for example, a TTL232R cable from FTDI, connected to K3. The cable carries a 5 V line (connecting to pin 1 of K3) which must not be allowed to make contact with the BTM-222 supply (this is at 3.3 V, and its upper limit of 3.6 V must not be exceeded). It is therefore important to leave pin 1 of K3 unconnected and power the Bluetooth module from the board power supply.
Run a terminal emulation program such HyperTerminal or Hterm on a PC (Figure 3), select a (virtual) COM port, to which the Bluetooth module is connected and use the serial port settings given above for the BTM-222 serial interface. Check to see if the module reacts to the ATI command; this should cause all the module settings to be dumped to the screen. If there is no response check that the 3.3 V supply, the COM port settings and the connections on K3 (TxD/ RxD switched?) are in order. If you are unsure of the module settings or maybe suspect that the BTM-222 is not operating correctly you can pull pin PIO4 high for a minimum of three seconds to reset the module to its factory settings. Change the UART settings to 4800 Baud (ATL = 0), even parity (ATM = 2), no handshake flow control (ATC = 0). Adjust the terminal emulator settings after each parameter change. Finally, you can change parameters such as the module name or the Bluetooth connection PIN code as you wish.
Turn on the Smartphone (or another Android device), check that the BTM-222 has been detected and enter the PIN for the connection. When everything is in order turn the remote control unit off, disconnect the PC and place the two jumpers in positions JP2 and JP3.
The Remote App:
Once the Remote_Control.APK App has been installed the Android Smartphone will be capable of remote control. Bring up the App to begin pairing with the BTM 222 module. Choose the Bluetooth device using SELECT DEVICE and use CONNECT to establish a connection to the device. LED D6 lights up indicating that the module is connected to an Android device and D5 flashes when data is being received.
The transmit ted value (0 to 99) plus a line feed character tells the adapter which memory location is referenced. In playback mode the command received from the Bluetooth module can be evaluated. The principle is really simple: ‘2/n’ is received and the adapter jumps to memory position 2, and transmits the command stored in this position (in this case turning up the volume of device 1). Commands 73 and 74 do not produce any IR signal but instead operate a relay. Command 73 closes the relay contacts for two seconds while command 74 toggles the relay contact state between off and on. Connector K2 provides connection to the contacts, allowing external equipment to be switched on and off.
Figure 4 shows the App running in all its glory on a Smartphone. With the left/right arrows at the top, you can choose between five different devices. For each device, you can choose to enter a name in the text box and store it with the Save button. The name is retained so it appears when the App is next started. In addition, you can add a description to the functions 1 to 10. Press the EDIT button, choose the button to edit and enter the text. Press SAVE to store the text. This sequence is the same for every device.
The controller software is divided into two parts; the programming mode and the operational mode. In programming mode the remote controller infrared command signals are recorded in the adapter memory in the following manner: First, it is necessary to clear the serial EEPROM. This is accomplished by pressing all three buttons simultaneously and applying power to the adapter. When the seven segment displays show dE (delete) the three buttons can be released. The complete erase process takes a few minutes before 00 is shown in the display.
To record the commands in programming mode hold the ENTER button (pin PD6 to GND) before connecting the supply voltage. On the seven-segment displays, Pr should flash three times (Programming mode). Now find a memory position from 0 to 99 using the UP/DOWN buttons (pin PD5 and pin PD7) and select it using the ENTER button. The display will show the symbol – indicating its readiness. The remote controller can now be brought within 2 to 10 cm to the IR receiver and the required command button on the remote controller pressed once (once only!) Try to complete this process quickly to reduce the chance of recording some interference. The display should now show io.. as confirmation. Recording a macro is possible for each device, each macro can contain up to six commands. Macros are stored in the same way that single commands are stored.
When the IR signals are recorded the pulse widths are stored as Unsigned integer Variables, buffered and then saved to the EEPROM. To program another command it is necessary during the confirmation display (io. flashing) to hold the ENTER button after programming to generate a μC reset. With no other button pressed during reset, the program automatically jumps into playback mode. Now using UP/DOWN buttons you can select the command you have just stored and press ENTER to transmit it over the IR diode to switch the A/V equipment. This will show if the command was correctly stored.
On the PCB:
A PCB for the remote control adapter is available from the Elektor shop , where you can also order a preprogrammed microcontroller. Use this link to find the compiled App and the firmware source code. A look at the PCB layout should allay any fears for the home constructor; although the Bluetooth module has SMD outline connections are spaced at 1.25 mm and are relatively easy to solder by hand with a standard fine tipped iron. Correct placement of this module is important prior to soldering. Pin 1 can be identified by a small round dot on the metal screen (on the side by the aerial). This pin should be orientated near the PC1 label on the PCB. The thick pads along the long sides and at the ends are at ground potential and connected to the module’s continuous earth plane. Once the module has been soldered in position the other through-hole components can be fitted. It is recommended to mount the IC components using sockets. Both seven segment displays, the three push buttons, D5 and D6 are fitted to the PCB underside. This leaves all the ‘HID’ devices on the same side of the board which makes it simpler to install into a case. A simple short length of cable is suitable as an aerial. According to the calculation at 2.4 GHz (13 cms band) the aerial should be around 3.1 cm (λ/4), but the length is not too critical and for this application, we only need relatively short range communication. The main thing to remember is that if the unit is fitted in a metal housing please ensure that the aerial extends outside the case.
Internet Links www.mikrocontroller.net/wikifiles/f/fc/ BTM222_DataSheet.pdf  www.elektor.com/120043  http://appinventor.mit.edu