0

members

Easy Basics: Project 028b Bluetooth controlled LEDs with SoftwareSerial library and without library - Blu

of Lex C in UNO

Basics: Project 028b

Project name: Bluetooth controlled LEDs with SoftwareSerial library and without library - Bluetooth modules HC-05 and HC-06 ZS-40/FC-114

Tags: Bluetooth module, HC-05, HC-06, LED, ZS-40, FC-114, AT commands, LED control with smartphone, Android app, SoftwareSerial library, Software Serial

Attachments: sketchwithoutlibraryHC0506 and sketchsowtwareseriallibraryHC0506

In this project, you needed these parts :

1.Aruduino Uno R3 (you can also use the other version of Arduino)

2.Arduino IDE ( you can download it from here  )

3.Jumper cables F-M, M-M

4. Breadboard 1 pc

5. Bluetooth modules HC-05 or HC-06 1 pc

6. Resistor 4 pcs (1pc 1 KOhm, 1 pc 2KOhm, 5 pcs 220-470 Ohm)

4. LED (different colors , for example red, green, blue, white,yellow) 5 pc

5. Android app (you can download it here)

6. Smartphone or tablet with Android OS. We have used Samsung Galaxy GT-I9000 smartphone.

General

We will learn how to control LEDs with bluetooth modules HC-05 and HC-06.

How Does it Work?

There are three main parts to this project. An Android smartphone, a Bluetooth transceiver, and an Arduino.

HC 05/06 works on serial communication. The Android app is designed to send serial data to the Arduino Bluetooth module when a button is pressed on the app. The Arduino Bluetooth module at other end receives the data and sends it to the Arduino through the TX pin of the Bluetooth module(connected to RX pin of Arduino). The code uploaded to the Arduino checks the received data and compares it. If the received data is 1, the LED turns ON. The LED turns OFF when the received data is 0. You can open the serial monitor and watch the received data while connecting.

Understanding the bluetooth modules HC-05 and HC-06

You can read about them here.

Signals and connections of LED

Connect the long leg of the LED (the positive leg, called the anode) to the other end of the resistor. Connect the short leg of the LED (the negative leg, called the cathode) to the GND. Resistor connected for long leg.

The operating voltage of the LED is 1.8V and the operating current is 10mA-20mA. The Arduino Uno board can supply 5V or 3.3V power. We will use 5V for this project, so the minimum resistance of the current limiting resistor should be (5 V to 1.8 V)/20 = 160 Om. The 220 Om offered in the kit is suitable and you can also choose other resistors that meet the condition. The larger the resistance is, the dimmer the LED will get.

Signals and connections of bluetooth modules HC-05 and HC-06

FC-114:

ZS-40:

ZS-040 and FC-114 boards differ from some of the other modules in that they have a EN pin rather than a KEY pin. SEE EXAMPLE BELOW.


HC-05 Pins:

  • KEY (EN): If brought HIGH before power is applied, forces AT Command Setup Mode. LED blinks slowly (2 seconds)
  • VCC: +5 Power
  • GND: System / Arduino Ground
  • TXD: Transmit Serial Data from HC-05 to Arduino Serial Receive. NOTE: 3.3V HIGH level: OK for Arduino
  • RXD: Receive Serial Data from Arduino Serial Transmit
  • STATE: Tells if connected or not

HC-06 Pins:

  • VCC: +5 Power
  • GND: System / Arduino Ground
  • TXD: Transmit Serial Data from HC-05 to Arduino Serial Receive. NOTE: 3.3V HIGH level: OK for Arduino
  • RXD: Receive Serial Data from Arduino Serial Transmit
  • STATE: Does not have this pin
  • KEY(EN): Does not have this pin.

Build the circuit

The following picture shows the needed connections with the Arduino Uno 

1 step. AT mode (initial bluetooth setup)

2 step. For bluetooth modules HC-05 ZS-40 and FC-114 WITHOUT LIBRARY


2 step. For bluetooth modules HC-05 ZS-40 and FC-114 WITH SOFTWARE LIBRARY


3. For buetooth modules HC-06 ZS-40 and FC-114 WITHOUT LIBRARY

3. For buetooth modules HC-06 ZS-40 and FC-114 WITH  SOFWARE SERIAL LIBRARY


Step by Step instruction

