Professional Documents
Culture Documents
Introduction
Environment) that runs on your computer, used to write and upload computer code
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
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
decent understanding of these concepts before you dive in to the wonderful world
of Arduino.
What is Electricity?
What is a Circuit?
Polarity
Digital Logic
The Arduino hardware and software was designed for artists, designers, hobbyists,
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
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 for
Instructables
Bildr
Arduino Playground
LadyAda
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)
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
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
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
GND (3): Short for ‘Ground’. There are several GND pins on the Arduino,
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
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
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
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
TX RX LEDs
TX is short for transmit, RX is short for receive. These markings appear quite a bit
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,
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,
2) 1x Arduino1000
3) 1x 10kΩ potentiometer
//T.K.Hareendran
int Vin; // Variable to read the value from the Arduino’s pin A0
float TC; // Variable that receives the converted voltage value to ºCtemperature
/* 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
void loop()
Vin = analogRead (tempSensor); /* Tells the Arduino to read A0 and stores the
value in “Vin” */
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 (TC);
delay(1000); // Waits for one second to read the sensor pin again
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.
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.
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.
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:
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
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.
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
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
4) Others
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.
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
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.
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”.
Set CGRAM address to AC. This instruction makes CGRAM data available from MPU.
When 4 bit mode is activated, the data needs to be transferred in two parts, first higher 4bits, and
then lower 4 bits.
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 display shift is performed, the contents of the address counter are not changed.
D=’0’ means entire display is turned off. But Display data remains in DDRAM.
C=’0’ turns off the cursor. But I/D register retains the data
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.
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.
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’).
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 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
4. Display Clear
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
0x0F CG8 / ? O _ o ←
█
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!
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!
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!
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.