You are on page 1of 44

.

TEMPERATURE MONITORING BY MICROCONTROLLER USING ARDUINO

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.


1)1x 16×2 parallel LCD display (compatible with Hitachi HD44780 driver)

2) 1x Arduino1000

3) 1x 10kΩ potentiometer

4) 1x LM35 temperature sensor

Main circuit diagram


Project program
//Room Temperature Monitor

//T.K.Hareendran

#include <LiquidCrystal.h> // Include the library to use a LCD display

#define tempSensor 0 // Define the A0 pin as “sensor”

int Vin; // Variable to read the value from the Arduino’s pin A0

float TC; // Variable that receives the converted voltage value to ºCtemperature

float TF; // Variable to receive the converted value from ºC to ºF

LiquidCrystal lcd (7, 8, 9, 10, 11, 12);

/* The function above declares which Arduino’s pins will be used for controlling
the LCD */

void setup()

lcd.begin(16, 2); // It tells the Arduino that the display is a 16x2 type

lcd.print("-Temperature-"); // Send the text to the screen of the display.

void loop()

Vin = analogRead (tempSensor); /* Tells the Arduino to read A0 and stores the
value in “Vin” */

TC=(500.0*Vin)/1023.0; /* Converts the voltage value into temperature and


stores it into the “TC” variable (in ºC)*/

TF = ((9.0*TC)/5.0)+32.0; // Converts ºC to ºF
lcd.setCursor(0, 1); // Moves the cursor of the display to the next line

lcd.print(TF); // Exhibits the value of the temperature on the display

lcd.print((char)223); //degree symbol

lcd.print("F "); // Writes “F” to indicate that it is in Fahrenheit scale.

lcd.print (TC);

lcd.print((char)223);// degree symbol

lcd.print("C"); // Writes “C” to indicate that it is in Centigrade scale.

delay(1000); // Waits for one second to read the sensor pin again

LM35 Temperature Sensor

In this project, we will demonstrate how to build temperature sensor circuit using a LM35
sensor.
As a temperature sensor, the circuit will read the temperature of the surrounding environment
and relay thi temperature to us back in degrees celsius.

The IC we will use to measure the temperature is the LM35 IC. We will integrate this with the
arduino to measure the temperature. The arduino will then read this measured value from the
LM35 and translate into degrees fahrenheit and celsius, which we will be able to read from the
computer from the arduino serial monitor.

We can use any type of arduino board.

The LM35 is a low voltage IC which uses approximately +5VDC of power. This is ideal because
the arduino's power pin gives out 5V of power. The IC has just 3 pins, 2 for the power supply
and one for the analog output.

The output pin provides an analog voltage output that is linearly proportional to the celsius
(centigrade) temperature. Pin 2 gives an output of 1 millivolt per 0.1°C (10mV per degree). oSo
to get the degree value in celsius, all that must be done is to take the voltage output and divide it
by 10- this give out the value degrees in celsius.

So, for example, if the output pin, pin 2, gives out a value of 315mV (0.315V), this is equivalent
to a temperature of 31.5°C.

We can then easily convert this celsius value into fahrenheit by plugging in the appropriate
conversion equation. All we must do is write this code and upload it to the arduino to convert
this celsius temperature into fahrenheit. The code is shown below.

Below is the pinout of the LM35 IC:


Pin 1 receives positive DC voltage in order for the IC to work. This, again, is voltage
approximately 5 volts. Pin 3 is the ground, so it receives the ground or negative terminal of the
DC power supply. And Pin 2 is the output of the IC, outputting an analog voltage in porportion
to the temperature it measures.

This is the datasheet of the LM35 IC: LM35 Temperature Sensor IC Datasheet.

The arduino, with suitable code, can then interpret this measured analog voltage and output to us
the temperature in degrees celsius and fahrenheit.

Also to do this project we need a USB cable with a Type A connector on one end and a Type B
connector on the other end. This is so that we can hook our arduino to a computer and send it
code that it can run to display to us the temperature.

Variable Resistors (Pots)


For historical reasons, variable resistors are often called 'pots' which is short for 'potentiometers'.

In our experiment with the Serial Monitor, the pot is somehow varying the voltage at A0 and the
little test sketch is converting this voltage into a number between 0 and 1023.
Your pot has a circular 'track' that acts as a resistor, in our case it's a 10 kΩ resistor. However,
the difference with a pot, is that there is also a middle connection called the 'slider'. This
connection is rotated when you turn the pot. So if you connect one end of the pot to 5V and the
other to GND, then the voltage at the slider will vary between 0 and 5V as you turn it.

