Post by curious48 on Jul 24, 2016 9:08:11 GMT
First, a reminder: this is an independent forum, and it's about you.
You guys are very welcome to submit articles or posts in this exact same style, if you think it will be useful to others, and to stick around for insightful discussion. We are dedicated to high-quality content and substantive, positive conversations on everything from microcontrollers, and Arduinos, to Raspberry Pis, other embedded PC's, projects, and even learning and about moving into manufacturing. But this means we have to be very clear that this is a completely independent forum by and for other hobbyists and niche manufacturers, whatever your stage in learning and developing, from first cracking open a microcontroller LED project or firing up Linux, through working on hobby projects, a prototype, and getting to manufacturing and sales. The goal of the forum is curiosity, exploration, learning, sharing, engaging with the community, with all substantial or interesting posts and discussions on all subjects especially related to building something, from zero knowledge as a hobbyist through starting to get to manufacture. Spam and the like are not allowed here. You can read our policy here. Register here and you will have access to our special board where you can draft articles and posts or you're ready to share them, and, if you feel like, why not start by introducing yourself here. How did you get interested in microcontrollers, embedded PC's, projects, or manufacturing? What do you hope to get out of the intersection of all of the same?
Walkthrough:
How to add Bluetooth to your Arduino setup
for just $2.39, in just a few minutes
Detailed Walkthrough
How to add Bluetooth to your Arduino setup
for just $2.39, in just a few minutes
Suppose you have a sweet Arduino project and it works just swell. Wouldn't it be cool if you could ditch the wires and connect to it from your phone or computer? Well, if you have just $2.39 then you can do that in fifteen minutes or less.
- What you will end up with is an Arduino that can take commands wirelessly from any phone or computer that has Bluetooth. (scroll to bottom for note on Apple devices.)
Firstly, we will be following this write-up by Sony Arouje. The focus is on simply establishing a serial connection, but wirelessly. He says:
A perfect application for serial over Bluetooth.
The key component you will use is this HC-05 Transceiver module which is available from eBay for $2.39.
This is what it looks like:
Here is the back:
This is the cheapest board we have found for Bluetooth. It is extremely widely used and very well-supported.
You should basically think of it as a wireless serial connection. We got these additional specifications from the "Other resources" linked below:
It can function both as Master (meaning it can initiate connections to other Bluetooth devices)
- and Slave (meaning another device, such as Phone, must connect to it), but comes preconfigured as the latter.
The module has a factory-set pin of 1234 when pairing with a phone.
As for the size, the bare board is 28mm * 15mm (just larger than US quarter in length, less than a US penny in width) and in the above-linked module is 43 x 15mm (less than 2 US quarters in length, same less than a penny width).
- What you will end up with is an Arduino that can take commands wirelessly from any phone or computer that has Bluetooth. (scroll to bottom for note on Apple devices.)
Firstly, we will be following this write-up by Sony Arouje. The focus is on simply establishing a serial connection, but wirelessly. He says:
This time I decided to use Bluetooth... to communicate between my mobile app and Arduino controller
A perfect application for serial over Bluetooth.
The key component you will use is this HC-05 Transceiver module which is available from eBay for $2.39.
This is what it looks like:
Here is the back:
This is the cheapest board we have found for Bluetooth. It is extremely widely used and very well-supported.
You should basically think of it as a wireless serial connection. We got these additional specifications from the "Other resources" linked below:
Additional specifications and information
- Protocol: Bluetooth Specification v2.0+EDR
- Frequency: 2.4GHz ISM band
- Modulation: GFSK
- Emission power: ≤4dBm, Class 2
- Sensitivity: ≤-84dBm at 0.1% BER
- Speed: Asynchronous: 2.1Mbps(Max) / 160 kbps, Synchronous: 1Mbps/1Mbps
- Security: Authentication and encryption
- Profiles: Bluetooth serial port
- Power supply: +3.3VDC 50mA
- Working temperature: -20 ~ +75 Centigrade
It can function both as Master (meaning it can initiate connections to other Bluetooth devices)
- and Slave (meaning another device, such as Phone, must connect to it), but comes preconfigured as the latter.
The module has a factory-set pin of 1234 when pairing with a phone.
As for the size, the bare board is 28mm * 15mm (just larger than US quarter in length, less than a US penny in width) and in the above-linked module is 43 x 15mm (less than 2 US quarters in length, same less than a penny width).
Detailed Walkthrough
This is how Sony wired up his HC05 module with an Arduino Nano:
He did three steps:
1. Connect pins to each other.
2. Level shift the voltage if you are using a 5V Arduino. (you can leave it out if using a 3.3V Arduino). These are the resistors you see below, and you can probably leave them out...
3. Load a 17-line sketch, which he includes, and which makes use of the software serial library.
Connect the pins
The module in the same orientation:
In other words, he put 5 volts into his Arduino and into the Module. He connected the rest of the pins as shown, and, as he explains elsewhere:
Which are the two resistors you can see in the above diagram. We've heard rumors that most BT modules will accept 5V on the RX/TX pins without issue, but of course, specs exist for a reason...
The rest of the connection is simply:
Note that he didn't need to use all of the pins. Specifically, he left out the Key pin, which he would need to use if he wanted the Bluetooth module to act as a master, initiating connections, instead of the default slave. (Accepting a connection, specifically form his phone.)
He did three steps:
1. Connect pins to each other.
2. Level shift the voltage if you are using a 5V Arduino. (you can leave it out if using a 3.3V Arduino). These are the resistors you see below, and you can probably leave them out...
3. Load a 17-line sketch, which he includes, and which makes use of the software serial library.
Connect the pins
The module in the same orientation:
In other words, he put 5 volts into his Arduino and into the Module. He connected the rest of the pins as shown, and, as he explains elsewhere:
The modules I used are operated in 5v but rx and tx has a limit of 3.3 volt, I used two resistors, 1k and 2k as level shifters at Bluetooth Rx side.
The rest of the connection is simply:
- Arduino Rx to Bluetooth Tx
- Arduino Tx to Bluetooth Rx
Note that he didn't need to use all of the pins. Specifically, he left out the Key pin, which he would need to use if he wanted the Bluetooth module to act as a master, initiating connections, instead of the default slave. (Accepting a connection, specifically form his phone.)
Copy this code
As for his code, as you can see in his write-up, his code is extremely simple. He uses the Software Serial to free up use of this hardware serial:
Click Sony's write-up to copy the above code
And that's really about it. You should then be able to connect from any Bluetooth device, such as your computer, and use any serial terminal (PuTTY has one, he recommends Hyperterminal, etc) to send commands over serial. If a passcode is required it would be 1234. The only remarkable thing is that's the same same combination as my luggage!
Further details:
- As Sony points out, if you go with an Arduino, such as the Arduino Zero, that runs at 3.3v - then you do not need to use the resistors but can connect straight to the Rx of the HC05.
- If you have a free hardware UART, you can use it without any issue - you don't have to use software serial.
Check out his article for a copy of the code.
Install (any) serial bluetooth terminal, and you're ready!
That's it for set-up. You should be able to connect from any Bluetooth device.
To connect from your computer:
- use any serial terminal (PuTTY has one, he recommends Hyperterminal, etc.)
- Macs can connect too using screen or any serial terminal supporting SPP.
To connect from your your phone:
- Simply install any serial bluetooth terminal that you want - you can just search for "serial bluetooth" from the Play Store and have lots of options. For an example of a simple terminal, you could use BlueTerm.
(for iPhone see "A note on Apple devices")
To connect:
1. Power on your Arduino
2. Connect your phone to it as a Bluetooth device - it'll show as HC05, and may require the passcode 1234. Once connected:
3. Launch your Bluetooth terminal app. You now have a serial connection with the Arduino!
You are now done and ready to use your Arduino wirelessly.
Going farther:
What if I want to initiate connections? For example to pair two Arduinos with each other?
As mentioned before, by default the HC-05 acts as a slave, meaning you must connect to it from a phone or other device that can act as a master. However, you may enter a command mode and ask it to act as a master instead - it has this capability. In the above write-up, the Key pin was not connected. You must connect this, if you would like to enter command mode, so that you can ask the HC-05 to act as a master, so it will initiate connections rather than just answering them. These instructions for putting the HC-05 into command mode are straightforward:
- www.instructables.com/id/Modify-The-HC-05-Bluetooth-Module-Defaults-Using-A/step3/Steps-To-Switch-The-HC-05-Into-Command-Mode/
You then enter the Command mode, and can issue an AT command to ask it to act as master.
Sending AT-commands is straightforward. Once you've wired the Pin as above, here is an instructable with exactly how to send HC-05 AT commands.
Here is a 16-page product manual: www.rcscomponents.kiev.ua/datasheets/hc_hc-05-user-instructions-bluetooth.pdf that covers all AT commands. The AT commands for HC-05 begin on Page 11. "manual for the first use of HC-05" There are some typos but it should be easy to follow.
For most Bluetooth applications you will not need to send any AT commands or make any changes.
Resources:
Product instruction manual:
www.rcscomponents.kiev.ua/datasheets/hc_hc-05-user-instructions-bluetooth.pdf
Pretty technical data sheet and command listing:
imall.iteadstudio.com/Modules/IM120723009/DS_IM120723009.pdf
Another simple Wiki is where we got the specifications and a very similar sketch.
A note on Apple devices.
Unfortunately, Apple does not support connecting to any Bluetooth 2.0 devices (such as the HC-05 used above) over a Serial profile on its iPhones, because Apple restricted this functionality in order to promote its own Mifi proprietary solution.
However, starting with iPhone 4S (the iPhone 4 and earlier do not support it) Apple supports connecting to Bluetooth 4.0 devices, also known as Bluetooth Low Energy, without paying Apple. So you will follow the same steps as the above, but use a Bluetooth 4.0 device. The cheapest and best-supported option here, is to purchase an HM-10 module instead of the HC-5 board discussed above - the bare board costs $4.87 USD for the HM-10 (here you would solder the pins), or you can find one with broken out pins for $7.85.
Here are detailed instructions for connecting it: www.instructables.com/id/Iphone-bluetooth-control-arduino/ - you will then be able to use this free HM10 bluetooth Serial app from the App store. The app is extremely straight-forward to use, simply following the directions.
Later, we can discuss iOS app development for the Arduino in more detail -- of course, that's a whole nother ballgame
Got your sweet arduino setup working for $2.39? Tell us about your experience!
Don't forget to check out our other posts, or join and talk about your projects, thoughts, trials, and tribulations. It doesn't get easy, but we can help each other make it easier. If you're serious about your projects, or just seriously curious, start or join a conversation today.