0% found this document useful (0 votes)
309 views79 pages

Bluetooth Control DC Motor 1

The document discusses using an Arduino board to control a DC motor via Bluetooth. It begins with an introduction to Arduino boards, their components, and how they can be programmed. It then discusses the specific Arduino Uno board and how it works. Finally, it explains that the tutorial will teach how to use an Arduino board and Bluetooth to control the speed and direction of a DC motor.

Uploaded by

jp2udhaya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
309 views79 pages

Bluetooth Control DC Motor 1

The document discusses using an Arduino board to control a DC motor via Bluetooth. It begins with an introduction to Arduino boards, their components, and how they can be programmed. It then discusses the specific Arduino Uno board and how it works. Finally, it explains that the tutorial will teach how to use an Arduino board and Bluetooth to control the speed and direction of a DC motor.

Uploaded by

jp2udhaya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 79

Bluetooth control dc motor

Introduction

Arduino is an open-source platform used for building electronics projects.

Arduino consists of both a physical programmable circuit board (often referred

to as a microcontroller) and a piece of software, or IDE (Integrated

Development Environment) that runs on your computer, used to write and

upload computer code to the physical board.

The Arduino platform has become quite popular with people just starting out

with electronics, and for good reason. Unlike most previous programmable

circuit boards, the Arduino does not need a separate piece of hardware (called a

programmer) in order to load new code onto the board – you can simply use a

USB cable. Additionally, the Arduino IDE uses a simplified version of C++,

making it easier to learn to program. Finally, Arduino provides a standard form

factor that breaks out the functions of the micro-controller into a more

accessible package.
This is an Arduino Uno

The Uno is one of the more popular boards in the Arduino family and a great

choice for beginners. We’ll talk about what’s on it and what it can do later in

the tutorial.
This is a screenshot of the Arduino IDE.

Believe it or not, those 10 lines of code are all you need to blink the on-board

LED on your Arduino. The code might not make perfect sense right now, but,

after reading this tutorial and the many more Arduino tutorials waiting for you

on our site, we’ll get you up to speed in no time!

You Will Learn


In this tutorial, we’ll go over the following:

 What projects can be accomplished using an Arduino

 What is on the typical Arduino board and why

 The different varieties of Arduino boards

 Some useful widgets to use with your Arduino

Suggested Reading

Arduino is a great tool for people of all skill levels. However, you will have a

much better time learning along side your Arduino if you understand some basic

fundamental electronics beforehand. We recommend that you have at least a

decent understanding of these concepts before you dive in to the wonderful

world of Arduino.

 What is Electricity?

 Voltage, Current, Resistance, and Ohm’s Law

 What is a Circuit?

 Polarity

 Integrated Circuits (ICs)

 Logic Levels

 Digital Logic

 Analog vs. Digital


What Does it Do?

The Arduino hardware and software was designed for artists, designers,

hobbyists, hackers, newbies, and anyone interested in creating interactive

objects or environments. Arduino can interact with buttons, LEDs, motors,

speakers, GPS units, cameras, the internet, and even your smart-phone or your

TV! This flexibility combined with the fact that the Arduino software is free,

the hardware boards are pretty cheap, and both the software and hardware are

easy to learn has led to a large community of users who have contributed code

and released instructions for a huge variety of Arduino-based projects.

For everything from robots and a heating pad hand warming blanket to honest

fortune-telling machines, and even a Dungeons and Dragons dice-throwing

gauntlet, the Arduino can be used as the brains behind almost any electronics

project.

And that’s really just the tip of the iceberg – if you’re curious about where to

find more examples of Arduino projects in action, here are some good resources

for Arduino-based projects to get your creative juices flowing:

 Instructables

 Bildr

 Arduino Playground

 The ITP Physical Computing Wiki


 LadyAda

 Make: Projects

 and, of course, you can find plenty more Arduino tutorials here at

learn.sparkfun.com.

What's on the board?

There are many varieties of Arduino boards (explained on the next page) that

can be used for different purposes. Some boards look a bit different from the

one below, but most Arduinos have the majority of these components in

common:
Power (USB / Barrel Jack)

Every Arduino board needs a way to be connected to a power source. The

Arduino UNO can be powered from a USB cable coming from your computer

or a wall power supply (like this) that is terminated in a barrel jack. In the

picture above the USB connection is labeled (1) and the barrel jack is labeled

(2).
The USB connection is also how you will load code onto your Arduino board.

More on how to program with Arduino can be found in our Installing and

Programming Arduino tutorial.

NOTE: Do NOT use a power supply greater than 20 Volts as you will

overpower (and thereby destroy) your Arduino. The recommended voltage for

most Arduino models is between 6 and 12 Volts.

Pins (5V, 3.3V, GND, Analog, Digital, PWM, AREF)

The pins on your Arduino are the places where you connect wires to construct a

