In this example we will add bluetooth support to our Arduino, there are several low cost modules labelled either Hc-05 or HC-06. Here is a picture of one of them
In this example we will connect one of these modules to our Arduino, use the software serial library and using a terminal program send a command via your PC and switch the on board LED on and off. First lets take a look at the schematic
Schematics
As you can see the connections are as follows in the schematic below
Code
Upload the following to your Arduino
[codesyntax lang=”cpp”]
#include <SoftwareSerial.h>// import the serial library SoftwareSerial BT(10, 11); // RX, TX int ledpin=13; // led on D13 will show blink on / off int BluetoothData; // the data given from Computer void setup() { // put your setup code here, to run once: BT.begin(9600); BT.println("Bluetooth On please press 1 or 0 blink LED .."); pinMode(ledpin,OUTPUT); } void loop() { // put your main code here, to run repeatedly: if (BT.available()) { BluetoothData=BT.read(); if(BluetoothData=='1') { // if number 1 pressed .... digitalWrite(ledpin,1); BT.println("LED On D13 ON ! "); } if (BluetoothData=='0') { // if number 0 pressed .... digitalWrite(ledpin,0); BT.println("LED On D13 Off ! "); } } delay(100);// prepare for next data ... }
[/codesyntax]
PC setup
I use software called TeraTerm to show the data received or what we want to send through it . You can download TeraTerm or any terminal emulator software , you can download Tera term from this link : http://hp.vector.co.jp/authors/VA002416/ttermv14.zip
To make a link between your Arduino and PC:
I'm using Windows 10 here
1) Go to the Bluetooth icon , right click and select Add a Bluetooth Device
2) Our bluetooth module will appear as HC-06 , select it and click on the Pair button
3) The pairing code is 1234 . On Windows 10 you will see something like this. Click on next and your ready to go
Now start Tera Term and you will see a bluetooth com port, as you can see in this example on my PC it was COM4
In the terminal send a 0 and 1 and you should see something like this
Links
Here are links to the HC-05 and HC-06 modules
Bluetooth Module 3.6V-6V HC-06 FZ0405 Free Shipping
HC-05 Wireless Bluetooth RF Transceiver Module
Originally my Windows 10 had no bluetooth capabilities but I added the small module below and this was then present