There are many display devices used by the hobbyists. LCD displays are one of the most
sophisticated display devices used by them. Once you learn how to interface it, it will be the
easiest and very reliable output device used by you! More, for micro controller based project, not
every time any debugger can be used. So LCD displays can be used to test the outputs.
Obviously, for last possibility, you need to know how to use this stuff pretty well.

Note 1:  We have sub divided this article for easy navigation as shown below:-

1.  Pin Configuration  2. Block Diagram 3. Control and Display Commands  4. LCD Interfacing 
5. LCD Initialization

Note 2: If you are interested in reading about working of LCD – we have an excellent article for
you – Working of Liquid Crystal Displays (LCD)
                Hitachi has set up a mile stone by its LCD controller IC. All the LCD displays use the
same, or any one of the IC s based upon the architecture introduced by Hitachi.

Ok, one minute, all I’m talking about is the character LCD display and not Graphical LCD
Display.

 Most of the LCD Displays available in the market are 16X2 (That means, the LCD displays are
capable of displaying 2 lines each having 16 Characters a), 20X4 LCD Displays (4 lines, 20
characters). It has 14 pins. It uses 8lines for parallel data plus 3 control signals, 2 connections to
power, one more for contrast adjustment and two connections for LED back light. Let us have a
look to typical pin configurations:

Pin Configuration table for a 16X2 LCD character display:-


Pin Number Symbol Function
1 Vss Ground Terminal

2 Vcc Positive Supply

3 Vdd Contrast adjustment

4 RS Register Select; 0→Instruction Register, 1→Data Register

5 R/W Read/write Signal; 1→Read, 0→ Write

6 E Enable; Falling edge

7 DB0
8 DB1
Bi-directional data bus, data transfer is performed once, thru DB0 to DB7,
9 DB2
10 DB3 in the case of interface data length is 8-bits; and twice, through DB4 to
11 DB4 DB7 in the case of interface data length is 4-bits. Upper four bits first
12 DB5 then lower four bits.
13 DB6
14 DB7
15 LED-(K) Back light LED cathode terminal

16 LED+(A) Back Light LED anode terminal

Data/Signals/Execution of LCD

Now that was all about the signals and the hardware. Let us come to data, signals and execution.

LCD accepts two types of signals, one is data, and another is control. These signals are
recognized by the LCD module from status of the RS pin. Now data can be read also from the
LCD display, by pulling the R/W pin high. As soon as the E pin is pulsed, LCD display reads
data at the falling edge of the pulse and executes it, same for the case of transmission.
                LCD display takes a time of 39-43µS to place a character or execute a command.
Except for clearing display and to seek cursor to home position it takes 1.53ms to 1.64ms. Any
attempt to send any data before this interval may lead to failure to read data or execution of the
current data in some devices. Some devices compensate the speed by storing the incoming data
to some temporary registers.

                LCD displays have two RAMs, naming DDRAM and CGRAM. DDRAM registers in
which position which character in the ASCII chart would be displayed. Each byte of DDRAM
represents each unique position on the LCD display. The LCD controller reads the information
from the DDRAM and displays it on the LCD screen. CGRAM allows user to define their
custom characters. For that purpose, address space for first 16 ASCII characters are reserved for
users. After CGRAM has been setup to display characters, user can easily display their custom
characters on the LCD screen.

Images of LCD Display:-

LCD - Front View


LCD - Back View
Block Diagram of LCD Display:-

LCD - Block Diagram

Control and display commands


Instruction Instruction Code Instruction Code Execution
Description time

RS R/W DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0


Read Data Read data from
1.53-
From RAM 1 1 D7 D6 D5 D4 D3 D2 D1 D0 internal RAM
1.64ms
Write data into
Write data to
1.53-
RAM 1 0 D7 D6 D5 D4 D3 D2 D1 D0 internal RAM
(DDRAM/CGRAM) 1.64ms

Busy flag (BF: 1→ LCD


Busy flag & Busy) and contents of
Address 0 1 BF AC6 AC5 AC4 AC3 AC2 AC1 AC0 address counter in 39 µs
bits AC6-AC0.

Set DDRAM Set DDRAM address


Address 0 0 1 AC6 AC5 AC4 AC3 AC2 AC1 AC0 in address counter. 39 µs
Set CGRAM Set CGRAM Address
Address 0 0 0 1 AC5 AC4 AC3 AC2 AC1 AC0 in address counter. 39 µs

Set interface data


