Tag Archives: Wireless

HC-05 Serial Bluetooth Module interface with Arduino

HC‐05 bluetooth module is an easy to use Bluetooth SPP (Serial Port Protocol) module, designed for transparent wireless serial connection setup & can easily interface with Arduino. The HC-05 Bluetooth Module can be used in a Master or Slave configuration, making it a great solution for wireless communication, especially for Arduino. This serial port Bluetooth module is fully qualified Bluetooth V2.0+EDR (Enhanced Data Rate) 3 Mbps Modulation with complete 2.4 GHz radio transceiver and base-band. It uses CSR Bluecore 04External single chip Bluetooth system with CMOS technology and with AFH (Adaptive Frequency Hopping Feature).

HC05

The Bluetooth module HC-05 is a MASTER/SLAVE module. By default the factory setting is SLAVE. The Role of the module (Master or Slave) can be configured only by AT commands. The slave modules cannot initiate a connection to another Bluetooth device, but can accept connections. Master module can initiate a connection to other devices. The user can use it simply for a serial port replacement to establish connection between MCU and GPS, PC to your embedded project, etc. Refer Datasheet/User Manual & AT command’s list.

Features

  • Typical ‐80 dBm sensitivity
  • Up to +4Bm RF transmit power
  • 3.3 to 5 V I/O and RoHS Compliant
  • PIO (Programmable Input/Output) control
  • UART interface with programmable baud rate
  • Inbuilt/Integrated antenna
  • Auto‐connect to the last device on power as default
  • Permit pairing device to connect as default
  • Auto‐pairing pin code: ”1234” as default (which can be changed)
  • CSR Bluetooth Chip Solution
  • Bluetooth Spec v2.0 EDR Compliant with V2.0.E.2 of specification for both 2Mbps and 3Mbps modulation modes
  • Full Speed Bluetooth Operation with Full Piconet Support and Scatternet Support
  • Support for 8Mbit External Flash On-board
  • Support for 802.11 Coexistence

Pinout

HC05 Pin

State: It is status indicator pin. When the HC05 is not connected to or not paired with any other Bluetooth device, signal at this pin goes Low. During this state the on-board LED flashes continuously which indicates that the module is not paired with any device. When HC05 is paired or connected with any Bluetooth device, the pin status goes High. During this state, on-board LED blinks with a constant delay say for example 2 seconds delay which indicates that the module is paired.

RXD: Receive pin of UART interface for communication

TXD: Transmit pin of UART interface for communication

GND: Ground pin

Vcc: Supply voltage of 3.3V or 5VDC

Key (or EN): When this pin is high, the module is disabled & will not be connected with any module. When this pin is open or connected to ground or kept open, the module is enabled & it can be connected/communicate.

Apart from pins, you will find a small push button on HC05. When you press the button for 1 second, HC05 will enable AT command mode. During AT command mode you can change different parameters of HC05, but while changing parameters the HC05 shouldn’t be connected/paired with any device.

Arduino Connection

HC05 Arduino
Vcc 5V
GND GND
TXD D10
RXD D11

Normally, people connects HC05 TXD & RXD to Arduino RX(D0) & TX(D1), but in that case if you want to upload any code using USB port then you have to remove connection from D0 & D1 otherwise you will get code upload error. To avoid this issue there is one best solution as library called ‘SoftwareSerial’. Using  SoftwareSerial library we can configure any two DIO as Tx & Rx. In above connection diagram, HC05 Tx & Rx are connected to Arduino pins D10 & D11 which to be assigned as Rx & Tx respectively.

Arduino Code

You can download above code from here.

Explanation of code:

#include : As you can see SoftwareSerial library is included, it is available in Arduino IDE

SoftwareSerial BTserial(10, 11); : anyname(RX, TX); i’ve give name BTserial, D10 pin as RX & D11 as Tx

char data; : variable where incoming data will be stored, for better execution data will be first stored in a variable then will be processed.

Serial.begin(9600); begin serial communication with Arduino IDE

Serial.println(“Beat Your Bit”); print custom message on serial monitor to confirm serial communication has been initiated

BTserial.begin(9600); begin serial communication using dedicated pins (D10 & D11)

BTserial.println(“Beat Your Bit”); transmit custom message on HC05 paired device to confirm serial communication with HC05 has been initiated

if (BTserial.available()) [if any data available from HC05 then]
data=BTserial.read(); [store received data in ‘data’ variable]
Serial.print(data); [print received data on serial monitor of Arduino IDE]
if (Serial.available()) [if any data available from serial monitor then]
data=Serial.read(); [store received data in ‘data’ variable]
BTserial.print(data); [transmit received data on HC05]

As explained, this code exchanges data between HC05 and Arduino IDE serial monitor. We can see data received on serial monitor but to read the data received on HC05, we have to use an android app or any terminal application which can be connected with HC05 using Bluetooth. Here we are going to use android app to test Arduino-HC05 connection & data exchange. I used Arduino Bluetooth Control app which have many add on features & easy to use. It has serial terminal, arrow keys, buttons, slider, accelerometer & voice control features.

Connect circuit as shown in connection diagram, upload code and connect/pair HC05 with your smartphone. If you are using/pairing HC05 for first time then default pairing PIN may be 1234, you can change it later using AT commands. Open Arduino Bluetooth Control App & select paired HC05. Open terminal windows in app & serial monitor in Arduino IDE with mentioned baud-rate. Write any text in Arduino IDE serial monitor & press enter, you will receive same text in terminal window of Arduino Bluetooth Control app. Vice versa, write in app and send it to Arduino IDE serial monitor.

Change HC05 settings

You can change HC05 default settings like Bluetooth display name, pairing PIN, baud rate etc. As mentioned in Pin-out details, you have to put HC05 in AT command mode by pressing the push button while power up the module but make sure it is not connected with any other Bluetooth device.

How to put HC05 in AT command mode: 

1. Disconnect HC05 form power, Remove the +5V connection to HC05.
2. Press and hold the push button switch on HC05
3. Re-connect HC05 Vcc to +5V (while still pressing the button switch), HC05 on-board LED should turn ON.
4. Release the push button switch and the LED should be blinking at interval of two seconds. It indicates that your are now in AT command mode. Now open serial monitor & give AT commands from there.

Some useful AT commands:

AT : Simple feedback request. If communication is working fine then it will return “OK”

AT+VERSION : This returns the firmware version.
For Example:
“+VERSION:2.0-20100601
OK”

AT+STATE : This returns the current state of the module.
For Example:
“+STATE:INITIALIZED
OK”

AT+ROLE : Valid values are 0~Slave, 1~Master, 2~Slave-Loop.
Return example:
“+ROLE:0
OK”
(To change to Master Mode, enter AT+ROLE=1, returns “OK”)

AT+UART : It returns the baud rate used by the HC05 in communication mode. Default it will be 9600 mostly.
Return example:
“+UART:9600,0,0
OK”
(To change the baud rate to 19200 : AT+UART=19200,0,0. Returns “OK”)

AT+NAME : The command AT+NAME? only works in AT command mode. If HC05 is not responding on AT+NAME? then put HC05 in AT command mode as procedure mentioned in tutorial.
Return when AT+NAME? is given:
“+NAME:HC-05
OK”
(To change name : AT+NAME=BeatYourBit, Returns “OK”)

You can find all AT commands list from here.

I hope you liked this tutorial, now you can add Bluetooth interface in your project & expand the features. Further you can display values on display, data exchange with another wireless modules like RF & WiFi. Give your feedback about this tutorial in Contact, Your feedback will be appreciated.

Subscribe BYB on FacebookTwitterInstagram & Telegram for latest updates.

Infrared transmitter & receiver interface with Arduino

IR, or infrared, communication is a common, inexpensive, and easy to use wireless communication technology. IR light is very similar to visible light, except that it has a slightly longer wavelength. This means infrared is undetectable to the human eye which means perfect for wireless communication. For example, when you hit a button on your TV remote, an IR LED repeatedly turns on and off, 38,000 time a second, to transmit information (like volume or channel control) to an IR photo sensor on your TV. IR receiving is done by TSOP382 IR photo sensor & IR transmitting is part of IR LED. This tutorial will help you to interface IR sensor with your Arduino or DIY Project.

IR Kit

IR

IR LED is nothing but a normal LED transmitting infrared light with longer wavelength. TSOP382 is a device which combines an IR sensitive photocell, a 38 kHz bandpass filter, and automatic gain control. It operates on a variety of supply voltages including 3.3v and 5v. It de-modulates the received IR signal and gives you a nice clean square wave of off and on pulses at the voltage level of your power supply. This means it is ideal for feeding its output directly into the digital input pin of our Arduino. Last in the picture is IR receiver module with easy pinout for interface with any microcontroller.

