Bluetooth Control DC Motor 1
Bluetooth Control DC Motor 1
Introduction
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++,
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
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
world of Arduino.
What is Electricity?
What is a Circuit?
Polarity
Logic Levels
Digital Logic
The Arduino hardware and software was designed for artists, designers,
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
For everything from robots and a heating pad hand warming blanket to honest
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
Instructables
Bildr
Arduino Playground
Make: Projects
and, of course, you can find plenty more Arduino tutorials here at
learn.sparkfun.com.
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)
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
NOTE: Do NOT use a power supply greater than 20 Volts as you will
overpower (and thereby destroy) your Arduino. The recommended voltage for
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
GND (3): Short for ‘Ground’. There are several GND pins on the
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
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
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
(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,
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
TX RX LEDs
TX is short for transmit, RX is short for receive. These markings appear quite a
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
Main IC
The black thing with all the metal legs is an IC, or Integrated Circuit (13). Think
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
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.
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
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,
LilyPad Arduino
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
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
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
Arduino Leonardo
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
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
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,
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
1x Arduino Uno
BlueTerm application
1x L293D IC
1x DC motor
1x Breadboard
Jumper Cables
Program
/*
* 2013
*/
int state;
int flag=0; //makes sure that the serial only prints once the state
void setup() {
pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);
pinMode(enablePin, OUTPUT);
digitalWrite(enablePin, HIGH);
Serial.begin(9600);
void loop() {
state = Serial.read();
flag=0;
if (state == '0') {
if(flag == 0){
Serial.println("Motor: off");
flag=1;
if(flag == 0){
Serial.println("Motor: right");
flag=1;
if(flag == 0){
Serial.println("Motor: left");
flag=1;
}
Dc motor
What is DC Motor ?
around us. Almost all the electro-mechanical movements we see around us are
energy.
Principle of DC Motor
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
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
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
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
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
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
directed opposite to the supplied voltage and is known as the back Emf, as it
Where, P = no of poles
Z= No. of conductors
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.
decreases. Thus the voltage difference between supply voltage and back emf
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 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
Now as the motor continues to rotate, the back Emf starts being generated and
That module comes already on a carrier, so I assumed I can use the same driver
HC-05 or HC-06
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
:idea: Check out this post which explains how to re-program the firmware of the
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
Or in other words:
The HC-05 module can build a connection to other modules. E.g. a Robot
The HC-06 module only can be a slave. This makes it only useful for say
For most use cases the HC-06 is enough, as typically I want to have a wireless
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:
On the bottom side there are labels for the signal direction and voltage levels:
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?
GND: Ground
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
The logic analyzer shows this behaviour too: AT command sent to 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
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:
With this knowledge, the Processor Expert Bluetooth component has been
methods):
Bluetooth Module Methods
With this, I can change the pairing pin, device name or baud, beside of sending
device. Keep in mind if you change the baud, this will change the baud as well
:!: Status and AT commands can only be used if the device is not paired yet
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
Before connecting, make sure the module is powered and ready to pair. The red
:idea: the name of the device shows here for me ‘blue1′, as I have named it as
Select the device and press ‘Next’. In the next dialog select ‘Enter the device’s
pairing code':
Checking the properties on the newly added device shows that it supports SPP.
:!: 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
Using that COM port shown for the SPP service, I can connect with a terminal
:!: Make sure you use the COM port used for the SPP service, and that it
and the Bluetooth module. I’m using above the default of 9600 baud. It is
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
Instead, what I send to the UART ends up transparently on the host PC:
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,
1 /**
2 * \file
5 *
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
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
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
In case there are issues with connecting to the module, it is necessary to unbind
connect once, but then not any more. In that case the following steps help:
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
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
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
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
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 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.
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.
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.
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.
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.
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.
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
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 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.
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.
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.
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!
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!
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:
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.
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!
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.
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.