length (DL: 4bit/8bit),
Numbers of display
Function Set 0 0 0 0 1 DL N F X X line (N: 1-line/2-line) 39 µs
display font type
(F:0→ 5×8 dots, F:1→
5×11 dots)

Set cursor moving


and display shift
Cursor or control bit, and the
Display Shift 0 0 0 0 0 1 S/C R/L X X direction without 39 µs
changing DDRAM
data

Set
Display & Display(D),Cursor(C)
Cursor On/Off 0 0 0 0 0 0 1 D C B and cursor blink(b) 39 µs
on/off control

Assign cursor moving


Entry Mode Set 0 0 0 0 0 0 0 1 I/D SH direction and enable 0µs
shift entire display.

Set DDRAM Address


to “00H” from AC and
Return Home 0 0 0 0 0 0 0 0 1 X return cursor to its 43µs
original position if
shifted.

Write “20H” to
DDRAM and set
Clear Display 0 0 0 0 0 0 0 0 0 1 43µs
DDRAM Address to
“00H” from AC

AC -Address Counter

Outline
Now the instruction can be divided mainly in four kinds

1)      Function set instructions

2)      Address set instructions

3)      Data transfer instructions with internal RAM

4)      Others

Details of the Instructions

1)      Read Data from RAM

RS R/W DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0


1 1 D7 D6 D5 D4 D3 D2 D1 D0

Read 8bit binary data from DDRAM/CGRAM

The selection of RAM is set by the previous address set instruction. If the address set instruction
of RAM is not performed before this instruction, the data that is read first is invalid, because the
direction of AC is not determined. If the RAM data is read several times without RAM address
set instruction before read operation, the correct RAM data from the second, but the first data
would be incorrect, as there is no time to transfer RAM data. In case of DDRAM read operation,
cursor shift instruction plays the same role as DDRAM address set instruction; it also transfers
RAM data to the output data registers.

After read operation, the data address counter is automatically increased or decreased by 1
according to the entry mode. After CGRAM read operation, display shift may not be executed
properly.

*In case of RAM write operation, AC is increased or decreased by 1 like that of the read
operation. In this time AC indicates the next address position, but the previous data can only by
the read instruction.

2)      Write data to ram

RS R/W DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0


1 0 D7 D6 D5 D4 D3 D2 D1 D0

Write binary 8bit data to DDRAM/CGRAM. The selection of CGRAM or DRAM is set by the
previous address set instruction; DDRAM address set, CGRAM address set. RAM set instruction
can also determine the AC direction to RAM.

After write operation, the address is automatically increased or decreased by 1 according to the
entry mode.
3)      Read Busy Flag and Address

RS R/W DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0


0 1 BF AC6 AC5 AC4 AC3 AC2 AC1 AC0

By making this read out operation, it can be determined if the LCD is performing some internal
operation or not. If Busy Flag (BF) is high, some internal operation is going inside the LCD at
that particular moment. To perform further operation the data source (e.g. micro controller) must
wait for the BF to go low. Here, the address counter value can also be read.

4)      Set DDRAM Address

RS R/W DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0


0 0 1 AC6 AC5 AC4 AC3 AC2 AC1 AC0

Set DDRAM address to AC, this instruction makes DDRAM data available from MPU. In 1-line
display mode, DDRAM address rangers from “00H” to “4FH”. In 2-line display mode, DDRAM
address in the first line ranges from “00H” to “27H”, and DDRAM address in the 2 nd line is from
“40H” to “67H”.

5)      Set CGRAM address

RS R/W DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0


0 0 0 1 AC5 AC4 AC3 AC2 AC1 AC0

Set CGRAM address to AC. This instruction makes CGRAM data available from MPU.

6)      Function Set

RS R/W DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0


0 0 0 0 1 DL N F X X

DL: Interface data length control bit

DL=’1’ means 8bit mode of data transfer.

DL=’0’ means 4bit mode of data transfer

When 4 bit mode is activated, the data needs to be transferred in two parts, first higher 4bits, and
then lower 4 bits.

N: display line number control bit

N=’1’ will allows to characters to display in 2-lines


N=’0’ will allows to characters to display in the first line only

F: display font control bit

F=’0’ will use 5×8 dots format display mode

F=’1’ will use 5×11 dots format display mode

7)      Cursor or display Shift

RS R/W DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0


0 0 0 0 0 1 S/C R/L X X

Without writing or reading the display data, shifting right/left cursor position or display.

This instruction is made to correct or search or display data. During 2-line display mode, cursor
moves to the 2nd line after the 40th digit of the 1st line.

When displayed data is shifted repeatedly, each line shifts individually.