TSOP module: It has an inbuilt control circuit for amplifying the coded pulses from the IR transmitter. A signal is generated when PIN photo-diode receives the signals. This input signal is received by an automatic gain control (AGC). For a range of inputs, the output is fed back to AGC in order to adjust the gain to a suitable level. The signal from AGC is passed to a band pass filter to filter undesired frequencies. After this, the signal goes to a demodulator and this demodulated output drives an npn transistor. The collector output of the transistor is obtained at pin 3 of TSOP module. Members of TSOP38xxx series are sensitive to different centre frequencies of the IR spectrum.

Career Frequency  Standard Applications (AGC2/AGC8) Very Noisy Environment (AGC4)
30 kHz TSOP38230 TSOP38430
33 kHz TSOP38233 TSOP32433
36 kHz TSOP38236 TSOP38436
38 kHz TSOP38238 TSOP38438
40 kHz TSOP38240 TSOP38440
56 kHz TSOP38256 TSOP38456

In TSOP1738xx series, last two digit indicates career frequency, ex: TSOP173838 = 38 kHz.

Specifications & Features

IR LED:

  • Forward current (IF) is 100mA (normal condition) and 300mA (max.)
  • 1.5A of surge forward current
  • 1.24v to 1.4v of forward voltage
  • Temperature for storage and operation varies from -40 to 100 ℃
  • Soldering Temperature should not exceed 260 ℃
  • Power Dissipation of 150mW at 25℃ (free air temperature) or below
  • Spectral bandwidth of 45nm
  • Viewing angle is 30 to 40 degree
  • Maximum wavelength is 940nm
  • RoHS certified

TSOP382 IR Receiver:

  • Very low supply current
  • Photo detector and pre-amplifier in one package
  • Internal filter for PCM frequency
  • Improved shielding against EMI
  • Supply voltage: 2.5 V to 5.5 V
  • Improved immunity against ambient light
  • Insensitive to supply voltage ripple and noise
  • Component in accordance to RoHS 2002/95/EC and WEEE 2002/96/EC

IR Receiver Connection With Arduino

As shown in figure, an IR receiver is connected with Arduino UNO. Here we will use an IR remote which is most commonly used for Arduino projects, in your project you can use any remote & can make your own remote as per application. In market you can get a kit which contains an IR Remote, IR Receiver, IR LED for you DIY purpose & jumper wires as shown in image.

Test Program For IR Remote

You can download above code from here.

Code explanation: Here we will use remote as shown in first image of tutorial which is easily available in market. You need IRremote library in this code which is available in library manager. IR receiver signal pin is connected to Pin 11 of Arduino. You need to define two variables; IRrecv irrecv(receiver);- to receive values from IR module, decode_results results;-to compare results value & print text accordingly.

You need to enable receiving using irrecv.enableIRIn(); in void setup() loop which runs in first cycle only. In void loop(), it continuously scans if IR module receives any signal. If it finds any signal then it calls translateIR() loop & then receives new value.

In translateIR() loop switch function is used which compares received value with preset values & print text accordingly. For example, When you press Up/Forward key on remote than remote will transmit a hex value FF629D which is received by IR module, compared in switch condition & print FORWARD in serial monitor. Each key has different value as per make. After printing it will complete the loop with delay of 500ms. Each key of remote has different hex value, you can try other remotes by removing switch condition & directly print hex value in serial monitor, for example;

You can download above code from here.

You can make your own IR remote using a keypad, IR LED & Arduino as per your requirement. Receive key value, compare it with preset & write value on IR LED. In that case you need to add ‘irsend.sendNEC(0x34895725, 32);}’ to transmit the value where 34895725 is the value to transmit & 32 is size of IR signal. For transmitter, IR LED must be connected in Pin 3 as it is defined in IRremote library. (All IR send & receive examples are available in IRremote library).

Device control using IR

You can control device using IR remote/transmitter easily. In this test code, we will control 4 outputs on pin 7, 6, 5 & 4 using numerical keys on IR remote.

You can download above code from here.

As shown in code, it compares received signal with preset values of IR remote control numeric key hex values. You can change the value according to your remote if you know hex values of each button, If you don’t know than use second code in tutorial which is IR remote test code & set it in #define functions.

I hope this tutorial will be helpful to use IR transmission & receiving in your DIY stuff. Give your feedback about this tutorial in Contact, Your feedback will be appreciated.

Subscribe BYB on FacebookTwitterInstagram & Telegram for latest updates.