circuit (probably in conjuction with a breadboard and some wire. They usually

have black plastic ‘headers’ that allow you to just plug a wire right into the

board. The Arduino has several different kinds of pins, each of which is labeled

on the board and used for different functions.

 GND (3): Short for ‘Ground’. There are several GND pins on the

Arduino, any of which can be used to ground your circuit.

 5V (4) & 3.3V (5): As you might guess, the 5V pin supplies 5 volts of

power, and the 3.3V pin supplies 3.3 volts of power. Most of the simple

components used with the Arduino run happily off of 5 or 3.3 volts.

 Analog (6): The area of pins under the ‘Analog In’ label (A0 through A5

on the UNO) are Analog In pins. These pins can read the signal from an
analog sensor (like a temperature sensor) and convert it into a digital

value that we can read.

 Digital (7): Across from the analog pins are the digital pins (0 through 13

on the UNO). These pins can be used for both digital input (like telling if

a button is pushed) and digital output (like powering an LED).

 PWM (8): You may have noticed the tilde (~) next to some of the digital

pins (3, 5, 6, 9, 10, and 11 on the UNO). These pins act as normal digital

pins, but can also be used for something called Pulse-Width Modulation

(PWM). We have a tutorial on PWM, but for now, think of these pins as

being able to simulate analog output (like fading an LED in and out).

 AREF (9): Stands for Analog Reference. Most of the time you can leave

this pin alone. It is sometimes used to set an external reference voltage

(between 0 and 5 Volts) as the upper limit for the analog input pins.

Reset Button

Just like the original Nintendo, the Arduino has a reset button (10). Pushing it

will temporarily connect the reset pin to ground and restart any code that is

loaded on the Arduino. This can be very useful if your code doesn’t repeat, but

you want to test it multiple times. Unlike the original Nintendo however,

blowing on the Arduino doesn’t usually fix any problems.

Power LED Indicator


Just beneath and to the right of the word “UNO” on your circuit board, there’s a

tiny LED next to the word ‘ON’ (11). This LED should light up whenever you

plug your Arduino into a power source. If this light doesn’t turn on, there’s a

good chance something is wrong. Time to re-check your circuit!

TX RX LEDs

TX is short for transmit, RX is short for receive. These markings appear quite a

bit in electronics to indicate the pins responsible for serial communication. In

our case, there are two places on the Arduino UNO where TX and RX appear –

once by digital pins 0 and 1, and a second time next to the TX and RX indicator

LEDs (12). These LEDs will give us some nice visual indications whenever our

Arduino is receiving or transmitting data (like when we’re loading a new

program onto the board).

Main IC

The black thing with all the metal legs is an IC, or Integrated Circuit (13). Think

of it as the brains of our Arduino. The main IC on the Arduino is slightly

different from board type to board type, but is usually from the ATmega line of

IC’s from the ATMEL company. This can be important, as you may need to

know the IC type (along with your board type) before loading up a new program

from the Arduino software. This information can usually be found in writing on
the top side of the IC. If you want to know more about the difference between

various IC’s, reading the datasheets is often a good idea.

Voltage Regulator

The voltage regulator (14) is not actually something you can (or should) interact

with on the Arduino. But it is potentially useful to know that it is there and what

it’s for. The voltage regulator does exactly what it says – it controls the amount

of voltage that is let into the Arduino board. Think of it as a kind of gatekeeper;

it will turn away an extra voltage that might harm the circuit. Of course, it has

its limits, so don’t hook up your Arduino to anything greater than 20 volts.

The Arduino Family

Arduino makes several different boards, each with different capabilities. In

addition, part of being open source hardware means that others can modify and

produce derivatives of Arduino boards that provide even more form factors and

functionality. If you’re not sure which one is right for your project, check this

guide for some helpful hints. Here are a few options that are well-suited to

someone new to the world of Arduino:

Arduino Uno (R3)

The Uno is a great choice for your first Arduino. It’s got everything you need to

get started, and nothing you don’t. It has 14 digital input/output pins (of which 6
can be used as PWM outputs), 6 analog inputs, a USB connection, a power jack,

a reset button and more. It contains everything needed to support the

microcontroller; simply connect it to a computer with a USB cable or power it

with a AC-to-DC adapter or battery to get started.

LilyPad Arduino

This is LilyPad Arduino main board! LilyPad is a wearable e-textile technology

developed by Leah Buechley and cooperatively designed by Leah and

SparkFun. Each LilyPad was creatively designed with large connecting pads

and a flat back to allow them to be sewn into clothing with conductive thread.

The LilyPad also has its own family of input, output, power, and sensor boards

that are also built specifically for e-textiles. They’re even washable!
RedBoard

At SparkFun we use many Arduinos and we’re always looking for the simplest,

most stable one. Each board is a bit different and no one board has everything

we want – so we decided to make our own version that combines all our

favorite features.

The RedBoard can be programmed over a USB Mini-B cable using the Arduino

IDE. It’ll work on Windows 8 without having to change your security settings

(we used signed drivers, unlike the UNO). It’s more stable due to the

USB/FTDI chip we used, plus it’s completely flat on the back, making it easier

to embed in your projects. Just plug in the board, select “Arduino UNO” from
the board menu and you’re ready to upload code. You can power the RedBoard

over USB or through the barrel jack. The on-board power regulator can handle

anything from 7 to 15VDC.

Arduino Mega (R3)

The Arduino Mega is like the UNO’s big brother. It has lots (54!) of digital

input/output pins (14 can be used as PWM outputs), 16 analog inputs, a USB

connection, a power jack, and a reset button. It contains everything needed to

support the microcontroller; simply connect it to a computer with a USB cable

or power it with a AC-to-DC adapter or battery to get started. The large number
of pins make this board very handy for projects that require a bunch of digital

inputs or outputs (like lots of LEDs or buttons).

Arduino Leonardo

The Leonardo is Arduino’s first development board to use one microcontroller

with built-in USB. This means that it can be cheaper and simpler. Also, because

the board is handling USB directly, code libraries are available which allow the

board to emulate a computer keyboard, mouse, and more!


The Extended Family

While your Arduino board sure is pretty, it can’t do a whole lot on its own –

you’ve got to hook it up to something. There are lots of tutorials here on learn

as well as the links back in the ‘What does it do’ section, but rarely do we talk

about the general kinds of things you can easily hook into. In this section we’ll

introduce basic sensors as well as Arduino shields, two of the most handy tools

to use in bringing your projects to life.

Sensors
With some simple code, the Arduino can control and interact with a wide

variety of sensors - things that can measure light, temperature, degree of flex,

pressure, proximity, acceleration, carbon monoxide, radioactivity, humidity,

barometric pressure, you name it, you can sense it!

Just a few of the sensors that are easily compatible with Arduino

Shields
Additionally, there are these things called shields – basically they are pre-built

circuit boards that fit on top of your Arduino and provide additional capabilities

– controlling motors, connecting to the internet, providing cellular or other

wireless communication, controlling an LCD screen, and much more.

Proposed circuit diagram


Circuit components list

1x Arduino Uno

1x Bluetooth Module (for example: HC-05)

1x Smartphone (any Android will work)

BlueTerm application

1x L293D IC

1x DC motor

1x Breadboard

Jumper Cables

Program

/*

* created by Rui Santos, http://randomnerdtutorials.wordpress.com

* Control DC motor with Smartphone via bluetooth

* 2013

*/

int motorPin1 = 3; // pin 2 on L293D IC

int motorPin2 = 4; // pin 7 on L293D IC

int enablePin = 5; // pin 1 on L293D IC

int state;
int flag=0; //makes sure that the serial only prints once the state

void setup() {

// sets the pins as outputs:

pinMode(motorPin1, OUTPUT);

pinMode(motorPin2, OUTPUT);

pinMode(enablePin, OUTPUT);

// sets enablePin high so that motor can turn on:

digitalWrite(enablePin, HIGH);

// initialize serial communication at 9600 bits per second:

Serial.begin(9600);

void loop() {

//if some date is sent, reads it and saves in state

if(Serial.available() > 0){

state = Serial.read();

flag=0;

// if the state is '0' the DC motor will turn off

if (state == '0') {

digitalWrite(motorPin1, LOW); // set pin 2 on L293D low


digitalWrite(motorPin2, LOW); // set pin 7 on L293D low

if(flag == 0){

Serial.println("Motor: off");

flag=1;

// if the state is '1' the motor will turn right

else if (state == '1') {

digitalWrite(motorPin1, LOW); // set pin 2 on L293D low

digitalWrite(motorPin2, HIGH); // set pin 7 on L293D high

if(flag == 0){

Serial.println("Motor: right");

flag=1;

// if the state is '2' the motor will turn left

else if (state == '2') {

digitalWrite(motorPin1, HIGH); // set pin 2 on L293D high

digitalWrite(motorPin2, LOW); // set pin 7 on L293D low

if(flag == 0){

Serial.println("Motor: left");

flag=1;
}

Dc motor

What is DC Motor ?

Electrical motors are everywhere

around us. Almost all the electro-mechanical movements we see around us are

caused either by an A.C. or a DC motor. Here we will be exploring this kind of

motors. This is a device that converts DC electrical energy to a mechanical

energy.
Principle of DC Motor

This DC or direct current motor works on the principal, when a current

carrying conductor is placed in a magnetic field, it experiences a torque and has

a tendency to move. This is known as motoring action. If the direction of

current in the wire is reversed, the direction of rotation also reverses. When

magnetic field and electric field interact they produce a mechanical force, and

based on that the working principle of dc motor established.

The direction of rotation of a this motor

is given by Fleming’s left hand rule, which states that if the index finger, middle

finger and thumb of your left hand are extended mutually perpendicular to each

other and if the index finger represents the direction of magnetic field, middle
finger indicates the direction of current, then the thumb represents the direction

in which force is experienced by the shaft of the dc motor.

Structurally and construction wise a direct current motor is exactly similar to a

DC generator, but electrically it is just the opposite. Here we unlike a generator

we supply electrical energy to the input port and derive mechanical energy from

the output port. We can represent it by the block diagram shown below.

Here in a DC motor, the supply voltage E and current I is given to the electrical

port or the input port and we derive the mechanical output i.e. torque T and

speed ω from the mechanical port or output port.

The input and output port variables of the direct current motor are related by

the parameter K.
So from the picture above we can well understand that motor is just the opposite

phenomena of a DC generator, and we can derive both motoring and generating

operation from the same machine by simply reversing the ports.

Detailed Description of a DC Motor

To understand the DC motor in details lets consider the diagram below,

The direct current motor is represented by the circle in the center, on which is

mounted the brushes, where we connect the external terminals, from where

supply voltage is given. On the mechanical terminal we have a shaft coming out

of the Motor, and connected to the armature, and the armature-shaft is coupled

to the mechanical load. On the supply terminals we represent the armature

resistance Ra in series. Now, let the input voltage E, is applied across the

brushes. Electric current which flows through the rotor armature via brushes, in
presence of the magnetic field, produces a torque Tg . Due to this torque Tg the

dc motor armature rotates. As the armature conductors are carrying currents and

the armature rotates inside the stator magnetic field, it also produces an emf Eb

in the manner very similar to that of a generator. The generated Emf E b is

directed opposite to the supplied voltage and is known as the back Emf, as it

counters the forward voltage.

The back emf like in case of a generator is represented by

Where, P = no of poles

φ = flux per pole

Z= No. of conductors

A = No. of parallel paths

and N is the speed of the DC Motor.

So from the above equation we can see E b is proportional to speed ‘N’. That is

whenever a direct current motor rotates, it results in the generation of back Emf.

Now lets represent the rotor speed by ω in rad/sec. So Eb is proportional to ω.


So when the speed of the motor is reduced by the application of load, E b

decreases. Thus the voltage difference between supply voltage and back emf

increases that means E − Eb increases. Due to this increased voltage difference,

armature current will increase and therefore torque and hence speed increases.

Thus a DC Motor is capable of maintaining the same speed under variable load.

Now armature current Ia is represented by

Now at starting,speed ω = 0 so at starting Eb = 0.

Now since the armature winding electrical resistance Ra is small, this motor has

a very high starting current in the absence of back Emf. As a result we need to

use a starter for starting a DC Motor.

Now as the motor continues to rotate, the back Emf starts being generated and

gradually the current decreases as the motor picks up spee


HC-06 Bluetooth Module

DX.com Bluetooth Module (HC-06)

That module comes already on a carrier, so I assumed I can use the same driver

as for my other module. I was wrong :-(.

HC-05 or HC-06

My earlier module which I received from another source (without an adapter,

see this post) has a different firmware on it, known as HC-05, while my

DX.com module has a HC-06 firmware. To be clear: the modules are the same,
but the software/firmware on it is different, and the firmware uses the pins

differently too :-(

HC-06 and HC-05 (Source Wavesen Data Sheet)

:idea: Check out this post which explains how to re-program the firmware of the

device with firmware programming adapter:

http://byron76.blogspot.ch/2011/09/hc05-firmware.html

The HC-05 has the ‘full’ firmware on it: many AT commands, and can be both

master and slave module. The HC-06 firmware on the other hand only can be a

slave device, with very limited AT commands.

Or in other words:
 The HC-05 module can build a connection to other modules. E.g. a Robot

being a master and connecting to slave bluetooth module. Or in slave

mode to make a wireless bridge to a notebook.

 The HC-06 module only can be a slave. This makes it only useful for say

connecting a notebook as a master to a robot with a slave module e.g. for

a wireless serial bridge.

For most use cases the HC-06 is enough, as typically I want to have a wireless

UART connection to my devices from my notebook.

JY-MCU V1.5 Module

Below is an image of the JY-MCU HC-06 (JY-MCU V1.5) module. The

module came with a 4-pin header, and I have added the pins for STATE and

KEY, and removed the plastic around the module to get access to the pins:

HC-06 Top Side


Pins

On the bottom side there are labels for the signal direction and voltage levels:

JY-MCU BT_BOARD V1.05 Bottom Side

 KEY: according to the data sheet, I need to pull-up this pin while power-

on-reset of the module to enforce AT mode. I have not been able to verify

this yet. I have been told that some modules have this pin not connected

at all?

 VCC is indicated in the range of 3.6V-6V. The module worked for me

both with 3.3V and 5V.

 GND: Ground

 TXD: serial output of the module, to be connected to RX of the

microcontroller. Note that this signal is using 3.3V logic level


 RXD: serial input of the module, to be connected to the TX of the

microcontroller. Note that this signal is using 3.3V logic levels.

 STATE: connected to LED2 (Pin32) of the module, but no meaning? At

least on my module the pin was always low, regardless if paired or not.

Different AT commands

On the HC-05 module, I send “AT\r\n” to the device, and then it responds with

“OK\r\n”.

But on the HC-06, the protocol is different :-( I need to send “AT” (without the

new-line characters), and I receive “OK” (without the new-line characters).

The logic analyzer shows this behaviour too: AT command sent to the device:

AT Command sent to Device

OK response from the device with no “\r\n” at the end:


OK Response from the Device

The missing “\r\n” is present for all commands of the HC-06 firmware. As as

this is not enough, there are very few command possible. The table below

shows all the HC-06 firmware commands with the response:

Command Response Comment

AT OK Used to verify communication

The firmware version (version might depend on


AT+VERSION OKlinvorV1.8
firmware)

AT+NAMExyz OKsetname Sets the module name to “xyz”

AT+PIN1234 OKsetPIN Sets the module PIN to 1234

AT+BAUD1 OK1200 Sets the baud rate to 1200

AT+BAUD2 OK2400 Sets the baud rate to 2400

AT+BAUD3 OK4800 Sets the baud rate to 4800

AT+BAUD4 OK9600 Sets the baud rate to 9600

AT+BAUD5 OK19200 Sets the baud rate to 19200


AT+BAUD6 OK38400 Sets the baud rate to 38400

AT+BAUD7 OK57600 Sets the baud rate to 57600

AT+BAUD8 OK115200 Sets the baud rate to 115200

AT+BAUD9 OK230400 Sets the baud rate to 230400

AT+BAUDA OK460800 Sets the baud rate to 460800

AT+BAUDB OK921600 Sets the baud rate to 921600

AT+BAUDC OK1382400 Sets the baud rate to 1382400

That’s it.

Firmware Timing

As this is not enough, my driver did not work even with the new commands

implemented. The HC-05 firmware as sending a response back in less than 300

ms, while the HC-06 firmware needs more than 500 ms until there is a response:

Delay between Command and Response

So for this I had to introduce a user configurable delay in the component.


Processor Expert Component

With this knowledge, the Processor Expert Bluetooth component has been

updated to support both the HC-05 and HC-06 firmware:

Bluetooth Component Supporting HC-05 and HC-06

 Firmware to select between HC-05 and HC-06

 Configurable Response Time if the module needs longer for commands

 Optional State and CMD pins

If the HC-05 firmware is selected, then the component automatically disables

the functionality methods not present/supported in the firmware (grayed out

methods):
Bluetooth Module Methods

Command Line Interface

The Processor Expert component features an optional command line interface:

HC-06 Shell Commands

With this, I can change the pairing pin, device name or baud, beside of sending

AT commands or sending a string over the wireless bridge.

:idea: Changing the pairing/name/baud will be effective after resetting the

device. Keep in mind if you change the baud, this will change the baud as well

between the module and the microcontroller.


The ‘status’ command issues an AT command to the device to see if it responds,

plus shows the firmware version:

BT1 Status with Module Firmware

:!: Status and AT commands can only be used if the device is not paired yet

(means: while the red LED is blinking).

Connecting to the Bluetooth Module

The Bluetooth module runs the SPP (Serial Protocol over Bluetooth) protocol.

So any device supporting SPP can connect to it. On a PC this looks like a virtual

COM port. I show here the steps for Windows (running Windows 7).

:!: It seems that Apple (iPhone, iPAD, etc) does *not* support SPP, so

connecting with an iPhone is not possible.  Android (which I did not try) should

work, or any PC machine with Bluetooth.

Before connecting, make sure the module is powered and ready to pair. The red

LED on the module indicates the status:


 blinking: ready to pair

 steady on: paired

From the Device Manager, select ‘Add a Device':

Device Manager with Add a Device

Then the new device should show up:


Add a device Dialog

:idea: the name of the device shows here for me ‘blue1′, as I have named it as

such. But it might show up for you as ‘linvor’ (default) or ‘other’.

Select the device and press ‘Next’.  In the next dialog select ‘Enter the device’s

pairing code':

Enter the device’s paring code

The default pairing code is 1234:


Enter the pairing code for the device

Pressing next, and device drivers will be installed:

Installing device drivers

Then the device is ready to use:


Your Device is ready to use

And the confirmation dialog shows up:

This device has been successfully added to this computer

COM Port used by Device

Checking the properties on the newly added device shows that it supports SPP.

And it shows the virtual COM port used:


Device Services

:!: Note that if I check the COM ports in the device manager, then I see that

actually two COM ports have been added. Only the one shown above with the

SPP protocol will work. It is unclear to me why there is a second port?

Connecting to the Wireless Bluetooth Bridge

Using that COM port shown for the SPP service, I can connect with a terminal

program on the host PC to my board. Basically this gives me a wireless bridge

over Bluetooth to my board. So from my PC I can open a terminal window and


type in some commands, which are parsed by the Shell on the FRDM board,

and it responds back to the terminal on the PC:

Wireless Bluetooth Bridge Connection

:!: Make sure you use the COM port used for the SPP service, and that it

matches the baud settings of the communication between the microcontroller

and the Bluetooth module. I’m using above the default of 9600 baud. It is

possible to change/increase the baud as explained above, as 9600 is not very


fast. Only be sure that you not exceed the baud to a value which cannot be

handled by your PC. It should work ok up to a baud of 115200.

Once connected, the red LED on the Bluetooth module is always on.

Pairing LED

While connected, the module is in ‘transparent’ mode, and does not accept AT

commands. Below is an example where I try to send an AT command from the

microcontroller while the Bluetooth module is connected to the host PC:


Trying to send AT commands from the microcontroller while connected to PC

Instead, what I send to the UART ends up transparently on the host PC:

Bluetooth Module in Transparent Mode

Wireless Bridge

Everything I send to the virtual COM port ends up on the Bluetooth module,

which then sends the commands to the microcontroller using the RX and TX

connection between the microcontroller and the module. With this, it is very
easy to send/receive commands using the Processor Expert Shell component,

and the implementation are just a few lines:

1 /**

2  * \file

3  * \brief This is the implementation module for the shell

4  * \author Erich Styger

5  *

6  * This interface file is used for a console and terminal.

7  * That way we can interact with the target and change settings using a shell

implementation.
8

 */
9

 
1

0 #include "Shell.h"

1 #include "CLS1.h"

1
#include "LEDR.h"

1
#include "LEDG.h"
2
#include "LEDB.h"
1
3 #include "BT1.h"

1  

4
static const CLS1_ParseCommandCallback CmdParserTable[] =

1
{
5
  CLS1_ParseCommand,
1
#if LEDR_PARSE_COMMAND_ENABLED
6

  LEDR_ParseCommand,
1

7 #endif

1 #if LEDG_PARSE_COMMAND_ENABLED

8
  LEDG_ParseCommand,

1
#endif
9
#if LEDB_PARSE_COMMAND_ENABLED
2
  LEDB_ParseCommand,
0
#endif
2

1 #if BT1_PARSE_COMMAND_ENABLED

2   BT1_ParseCommand,

2
2 #endif

3
  NULL /* sentinel */

2
};
4
 
2
/* Bluetooth stdio */
5

static CLS1_ConstStdIOType BT_stdio = {


2

6   (CLS1_StdIO_In_FctType)BT1_StdIOReadChar, /* stdin */

2   (CLS1_StdIO_OutErr_FctType)BT1_StdIOSendChar, /* stdout */

7
  (CLS1_StdIO_OutErr_FctType)BT1_StdIOSendChar, /* stderr */

2
  BT1_StdIOKeyPressed /* if input is not empty */
8
};
2
 
9
void SHELL_Run(void) {
3

0   unsigned char buf[32];

3   unsigned char bTbuf[32];

1  

3
2   buf[0]='\0';

3   bTbuf[0]='\0';

3
  CLS1_ParseWithCommandTable((unsigned char*)CLS1_CMD_HELP,

3 CLS1_GetStdio(), CmdParserTable);

4
  for(;;) {

3
    (void)CLS1_ReadAndParseWithCommandTable(buf, sizeof(buf),
5
CLS1_GetStdio(), CmdParserTable);

3
    (void)CLS1_ReadAndParseWithCommandTable(bTbuf, sizeof(bTbuf),
6
&BT_stdio, CmdParserTable);

3
  }
7
}
3

1
4

5
1

Unbinding and Trouble Shooting

In case there are issues with connecting to the module, it is necessary to unbind

and re-bind (connect) to the module. It happened to me sometimes I’m able to

connect once, but then not any more. In that case the following steps help:

1. Close any terminal program potentially connected to the Bluetooth virtual

COM port.

2. Unpower the Bluetooth module so it is not visible any more to the PC.

3. Right click on the device in the Windows Device manager (or Devices

and Printer group) and select ‘Remove Device':


Unbinding Bluetooth Device

4. Re-power the module: the red LED shall be blinking as not connected.

5. Search for the device in the device manager (as above), and connect again

to the device with a pairing pin.

6. Connect to the module using the COM port specified for the SPP service.

That way I was always able to recover connection to my module. See as well

this post which helped me to solve my problem.

Blueterm Android App


  By Joseph Dattilo August 5, 2014 business and education



 0
inShare

Working in the Electronics industry, particularly with Arduino boards, and the
Virtuabotix BT2S Slave (Bluetooth 2 Serial) it didn’t take long before the need
for a Bluetooth terminal application on the phone became a serious need for me.
After having used many different Bluetooth serial terminal applications on the
Android OS Blueterm has become one of my favorite Utility applications for
Arduino/Versalino projects.

How it works
Retrieved 4 August 2014 from https://play.google.com/store/apps/details?
id=es.pymasde.blueterm&hl=en

The Blueterm App is simply put a Serial Terminal for your Android Phone or
Tablet. It provides many of the basic features you have come to expect from a
standard Serial Terminal on a PC. The big difference is that it is on your Phone
or Tablet, and that it is designed specifically to work with Bluetooth to Serial
devices. It doesn’t emulate web terminal, SSH, or other options that you might
find on the drop down menu in TeraTerm or Hyperterminal.

Once you have the application installed you simply click the options button and
connect to the appropriate device (such as HC-05/HC-06 in the case of the
Virtuabotix BT2S Slave) and enter the pairing code (1234 in the case of the
BT2S Slave default) and complete the pairing process.

Once properly paired you will see a blue screen that is actually a text field
where inbound data can be seen. Clicking on the textfield will allow you to send
data through your bluetooth device as if it was physically connected to a
computer.

Pros

 Works well on Android phones and Tablets


 Supports tons of Bluetooth Serial devices (Bluetooth 2.0, 3.0, 4.0 etc)
 Allows monitoring and transmission of data to and from Bluetooth Serial
devices

Cons
 Only works on the Android OS
 Does not support Macros, or instant commands
 Has limited support for pairing memorization

Android phone

Android is now over six years old and despite the green robot android peeking
out of phone shops up and down the highstreet, there are still those who don’t
know what it is or what it’s all about.

If you fit into this category then have no fear, this article is your guide to
understanding Android and what to expect when you see the little green guy on
a product or device.

What is Android?

Android is the name of the mobile operating system made by American


company; Google. It most commonly comes installed on a variety of
smartphones and tablets from a host of manufacturers offering users access to
Google’s own services like Search, YouTube, Maps, Gmail and more.
This means you can easily look for information on the web, watch videos,
search for directions and write emails on your phone, just as you would on your
computer, but there’s more to Android than these simple examples.

What can an Android phone do?

Android phones are highly customisable and as such can be altered to suit your
tastes and needs with wallpapers, themes and launchers which completely
change the look of your device's interface. You can download applications to do
all sorts of things like check your Facebook and Twitter feeds, manage your
bank account, order pizza and play games. You can plan events on from your
phone's calendar and see them on your computer or browse websites on your
desktop and pick them up on your phone.

Another neat feature of Android is that it automatically backs up your contacts


for you. When you set up an Android phone you’ll need to create a Google
Account or sign in with an existing one. Every time you save a number to the
address book of your Android phone it will be synced to your Google Account.

The benefit of this is that if you lose your phone all of your numbers will be
saved. The next time you get an Android phone (or and iPhone or Windows
Phone if you prefer) and sign in with your Google Account, all of your contacts
and friend's numbers will be displayed in your new phone’s address book
immediately, no need to transfer or back them up anywhere else.

Syncing is a way for your phone to keep all your information; websites,
contacts, calendar entries and apps up-to-date. This can happen over your
phone's mobile data or WiFi connection, seamlessly, in the background.

What apps can I get on an Android phone?

There are hundreds of thousands of apps and games available to download from
the Google Play store (formerly the Android Market). There are camera apps
that allow you to take pictures with artistic effects and filters on them and music
players which allow you to stream music from the web or create playlists. You
can customise the appearance of your Android handset with a number of
wallpapers based on pictures you’ve taken yourself or downloaded from the
internet too.
An example of a widget on the homescreen of an Android phone. This one let's
you access music playback from Spotify without having to open the application.

There are also various on-screen widgets to download which allow access to
and the alteration of settings on your phone, without the need to dive through
menus as you would on non-Android devices. You can pretty much create your
own system of shortcuts and menus to better suit how you uniquely use your
phone.

Popular games available for Android phones include Cut The Rope, Goat
Simulator and Temple Run 2 to name but three, but there are thousands of free
and paid apps and games on offer.

How can I get apps on an Android phone?

The majority of apps can be downloaded from the Google Play store (the
equivalent of Apple’s App Store), which includes a mix of free as well as
'premium' apps that you have to pay for. Some apps have ‘lite’ versions which
are free, in the hope you’ll enjoy them and upgrade to the full premium version.
Others - like Angry Birds - are free, but include adverts or the ability to make
in-app purchases.

The same account that lets you backup your contacts can also have financial
details added to it, allowing you the ability to purchase content from the Google
Play store directly. You can pay either by debit or credit card and initial setup
takes less than five minutes from a computer.

Although there are over 1.3 million apps available to Android users in the
Google Play store, some developers choose to make their apps available to
download from their own sites or alternative app stores. In order to download
these you'll have to change some settings on your phone before visiting these
sites on your Android phone’s web browser. By downloading apps outside
of the Google Play store, you do run the risk of attack in the form of data theft
leave yourself more susceptible to viruses, so be careful if you choose
this route.

Should you upgrade or change your Android phone; log into your Google
account and you’ll be able to download your previously owned apps again,
without being charged.

What does an Android phone look like?

Android phones come in many different shapes, colours and sizes. Some have
super-fast processors, some have powerful cameras and a few have hardware
QWERTY keyboards.

All current Android phones feature a touchscreens, the size of which varies, but
in most cases it measures at least 3-inches diagonally, although some devices
use much larger displays; like the Samsung Galaxy Note 4 for example which
features a 5.7-inch screen and has been described as a 'phablet' - a cross between
a phone and tablet.

Popular Android phones include the Motorola Moto X (5.2-inch), HTC One


(M8) (5-inch), Sony Xperia Z3 Compact (4.6-inch) and Samsung Galaxy Ace
3 (4-inch). Some examples of older Android phones with hardware QWERTY
keyboards include the HTC Desire Z, HTC ChaCha and Sony Xperia Mini Pro,
but these designs are diminishing as on-screen keyboards become better at
predicting words, phrases and even complete sentences.

So who makes Android phones?

Any handset maker is free to make an Android phone if they want to. As well as
the aforementioned Motorola, HTC, Samsung and Sony, Acer, Alcatel, Asus,
Huawei, LG and ZTE have all made Android phones (and tablets) too. Apple,
Nokia and BlackBerry do not offer Android handsets however. 

Does Google make any Android phones?

Although Google owns the OS (Android) they have not made any hardware on
which it runs in-house. However, they have partnered with various handset
manufacturers over the years to make their own-brand smartphones under the
'Nexus' name.

[From left to right] The Google Nexus One was actually made by HTC and ran
Android 2.1 Eclair; the Google Nexus S was made by Samsung and launched on
Android 2.3 Gingerbread, the Samsung Galaxy Nexus launched on Android 4.0
Ice Cream Sandwich, the LG Nexus 4 was the first handset to run Android 4.1
Jelly Bean out-the-box; the LG Nexus 5 was the first handset to run Android 4.4
KitKat and the current Nexus handset the Motorola Nexus 6, is the is the first
handset to run Android 5.0 Lollipop.
Google's Nexus phones are typically the first to receive new updates and are
considered to be the flagship Android phones, even though some other Android
devices sport larger screens, better cameras and more powerful hardware.

Android updates

Google is constantly working on new versions of the Android software. These


releases are infrequent; at the moment they normally come out every six months
or so, but Google is looking to slow this down to once a year.

Versions usually come with a numerical code and a name that’s so far been
themed after sweets and desserts, running in alphabetical order.

 Android 1.5 Cupcake


 Android 1.6 Donut
 Android 2.1 Eclair
 Android 2.2 Froyo
 Android 2.3 Gingerbread
 Android 3.2 Honeycomb - The first OS design specifically for a tablets,
launching on the Motorola Xoom
 Android 4.0 Ice Cream Sandwich: The first OS to run on smartphones
and tablets, ending the 2.X naming convention.
 Android 4.1 Jelly Bean: Launched on the Google Nexus 7 tablet by Asus
 Android 4.2 Jelly Bean: Arrived on the LG Nexus 4
 Android 4.3 Jelly Bean
 Android 4.4 KitKat: Launched on the LG Nexus 5
 Android 5.0 Lollipop: Launched on the Motorola Nexus 6 and HTC
Nexus 9
Google also releases minor updates with bug fixes and improvements.

Android tablets

Like Android phones, Android tablets come in all shapes and sizes. These can
range from the 7-inch screen of the Asus-made Google Nexus 7 to far larger
displays, such as the 10-inch display found on the Nexus 10.

Somewhat confusingly, some older Android tablets; like the original Samsung
Galaxy Tab, launched running Android 2.2 Froyo - a version of Android
designed for phones, whilst Android 3.0 Honeycomb was the first release of the
OS specifically for tablets.
Older Android tablets which didn’t run on 3.0 Honeycomb couldn’t benefit
from things like the redesigned YouTube app, improved widgets and certain
tablet-specific apps like SwiftKey for Tablets.

This fragmentation between Android phones and tablets was eliminated with the
launch of Android Ice Cream Sandwich, which was designed to operate on
either type of device and scale accordingly. Android Jelly Bean introduced a
number of improvements for both the smartphone and tablet experience over the
likes of ICS (Ice Cream Sandwich) and that trend continues with the latest
release, Android 5.0 Lollipop.

Do Android updates cost anything?

Android updates are free. The updates bring a number of new features and
changes to Android each time. Generally though, with each update the speed
and overall performance of Android is improved upon.

Most of the high-end Android phones are scheduled to receive updates first.
Most Android phones will have at least one update during their life cycle, with
some having two. A life cycle is usually around 18 months, but depending on
the phone can be longer.

How do I get an update?

Android updates are normally received OTA (Over The Air), that is, sent
directly to your Android phone without the need for a computer. Normally, once
your Android phone or tablet is due to get an upgrade, you'll see a notification
in the bar at the top of the screen. You'll then be prompted to connect to WiFi to
avoid incurring extra data charges - updates can be quite big and downloading
them over a mobile data connection isn’t advised as it may result in expensive
data charges.

Updates are generally one-stage processes and relatively straightforward, but in


some cases you may need to back up/save any media (photos, movies, music) or
apps you've downloaded before updating.

In some cases, such as with some of Sony’s and Samsung's older Android
phones, you'll need to install the dedicated software supplied online by the
manufacturer first.

Unlike Apple's iOS, where the majority of users get the latest update
simultaniously, regardless of device (this usually means the last three to four
generations of hardware). Android updates are more fragmented, dependent on
manufacturers and in some cases carriers as well - this can make for a
frustrating experience when some phones of the same model have the update
and others haven't.

Dc power supply

The most common and inexpensive plugpack power supply type you'll see is the chunky transformer
based plug. Whenever you buy some consumer electronics you'll be getting one of these:

These guys are everywhere - all sorts of voltage and current ratings. They're available for
sale at any store just about, but there are some big things to watch out for! One is that the
output voltage is not going to be 9V (for example) out of the box, that voltage rating is just
the minimum output for the current rating (200mA for example). And also, the output is
going to have a lot of ripple on it!

Before we talk precisely about these guys, lets go back in time to when engineers had to build
their power supplies with their bare hands!

The good old days!


Back a couple decades ago, the only way to build a power supply was to start a big chunky
120VAC/12VAC transformer. The transformer was used to bring the high voltage from the wall down
to a less dangerous level. Then diodes and capacitors were used to turn the AC into DC.

Transformers

We aren't going to get into the heavy detail of the electromagnetic theory behind transformers
except to say that they are made of two coils of wire around a chunk of iron. If the number of coils
are the same on both sides then the AC voltage is the same on both sides. If one side has twice the
coils, it has twice the voltage. They can be used 'backwards' or 'forwards'! For more detailed
information, be sure to check out the wikipedia page.
To use it, one half would get wired up to the wall (the 'primary' 'high side')

and the other half would output 12V AC (the 'secondary' 'low side'). The transformer
functioned in two ways: one it took the dangerous high voltage and transformed it to a much
safer low voltage, second itisolated the two sides. That made it even safer because there was
no way for the hot line to show up in your electronics and possibly electrocute you.
We'll use a schematic symbol to indicate a transformer, its two coils inside which are drawn
out, the schematic symbol will have the same number of coils on either side so use common
sense and any schematic indicators to help you out in figuring which is primary and which is
secondary!

Half wave rectification


Now that the voltage is at a non-electrocutey level of around 12VAC it can be converted into DC. The
easiest and cheapest way to convert (also called rectify) AC to DC is to use a single diode. A diode is
a simple electronic 'valve' - it only lets current flow one way. Since AC voltage cycles from positive to
negative and we only want positive, we can connect it up so that the circuit only receives
the positive halfof the AC cycle.

You'll want to use a power diode such as a 1N4001 , they're extremely common and can put up with
a lot of abuse. The side with the silver stripe matches the schematic symbol side that the 'arrow' in
the diode symbol is pointing to. That's the only direction that current can flow. The output is then
chopped in half so that the voltage only goes positive.
This will convert

into
What we have now isnt really AC and isn't really DC, its this lumpy wave. The good news is
that it's only positive voltage'd now, which means its safe to put a capacitor on it.

This is a 2200 microFarad (0.0022 Farad) capacitor, one leg has (-) signs next to it, this is the
negative side. The other side is positive, and there should never be a voltage across is so that
the negative pin is 'higher' than the positive pin or it'll go POOF!
A capacitor smooths the voltage out, taking out the lumps, sort of how spring shocks in car or
mountain bike reduce the bumpiness of the road. Capacitors are great at this, but the big capacitors
that are good at this (electrolytic) can't stand negative voltages - they'll explode!

Because the voltage is very uneven (big ripples), we need a really big electrolytic-type
capacitor. How big? Well, there's a lot of math behind it which you can read about but the
rough formula you'll want to keep in mind is:

Ripple voltage = Current draw / ( (Ripple frequency) * (Capacitor size) )


or written another way

Capacitor size = Current draw / ( (Ripple frequency) * (Ripple Voltage) )

For a half wave rectifier (single diode) the frequency is 60 Hz (or 50 Hz in europe). The
current draw is how much current your project is going to need, maximum. The ripple
voltage is how much rippling there will be in the output which you are willing to live with
and the capacitor size is in Farads.

So lets say we have a current draw of 50 mA and a maximum ripple voltage of 10mV we are
willing to live with. For a half wave rectifier, the capacitor should be at least = 0.05 / (60 *
0.01) = 0.085 Farads = 85,000 uF! This is a massive and expensive capacitor. For that
reason, its rare to see ripple voltages as low as 10mV. Its more common to see maybe 100mV
of ripple and then some other technique to reduce the ripple, such as a linear regulator chip.

You don't have to memorize that formula, but you should keep the following in mind: When
the current goes up and the capacitor stays the same, the ripple goes up. If the current goes
up and you want the ripple the same, the capacitor must also increase.

Full wave rectifiers


One thing that can be done to reduce the ripple/capacitor size by half is to use a full wave rectifier
instead of a half wave. A full wave rectifier uses 4 diodes arranged in a peculiar way so that it both
lets the positive voltage through and manages to 'flip over' the negative voltages into positive.

So now we get:
As you can see, there are twice as many humps - there isnt that "half the time, no voltage" thing
going on. This means we can divide the calculated capacitor size to half of what it was in the
previous.

Basically, a full wave rectifier is way better than a half wave! So why even talk about half-wave type
rectifiers? Well, because they're useful for a few other purposes. In general, you're unlikely to see an
AC/DC converter that uses a half wave as the cost of the diodes makes up for the saving in capacitor
size and cost!
The transformer AC/DC in practice

OK now that we've reviewed transformers, diodes when used as rectifiers and big capacitors, lets
look at a chunky plugpack again. This time, we'll look inside by cutting it in half! This power supply is
rated at9VDC @ 200mA.
We can pull it out completely to see the circuit board parts.

Wow so this looks really familiar, right? From let to right, you can see the wires that come
into the transformer from the wall plug, the transformer output has two power diodes on it
and a big capacitor (2,200uF). You might be a little puzzled at the two diodes - shouldn't
there be four for a full-wave rectifier? It turns out that if you have a special transformer made
with a 'center tap' (a wire that goes to the center) you can get away with using only two
diodes . So it really is a full wave rectifier, just one with a center-tap transformer.

These transformer-based plug-packs are really cheap to make - like on the order of under $1!

Testing the 9V supply


So now we will take a fresh power supply (don't use one you sawed in half, of course) and measure
the output voltage with a multimeter.

Yow! 14V? That's not anything like the 9V on the package, is this a broken wall wart? No! Its totally
normal! Transformer-based wall adapters are not designed to have precision outputs. For one thing,
the transformer, if you remember, is made of coils of wire. The coils for the most part act like
inductors but they still have some small resistance. For example, if the coil is 10 ohms of resistance,
then 200 mA of current will cause V = I * R = (0.2 Amps) * (10 ohms) = 2 Volts to be lost just in the
copper winding! Another thing that causes losses is the metal core of the transformer becomes less
efficient as the amount of current being transformed increases. Altogether, there are many
inefficiencies that will make the output fluctuate. In general, the output can be as high as twice the
'rated' voltage when there is less than 10mA of current being drawn.

Let's look in detail


Lets look on an oscilloscope, that way we can see in detail what is going on.
With no current being drawn on the supply, the voltage output is about 14V
When I connected a 100 ohm resistor (110 mA draw) from the positive pin to the negative pin, it
dropped to 11.2V
Connecting a 60 ohm resistor (~160 mA draw), it goes down to 10.3V
With 35 ohms (230 mA draw) the voltage plummets to 7.7V!

As the resistance gets smaller and smaller, the current draw gets higher and higher and the
voltage droops (that's the technical term for it!) You can also see the ripple increase as the
current goes up.

Now we can at least understand the thinking behind saying "9V 200mA" on the label. As
long as we are drawing less than 200mA the voltage will be higher than 9V.

You might also like