Sunday 21 October 2012

Arduino with Blue tooth

I want to be able to communicate with the robot I'm planning, not to control it, I'm planning that it will be largely autonomous, but I think it will be useful for development and debugging to get messages from it. A wheeled robot can't really communicate via a cable so I needed a wireless method and my research suggested that Bluetooth was the most suitable and economic method (also I hope to eventually use my mobile phone to communicate with it). I therefore purchased the Blue SMiRF module (made by Sparkfun) from Hobbytronics in the UK (see here). The module does not come with specific instructions about how to connect it to the Ardunio but its not that difficult.
To start with I needed to solder wires to the Blue SMiRF module. These are:

  • RTS (Request to Send) - this is connected directly to the CTS pin
  • 5V+
  • Ground
  • TX (Transmit) - this is connected the the RX pin on the Arduino
  • RX (Receive) - this is connected to the TX pin on the Ardunio
  • CTS (Clear to send) - connected to RTS


Once I did this I supplied the module with 5V and looked to see if the Bluetooth radio on my laptop could see it. To do this I went to Start, then Devices and printers and clicked Add a new device. The Blue SMirF showed up like this:
Click on the device and choose Next. Choose 'Enter the Device's pairing code' then click Next and enter the default code (1234). The module should now be paired.
The module now appears in the Devices and printers window and if you right click on it and choose Properties you can see which COM port it uses (its COM 6 here):
Next I connected the module up to my Ardunio. It is set up to run the motor controller sketch (see previous Blog entry). This requires the user to send an F over the serial link to run the motor forward, S to sop and R to reverse the motor. Note that you must download your sketch to the Ardunio over the USB serial link, you can't do this using the  Bluetooth link. You also MUST set the link speed int he sketch to 115200. It won't work at other speeds.

Now I connect the module to the Ardunio, the RX wire on the module goes to the TX pin on the Ardunio and the TX wire from the module goes to the RX pin on the Ardunio. I power the Ardunio using a 9v battery.

On my laptop I have downloaded a free serial communication program called  PuTTY which I now run. In the Session option I choose Serial, set the COM port to the correct one (COM6 in my case) and the speed to 115 (for 115200), like this:
Then click Open and a serial terminal window should open and the Green LED on the module should light.
The motor can then be run forwards and in reverse and stopped over the Bluetooth link, with messages from the Ardunio displayed in the serial window.