You are on page 1of 33

ARDUINO MICROCONTROLLER

GUIDE
I/O & MEMORY SYSTEMS

PRESENTED BY: ENGR. BRYAN A. CAMELLO


ARDUINO NANO
ARDUINO UNO

ARDUINO MEGA
OVERVIEW
• Arduino Uno is based on the ATmega328.
• It has 14 digital input/output pins (of which 6 can be used as PWM outputs)
and 6 analog inputs.
• Also, a 16 MHz crystal oscillator, a USB connection, a power jack and a reset
button.
• It contains everything needed to support the microcontroller; simply connect it
to a computer with a USB cable or power it with a AC-to-DC adapter or
battery to get started.
SUMMARY
POWER
• The Arduino Uno can be powered via the USB connection or with an external
power supply. The power source is selected automatically.
• External (non-USB) power can come either from an AC-to-DC adapter (wall-
wart) or battery.
POWER

• The board can operate on an external supply of 6 to 20 volts.


• The recommended range is 7 to 12 volts.
POWER PINS
• VIN – The input voltage to the Arduino board when it's using an external power
source (as opposed to 5 volts from the USB connection or other regulated
power source).
- You can supply voltage through this pin, or, if supplying voltage via the
power jack, access it through this pin.
• 5V - The regulated power supply used to power the microcontroller and other
components on the board.
- This can come either from VIN via an on-board regulator, or be supplied by
USB or another regulated 5V supply.
• 3.3V - A 3.3 volt supply generated by the on-board regulator. Maximum current
draw is 50 mA.
• GND – Ground pins
MEMORY
• There are three pools of memory in the microcontroller used on average-
based Arduino boards:
1. Flash Memory (program space), is where the Arduino sketch is stored.
2. SRAM (static random access memory) is where the sketch creates and manipulates
variables when it runs.
3. EEPROM is memory space that programmers can use to store long-term information.

• The ATmega328 chip found on the Uno has the following amounts of memory:
Flash 32k bytes (of which .5k is used for the bootloader)
SRAM 2k bytes
EEPROM 1k byte
SRAM SIZE
• Notice that there's not much SRAM available in the Uno.
• It's easy to use it all up by having lots of strings in your program. For example,
a declaration like: char message[] = "I support the Cape Wind project.";
• puts 33 bytes into SRAM (each character takes a byte, plus the '\0'
terminator).
• This might not seem like a lot, but it doesn't take long to get to 2048,
especially if you have a large amount of text to send to a display, or a large
lookup table, for example.
SRAM SIZE
• If you run out of SRAM, your program may fail in unexpected ways; it will
appear to upload successfully, but not run, or run strangely.
• You can address this problem, for example:
• If you have lookup tables or other large arrays, use the smallest data type
necessary to store the values you need; for example, an int takes up two
bytes, while a byte uses only one (but can store a smaller range of values).
INPUT AND OUTPUT (I/O)

• Each of the 14 digital pins on the Uno can be used as an input or output, using
pinMode(), digitalWrite(), and digitalRead() functions.
• They operate at 5 volts.
INPUT AND OUTPUT (I/O)

• Serial: 0 (RX) and 1 (TX) . Used to receive (RX) and transmit (TX) TTL serial data.
• External Interrupts: 2 and 3. These pins can be configured to trigger an interrupt on
a low value, a rising or falling edge, or a change in value. See the attachInterrupt()
function for details.
• PWM: 3, 5, 6, 9, 10, and 11. Provide 8-bit PWM output with the analogWrite()
function.
• SPI: 10 (SS), 11 (MOSI), 12 (MISO), 13 (SCK). These pins support SPI communication
using the SPI library.
• LED: 13. There is a built-in LED connected to digital pin 13. When the pin is HIGH
value, the LED is on, when the pin is LOW, it's off.
INPUT AND OUTPUT (I/O)

• The Uno has 6 analog inputs, labeled A0 through A5, each of which provide 10 bits
of resolution (i.e. 1024 different values).
• By default they measure from ground to 5 volts, though is it possible to change the
upper end of their range using the AREF pin and the analogReference() function.
• I2C: 4 (SDA) and 5 (SCL). Support I2C (TWI) communication using the Wire library.
• AREF. Reference voltage for the analog inputs. Used with analogReference().
• Reset. Bring this line LOW to reset the microcontroller. Typically used to add a reset
button to shields which block the one on the board.
ANALOG TO DIGITAL CONVERTER (ADC)

• analogRead() – reads the value from the specified analog pin.


• The ADC takes the analog signal, measures it, and converts it to digital (or binary).
• Resolution - the number of bits used to the digitally communicate the binary value.
• The ADC is a multichannel,10-bit analog to digital converter.
• For Arduino uno, this yields a resolution between readings of: 5 volts/1024 units or
0.0049 volts (4.9 mV) per unit.
PROGRAMMING

