X

Connecting Arduino Uno and the JY-MCU Bluetooth module using SoftwareSerial

JY-MCU-Bluetooth-Module-Arduino-Uno

My previous post covers the basics of setting up a Bluetooth connection between an Arduino Uno and an Android phone using the JY-MCU Bluetooth module. We connected the  JY-MCU Bluetooth module to the Arduino via a serial connection on (digital) pins 0 (rx) and 1 (tx).

This uses Arduino’s built in hardware support for serial communication (via something called UART) and requires no additional libraries. The Arduino has a 64 byte serial buffer and can receive and store data in it, while executing other tasks in your program. For some great examples of using serial communication, as well as wealth of other Arduino related info see Nick Gammon’s web-site.

There are a couple of downsides of this set-up for Bluetooth connectivity:

  • You cannot use the Arduino serial console for debugging your code in the Arduino IDE console anymore. This is because the same two Arduino pins used of serial communication with the module are needed to communicate with your computer, via the USB port.
  • For the same reason, you can’t program your Arduino, while the JY-MCU Bluetooth module is connected and powered.
  • Last, but not least: you can’t use the Arduino IDE serial console to configure some of the settings of the JY-MCU Bluetooth module (like name, default baud rate, pairing code etc.).

The SoftwareSerial library helps address these problems and comes pre-installed with the latest version of the Arduino IDE. It has been developed to allow multiple serial communication on (almost any) digital pin of the Arduino, using software to replicate Arduino’s native serial support. See the SoftwareSerial library page for more details on its functions and limitations.

Only a couple of changes are needed from our original Arduino / JY-MCU Bluetooth module set-up to implement SoftwareSerial:

  • Change the wiring to free up digital pins 0 and 1 and replace them with other pins supported by the SoftwareSerial library. I chose to use digital pins 2 and 4 on my Arduino Uno.
  • Modify our Arduino sketch to import and use the SoftwareSerial library and the alternative pins.

Here is a picture of the updated wiring. Note that I am still using a voltage divider to shift the TX signal from the Arduino to 3.3 volts, as in my previous post:

And here is the modified sketch.

As in the original post, you can use Blueterm to send 1, or 0 (zero) from your Android phone to the Arduino and switch the LED on or off.

Stan: