In this article, weāll look at how to control an LED over Bluetooth using the HC-06 Bluetooth module, Bluetooth Serial mobile app and your Arduino.
Youāll need the following items to carry out this project
Hardware
Software
- Any terminal of your choice, iāll be using Tera Term for this project, get itĀ here
- Latest Arduino IDE, get itĀ here
- Go to your mobile app store and downloadĀ Bluetooth Serial App.
Introducing the HC-06 Bluetooth Module
The HC-06 module is a device based on the BC417 2.4GHz Bluetooth radio chip. It uses an 8MB flash memory. These small 3 cm long modules run off 3.3V power and logic level. The HC-06 module includes the Radio and Memory chips, 26 MHz crystal, antenna and RF matching network. The right section of the BT Board has connection pins for power and signals as well as a 5V to 3.3V Regulator, LED, and level shifting.Ā Baud Rate: 9600 bps, Data : 8 bits, Stop Bits: 1 bit, Parity : None, Handshake: None
Please note that HC-05 is the sister module of the HC-06 which can act alternately as a master or slave device. HC-06 functions only as a slave.
IMPLEMENTATION
STEP 1: CIRCUIT CONNECTION
STEP 2: COMMUNICATION
If you havenāt downloaded the Tera Term software and Bluetooth Serial mobile app, please refer to the beginning of this article.
Start your Tera Term software
- Click on the Serial radio button
- Click the port drop down select the appropriate COM port
- Type in AT, you should get an āOKā response, that means your module is functioning correctly.
- Type in AT+VERSION? to get the version of your module
- Type in AT+PSWD? to get the password of your module
- To change the name of your HC-06 module, disconnect power from the module, hold down the button on the module and re-connect the power, then type in AT+NAME CHOICEOFNAME, replace CHOICEOFNAME with the name you want.
Start your Bluetooth Serial mobile app,
- Click the connect button on the top right
- Select the HC-06 module to connect to it
- If your textbox isnāt showing below the screen, click the Preference button on the top right
- Scroll down and toggle the Text Box and Sent Data mode
- Click on the text box, type any letter or word of your choice
- Youāll see them appear on the Tera Term software screen.
Now, we can communicate with the HC-06 module, letās control an LED with an Arduino using the Bluetooth Serial mobile app.
STEP 1: CIRCUITRY
STEP 2: CODE
- Start your Arduino IDE and copy the following code
char data = 0; //Variable for storing received data void setup() { Serial.begin(9600); //Sets the baud for serial data transmission pinMode(13, OUTPUT); //Sets digital pin 13 as output pin } void loop() { if(Serial.available() > 0) // Send data only when you receive data: { data = Serial.read(); //Read the incoming data & store into data Serial.print(data); //Print Value inside data in Serial monitor if(data == '1') // Checks whether value of data is equal to 1 digitalWrite(13, HIGH); //If value is 1 then LED turns ON else if(data == '0') // Checks whether value of data is equal to 0 digitalWrite(13, LOW); //If value is 0 then LED turns OFF } }
STEP 3: RESULTS
- Start the Serial Monitor and set the BAUD rate to 9600.
- In your Bluetooth Serial mobile app, type in 1/0 to turn on/off the LED
Wanna do more?
You can control things robots and and carry out home automation projects with your smart phone. Get a relay, Ā hereĀ and start to switch real loads.