• The Arduino runs a simplified version of the C programming language, with


some extensions for accessing the hardware.
• Programs are created in the Arduino development environment and then
downloaded to the Arduino board.
• Code must be entered in the proper syntax which means using valid
command names and a valid grammar for each code line.
PROGRAM FORMATTING AND SYNTAX
• Programs are entered line by line. Code is case sensitive which means
"myvariable" is different than "MyVariable".
• Statements are any command. Statements are terminated with a semi-colon. A
classic mistake is to forget the semi-colon so if your program does not compile,
examine the error text and see if you forgot to enter a colon.
• Comments are any text that follows “//” on a line. For multi-line block
comments, begin with “/*” and end with “*/”
• Constants are fixed numbers and can be entered as ordinary decimal
numbers (integer only) or in hexadecimal (base 16) or in binary (base 2)
PROGRAM FORMATTING AND SYNTAX

• Labels are used to reference locations in your program. They can be any
combination of letters, numbers and underscore (_), but the first character must
be a letter.
• When used to mark a location, follow the label with a colon. Here’s an
example:
repeat: digitalWrite( 2, HIGH);
delay(1000);
digitalWrite(2, LOW);
delay(1000);
goto repeat;
PROGRAM FORMATTING AND SYNTAX
• Variables are allocated by declaring them in the program. Every variable
must be declared. If a variable is declared outside the braces of a function, it
can be seen everywhere in the program.
• If it is declared inside the braces of a function, the variable can only be seen
within that function.
• Variables come in several flavors including byte (8-bit, unsigned, 0 to 255),
word (16-bit, unsigned, 0 to 65,536), int (16-bit, signed, -32,768 to 32,767),
and long (32-bit, signed, -2,147,483,648 to 2,147,483,647).
PROGRAM FORMATTING AND SYNTAX

• Use byte variables unless you need negative numbers or numbers larger than
255, then use int variables.
• Using larger sizes than needed fills up precious memory space.
• Variable declarations generally appear at the top of the program

byte i;
word k;
int length;
int width;
PROGRAM FORMATTING AND SYNTAX

• Symbols are used to redefine how something is named and can be handy for
making the code more readable.
• Symbols are defined with the "#define" command and lines defining symbols
should go at the beginning of your program.
PROGRAM FORMATTING AND SYNTAX

• Here's an example without symbols for the case where an LED is connected to
pin 2.
PROGRAM FORMATTING AND SYNTAX

• Here is the same using a symbol to define “LED”


PROGRAM STRUCTURE

• All Arduino programs have two functions, setup() and loop().


• The instructions you place in the setup() function are executed once when the
program begins and are used to initialize.
• Use it to set directions of pins or to initialize variables.
• The instructions placed in loop are executed repeatedly and form the main
tasks of the program.
PROGRAM STRUCTURE
• Therefore every program has this structure

• The absolute, bare-minimum, do-nothing program that you can compile and run is
THE SIMPLE COMMANDS

• This section covers the small set of commands you need to make the Arduino
do something useful.
• These commands appear in order of priority.
• You can make a great machine using only digital read, digital write and
delay commands.
THE SIMPLE COMMANDS

• pinMode
This command, which goes in the setup() function, is used to set the
direction of a digital I/O pin.
Set the pin to OUTPUT if the pin is driving and LED, motor or other
device.
Set the pin to INPUT if the pin is reading a switch or other sensor.
THE SIMPLE COMMANDS

• pinMode
This example sets pin 2 to an output and pin 3 to an input.
THE SIMPLE COMMANDS

• Serial.print
The Serial.print command lets you see what's going on inside the Arduino
from your computer.
For example, you can see the result of a math operation to determine if
you are getting the right number.
For this command to show anything, you need to have the Arduino
connected to the host computer with the USB cable.
THE SIMPLE COMMANDS

• Serial.print
For the command to work, the command Serial.begin(9600) must be
placed in the setup() function.
After the program is uploaded, you must open the Serial Monitor
window to see the response.
There are two forms of the print command. Serial.print() prints on the
same line while Serial.println() starts the print on a new line.
THE SIMPLE COMMANDS

• Serial.print
Here is a brief program to check if your board is alive and connected to
the PC
THE SIMPLE COMMANDS

• digitalWrite
This command sets an I/O pin high (+5V) or low (0V) and is the
workhorse for commanding the outside world of lights, motors, and
anything else interfaced to your board.
Use the pinMode() command in the setup() function to set the pin to an
output.
THE SIMPLE COMMANDS
• Delay
Delay pauses the program for a specified number of milliseconds. Since
most interactions with the world involve timing, this is an essential
instruction.
The delay can be for 0 to 4,294,967,295 msec. This code snippet turn
on pin 2 for 1 second.
END

You might also like