Step 1. Initial bluetooth setup for bluetooth modules HC-05 FC-114 and ZS-40

  1. Do wiring for AT mode (Initial bluetooth setup) according to pictures above.
  2. Open Arduino IDE.
  3. Plug your Adruino Uno board into your PC and select the correct board and com port. 
  4. Open up serial monitor and set your baud to 38400 baud. Select “Both NL & CR” at the bottom of the window. 
  5. Always disconnect power from bluetooth module before verifying and uploading the sketch or you will get error messages
  6. Power off buetooth module
  7. Verify and upload the BAREMINIMUM sketch to your Adruino Uno board.
  8. To activate AT mode on the HC-05 zs-040 modules pin 34 needs to be HIGH on power up. The small push button switch on bluetooth module connects pin 34 to +3.3v so we can either:
    1. connect pin 34 directly to +3.3v and power on, or
    2. hold the button switch closed when starting the module.
    To activate AT mode on the HC-05 zs-040 modules pin 34 needs to be HIGH on power up  (see steps here). You can also do temporary wiring as shown on the picture below as it is quite easy.
  9. To activate AT mode on the HC-05 FC-114 modules pin 27 needs to be HIGH on power up  (see steps here). 
  10. Power on the bluetooth module.
  11. Open the serial monitor and check if AT commands are working - enter “AT” and press button Send. It can be writing ERROR (0) first, try to enter “AT” and press button Send again.
  12. Check the firmware version - enter “AT+VERSION” and press button Send.
  13. Check for a list of the available AT commands here.
  14. Enter “AT+STATE” and press button Send
  15. Enter “AT+ROLE” and press button Send. The possible values are ; 0 – Slave, 1 – Master, 2 – Slave-Loop. We need to set our bluetooth module as SLAVE - enter “AT+ROLE=0” and press button Send
  16. Enter “AT+PSWD” and press button Send. Returns with the set passkey (0000 or 1234):  “+PSWD:1234 OK”. If you want to change the passkey, enter “AT+PSWD=0000” and press button Send
  17. Enter “AT+UART” and press button Send. Returns the baud rate used by the HC-05 in communication mode. The default for the modules is 9600. 
  18. Enter “AT+NAME” and press button Send. Querying the modules name with “AT+NAME?” only works in “full” At mode. If you cannot get “AT+NAME?” to work you need to bring pin34 HIGH. Changing the modules name with “AT+NAME=newname” works in “full” AT mode and “mini” AT mode. 
  19. If you send AT command and do not get a response try to press the button above the EN pin on the bluetooth module and hold it pressed while you send the AT command. 
  20. The AT initial setup completed. Your Bluetooth module HC-05 is ready for operation.
  21. Power off Arduino board. Remove the temporary jumper cable attached to 3.3V Arduino board pin (if you used it).

Step 1. Initial bluetooth setup for bluetooth modules HC-06 FC-114 and ZS-40

  1. Do wiring for AT mode (Initial bluetooth setup) according to pictures above.
  2. Open Arduino IDE.
  3. Plug your Adruino Uno board into your PC and select the correct board and com port. 
  4. Open up serial monitor and set your baud to 9600 baud. Select “No line ending” at the bottom of the window. 
  5. Always disconnect power from bluetooth module before verifying and uploading the sketch or you will get error messages
  6. Power off buetooth module.
  7. Verify and upload the BAREMINIMUM sketch to your Adruino Uno board.
  8. The HC-06 enters AT mode as soon it is powered on.
  9. Wait a little before openiong the serial monitor (approx. 10-20 seconds) (see steps here).
  10. Open the serial monitor and check if AT commands are working - enter “AT” and press button Send. 
  11. Returns “OK”. AT is a basic communications test command that allows you to check the HC-06 is connected and communicating. If AT does not work try to enter it again in 10-15 seconds.
  12. Check the firmware version - enter “AT+VERSION” and press button Send. Returns  "OKlinvorV1.8". Firmware versions linvorV1.8 or hc01.comV2.0 are quite common for many HC-06s.
  13. Check the list of available commands here.
  14. The AT initial setup completed. Your Bluetooth module HC-06 is ready for operation.
  15. Power off Arduino board. Remove the temporary jumper cable attached to 3.3V Arduino board pin (if you used it).

Step 2. Preparing for and using LED control application

  1. Do wiring For bluetooth modules HC-05 or HC-06 (see pictures above)
  2. Open Arduino IDE.
  3. Plug your Adruino Uno board into your PC and select the correct board and com port.
  4. Open up serial monitor and set your baud to 9600 baud. Select “No line ending” at the bottom of the window. 
  5. Always disconnect power from bluetooth module before verifying and uploading the sketch or you will get error messages
  6. Power off bluetooth module.
  7. Verify and upload the sketchwithoutlibrary or sketchwithSoftwareserial library to your Adruino Uno board.
  8. Re-apply power to bluetooth module.
  9. Download, upload and install SmartduinoControl.apk to your smartphone or tablet with Android OS. We have used Samsung Galaxy S GT-I9000 smartphone.
  10. Pair your smartphone with the HC 05/06 Bluetooth module. Scan your smartphone for available devices on your smartphone, for example: Application->Settings->Wireless and network->Bluetooth settings->Bluetooth ON->Scan devices->
  11. Pair your smartphone to the HC 05/06 by entering default password 1234 or 0000. You will see your bluetooth module with status paired but not connected.
  12. Open the Smartduino Control application.
  13. Select LED control->Connect to bluetooth->Select from the lsit of devices your bluetooth module->the status will change to connected.
  14. Congrats, your are able to control your Arduino digital pins with LEDs attached to them - just press buttons ON/OFF.

Summary

We have learnt how to control LEDs with bluetooth modules HC-05 and HC-06 (ZS-40, FC-114) from smartphone/tablet with and without Software library.

Library:

  • SoftwareSerial library included in Arduino IDE. The version of SoftwareSerial included in Arduino IDE 1.0 and later is based on the NewSoftSerial library by Mikal Hart. You can also read about it here

Sketch:

  • See attachments on the begining of this project description. 


Other projects of Lex C
Easy Basics: Project 057a ACR122U NFC Reader of Lex C, Not selected 17-01-2018

Published at 09-11-2017
Viewed: 1839 times