You are on page 1of 42

What is a Microcontroller

A small computer on a single chip


containing a processor, memory, and input/output
Typically "embedded" inside some device that they
control

What is a Development
Board
A printed circuit
board designed to
facilitate work
with a particular
microcontroller.

Typical components include:


power circuit
programming interface
basic input; usually buttons and
LEDs
I/O pins

Arduino Development Board


PWR IN

USB (to Computer)


RESET

I2C

POWER
5V / 3.3V / GND

Digital I\O
PWM(3, 5, 6, 9, 10, 11)

Analog
INPUTS
Making-robots-with-arduino.pdf

Different Arduino Boards

UNO
LEONARDO
DUE
YUN
TRE
ZERO
MICRO
ESPLORA
& many more

Sample Specification:
Arduino Uno

Microcontroller:
AT mega 328
Operating Voltage
5V
Input Voltage (recommended) 7-12V
Input Voltage (limits)
6-20V
Digital I/O Pins
14 (of which 6 provide PWM output)
Analog Input Pins
6
DC Current per I/O Pin
40 mA
DC Current for 3.3V Pin
50 mA
Flash Memory
32 KB (of which 0.5 KB used by boot loader)
SRAM
2 KB (ATmega328)
EEPROM
1 KB (ATmega328)
Clock Speed
16 MHz

The Arduino Microcontroller: Atmel

What is the Arduino

todbot.com/blog/bionicarduino

Getting Started
Check out: http://arduino.cc/en/Guide/HomePage
1. Download & install the Arduino environment
(IDE)
2. Connect the board to your computer via the
UBS cable
3. If needed, install the drivers (not needed in lab)
4. Launch the Arduino IDE
5. Select your board
6. Select your serial port
7. Open the blink example
8. Upload the program

Connect the USB Cable

Arduino IDE

C
O
M
P
I
L
E

U
P
L
O
A
D

N
E
W

O
P
E
N

S
A
V
E

Select Serial Port and Board

Status Messages

todbot.com/blog/bionicarduino

A Little Bit About


Programming

Code is case
sensitive
Statements are
commands and
must end with a
semi-colon
Comments
follow a // or
begin with /*
and end with */
loop and setup

Terminology

Digital I/0
www.mikroe.com/chapters/view/1

pinMode(pin, mode)

Sets pin to either INPUT or OUTPUT

digitalRead(pin)

Reads HIGH or LOW from a pin

digitalWrite(pin, value)
Writes HIGH or LOW to a pin

Electronic stuff

Output pins can provide 40 mA of current


Writing HIGH to an input pin installs a 20K

Arduino Timing
delay(ms)
Pauses for a few milliseconds

delayMicroseconds(us)
Pauses for a few microseconds

More commands:
arduino.cc/en/Reference/
HomePage

Variables
Basic variable types:
Boolean
Integer
Character

Declaring Variables
Boolean: boolean
variableName;
Integer: int variableName;
Character: char
variableName;
String: stringName [ ];

Assigning Variables
Boolean: variableName =
true;
or variableName = false;
Integer: variableName =
32767;
or variableName = -32768;
Character: variableName =
A;

Variable Scope
Where you declare your variables
matters

Setup
void setup ( ) { }

The setup function comes before


the loop function and is
necessary
for all Arduino sketches

If Statements
if ( this is true ) { do this; }

If
if ( this is true ) { do this; }

Conditional
if ( this is true ) { do this; }

Action
if ( this is true ) { do this; }

Else
else { do this; }

Basic Repetition
loop
For
while

Basic Repetition
void loop ( ) { }

Basic Repetition
void loop ( ) { }

Basic Repetition
void loop ( ) { }

Basic Repetition
for (int count = 0; count<10; count++)
{
//for action code goes here
//this could be anything
}

Basic Repetition
for (int count = 0; count<10; count++)
{
//for action code goes here
}

Basic Repetition
for (int count = 0; count<10; count++)
{
//for action code goes here
}

Basic Repetition
for (int count = 0; count<10; count++)
{
//for action code goes here
}

Basic Repetition
for (int count = 0; count<10; count++)
{
//for action code goes here
}

Basic Repetition
for (int count = 0; count<10; count++)
{
//for action code goes here
}

Basic Repetition
for (int count = 0; count<10; count++)
{
//for action code goes here
}

Basic Repetition
while ( count<10 )
{
//while action code goes here
//should include a way to change count
//variable so the computer is not stuck
//inside the while loop forever
}

Basic Repetition
while ( count<10 )
{
//looks basically like a for loop
//except the variable is declared before
//and incremented inside the while
//loop
}

You might also like