When display shift is performed, the contents of the address counter are not changed.

8)      Display On/Off Control

RS R/W DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0


0 0 0 0 0 0 1 D C B

This instruction controls Display, Cursor and cursor blink.

D: Display On/Off control bit

D=’1’ means entire display is turned on

D=’0’ means entire display is turned off. But Display data remains in DDRAM.

C: cursor On/Off control bit

C=’1’ turns on the cursor

C=’0’ turns off the cursor. But I/D register retains the data

B: Cursor blink On/Off control bit

B=’1’ makes cursor blink periodically.


B=’0’ stops the cursor to blink and cursor looks steady if the Cursor is turned on.

9)      Entry Mode Set

RS R/W DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0


0 0 0 0 0 0 0 1 I/D SH

This instruction sets the moving direction of cursor and display.

When I/D= ’1’ cursor moves to the right and DDRAM address is increased by 1.

When I/D= ’0’ cursor moves to the left and DDRAM address is decreased by 1.

CGRAM operates in the same way in this setting.

10)   Return Home

RS R/W DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0


0 0 0 0 0 0 0 0 1 X

This instruction sets the address counter to ‘00H’, and returns the cursor to the first column of
first line. And if display is shifted previously, this instruction shifts this too. The DDRAM
contents don’t change in this instruction.

11)   Clear display

RS R/W DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0


0 0 0 0 0 0 0 0 0 1

Clear all the display data by writing “20H” (ASCII code of ‘space’ character) to all DDRAM
address, AND set value DDRAM address counter (AC) to “00H”. It returns the cursor to the first
column of first line and sets the entry mode to increment mode (I/D=’1’).

8-bit and 4-bit interfacing of LCD

Now the question is how to display data in the LCD or give command to it. There is two modes
of data transfer are supported by LCD displays. One is 4bit mode, another is 8 bit mode. To
transfer data In 8 bit mode, first put your data in the 8bit bus, then put command in the command
bus and then pulse the enable signal.

                To send data in 4bit mode; first put upper 4bit in the 4 bit data bus connected to 4MSB
pins of LCD display, then put control signals in the control bus, then pulse the E pin once. Next
put the lower 4 bit in the data bus and pulse the E pin again. Here is a flowchart simply
describing it.

LCD Display Interfacing – Flowchart:-

LCD Interfacing - Flowchart

LCD Initialisation

We are pretty familiar how to send data. But before displaying characters on the LCD display, it
must be configured first. To configure an LCD display, four command words must be sent to
LCD in either 4 bit mode, or in 8 bit mode. The commands are:

1. Function set

2. Display On/Off control

3. Entry mode set

4. Display Clear

Here is a flow chart of the initialization sequence of LCD display.


LCD Initialization

Displaying Custom Characters

All these character display modules got the feature to create 8 user defined characters (ASCII
Codes 0…7) in addition to the ROM fixed codes.

1.) The command “CG RAM Address Set” defines the ASCII code (Bit 3, 4, 5) and the dot line
(Bit 0, 1, 2) of the new character. Example demonstrates creating ASCII code “00H”.

2.) Doing 8 times the write command “Data Write” defines line by line the new character. 8th
byte stands for the cursor line.

3.) The new defined character can be used as a “normal” ASCII code (0…7); use with “DD
RAM Address Set” and “Data Write”.
Now let us look up the character set that can be displayed using the LCD Displayed

0×00 0×10 0×20 0×30 0×40 0×50 0×60 0×70 0×80 to 0xd0 0xE 0xF
0 0

0×00 CG1 0 @ P ` p CUSTOM


REGIONAL Α
0×01 CG2 ! 1 A Q a q CHARACHTER
S Ä
0×02 CG3 “ 2 B R b r
Β θ
0×03 CG4 # 3 C S c s
Ε
0×04 CG5 $ 4 D T d t
Μ Ω
0×05 CG6 % 5 E U e u
Σ ϋ
0×06 CG7 & 6 F V f v
Ρ Σ
0×07 CG8 7 G W g w
G π
0×08 CG1 ( 8 H X h x

0×09 CG2 ) 9 I Y i y
¯¹ y
0x0A CG3 * : J Z j z
J
0x0B CG4 + ; K [ k {

0x0C CG5 , < L ¥ l |


0x0D CG6 - = M ] m }

0x0E CG7 . > N ^ n →

0x0F CG8 / ? O _ o ←

CG→ CGRAM User Defined Character

Custom Regional characters vary from manufacturer to manufacturer. The Greek letters may or may not
appear. It too depends upon the design

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.

You might also like