Professional Documents
Culture Documents
Embedded Systems ICT211a
Embedded Systems ICT211a
Embedded Systems ICT211a
• Microprocessor
• CPU that is generally concerned with efficient processing (computing) and
data management.
• Microcontroller
• CPU that is generally concerned with efficient control of input and output
devices
Arduino Architecture
Inherent Characteristics of Microcontrollers
1. Embedded
2. Dedicated to one task and run one specific program
3. Often low power devices, a battery operated microcontroller will
consume 50 milliwatts while desktop computers might consume 50
watts
4. Microcontrollers has dedicated input and output devices
5. Often small and low cost
6. Often but not always ruggedized
Sample Applications
• Microwave Oven
Microwave Operation
Car Engine Controller
TV remote control
Lighting Controls
Exercise Machines
Lawn Mower
Vacuum Cleaner
And so much more
Arduino Microcontroller Platform
• What is an Arduino ?
• Arduino is an open-source electronics prototyping platform based on
flexible, easy-to-use hardware and software. It's intended for artists,
designers, hobbyists, and anyone interested in creating interactive
objects or environments. (http://www.arduino.cc)
• It is using the Atmel microcontroller.
Arduino Microcontroller Platform
• The boards can be built by hand or purchased preassembled;
• The software can be downloaded for free. It can support different OS namely:
Windows, MacOSx and Linux. http://arduino.cc/en/Main/Software
• The hardware reference designs (CAD files) are available under an open-source
license, you are free to adapt them to your needs.
Arduino Microcontroller Platform
• Arduino received an Honorary Mention in the Digital Communities
section of the 2006 Ars Electronica Prix.
• The Arduino team is: Massimo Banzi, David Cuartielles, Tom Igoe,
Gianluca Martino, and David Mellis.
Arduino Variants
Arduino Variants
Filipino Microcontroller Platform
• What is Gizduino?
• Gizduino is an Arduino Clone and based on the popular
Arduino Uno (Arduino Diecimila) developed by e-gizmo a Filipino
Company. It has all the basic features of an Arduino.
Arduino’s Instruction Set
• Structure
• setup()
• The setup() function is called when a sketch starts. Use it to initialize variables, pin modes, start using
libraries, etc. The setup function will only run once, after each powerup or reset of the Arduino board.
• loop()
• After creating a setup() function, which initializes and sets the initial values, the loop()
function does precisely what its name suggests, and loops consecutively, allowing your
program to change and respond. Use it to actively control the Arduino board.
Arduino Microcontroller Platform
• Arduino Nano has 14 digital input/output pins (of
which 6 can be used as PWM outputs), 6 analog
inputs, a 16 MHz crystal oscillator, a USB
connection, a power jack, an ICSP header, and a
reset button.
• Although most computers provide their own internal protection, the fuse
provides an extra layer of protection. If more than 500 mA is applied to the
USB port, the fuse will automatically break the connection until the short
or overload is removed.
Arduino Nano V3 Board Layout
Arduino’s Instruction Set
• The open-source Arduino environment makes it easy to write code
and upload it to the i/o board. It runs on Windows, Mac OS X, and
Linux. The environment is written in Java and based on Processing,
avr-gcc (C/C++), and other open source software.
• Digital I/O
• pinMode()
• digitalWrite()
• digitalRead()
• Analog I/O
• analogReference()
• analogRead()
• analogWrite() - PWM
Arduino’s Instruction Set
• pinMode()
• Description
• Configures the specified pin to behave either as an input or an output. See the
description of digital pins for details.
• Syntax
• pinMode(pin, mode)
• Parameters
• pin: the number of the pin whose mode you wish to set
• mode: either INPUT or OUTPUT
• Returns: None
Arduino’s Instruction Set
• digitalWrite()
• Description
• Write a HIGH or a LOW value to a digital pin.
• Syntax
• digitalWrite(pin, value)
• Parameters
• pin: the pin number
• value: HIGH or LOW
• Returns:none
Arduino’s Instruction Set
• digitalRead()
• Description
• Reads the value from a specified digital pin, either HIGH or LOW.
• Syntax
• digitalRead(pin)
• Parameters
• pin: the number of the digital pin you want to read (int)
• Returns :HIGH or LOW
Arduino’s Instruction Set
• analogWrite() - PWM
• Writes an analog value (PWM wave) to a pin. Can be used to light a LED at varying
brightness or drive a motor at various speeds.
• After a call to analogWrite(), the pin will generate a steady square wave of the
specified duty cycle until the next call to analogWrite() (or a call to digitalRead()
or digitalWrite() on the same pin). The frequency of the PWM signal is
approximately 490 Hz.
Arduino’s Instruction Set
• analogWrite() - PWM
• Syntax
• analogWrite(pin, value)
• Parameters
• pin: the pin to write to. (3,5,6,9,10 & 11 only)
• value: the duty cycle: between 0 (always off) and 255 (always on).
• Returns:nothing
Example Program 1
/*Blink
Turns on an LED on for one second, then off for one second, repeatedly. */
void setup() {
// initialize the digital pin as an output.
// Pin 13 has an LED connected on most Arduino boards:
pinMode(13, OUTPUT);
}
void loop() {
digitalWrite(13, HIGH); // set the LED on, HIGH is same as 1
delay(1000); // wait for a second
digitalWrite(13, LOW); // set the LED off, LOW is same as 0
delay(1000); // wait for a second
}
Example Program 2
int ledPin = 13; // LED connected to digital pin 13
int inPin = 7; // pushbutton connected to digital pin 7
int val = 0; // variable to store the read value
void setup()
{
pinMode(ledPin, OUTPUT); // sets the digital pin 13 as output
pinMode(inPin, INPUT); // sets the digital pin 7 as input
}
void loop()
{
val = digitalRead(inPin); // read the input pin
digitalWrite(ledPin, val); // sets the LED to the button's value
}
Example Program 3
/*Blink
Turns on an LED on for one second, then off for one second, repeatedly. */
void setup() {
// initialize the digital pin as an output.
// Pin 11 must be connected to a LED
pinMode(11, OUTPUT);
}
void loop() {
analogWrite(11, 255); // set the LED on in Full Brightness(0-255)
delay(1000); // wait for a second
analogWrite (11, 0); // set the LED off
delay(1000); // wait for a second
}
Arduino’s Instruction Set
• Control Structures
• if
• if...else
• for
• switch case
• while
• do... while
• break
• continue
• return
• goto
Arduino’s Instruction Set
• Further Syntax
• ; (semicolon)
• {} (curly braces)
• // (single line comment)
• /* */ (multi-line comment)
• #define
• #include
Arduino’s Instruction Set
• Arithmetic Operators
• = (assignment operator)
• + (addition)
• - (subtraction)
• * (multiplication)
• / (division)
• % (modulo)
Arduino’s Instruction Set
• Comparison Operators
• == (equal to)
• != (not equal to)
• < (less than)
• > (greater than)
• <= (less than or equal to)
• >= (greater than or equal to)
Arduino’s Instruction Set
• Boolean Operators
• && (and)
• || (or)
• ! (not)
Arduino’s Instruction Set
• Bitwise Operators
• & (bitwise and)
• | (bitwise or)
• ^ (bitwise xor)
• ~ (bitwise not)
• << (bitshift left)
• >> (bitshift right)
Arduino’s Instruction Set
• Compound Operators
• ++ (increment)
• -- (decrement)
• += (compound addition)
• -= (compound subtraction)
• *= (compound multiplication)
• /= (compound division)
• &= (compound bitwise and)
• |= (compound bitwise or)
Arduino’s Instruction Set
• Variables
• Constants
• HIGH | LOW
• INPUT | OUTPUT
• true | false
• integer constants
• floating point constants
Arduino’s Instruction Set
• Data Types
• void
• boolean
• char
• unsigned char
• byte
• int
• unsigned int
• word
• long
• unsigned long
• float
• double
• string - char array
• String - object
• array
Arduino’s Instruction Set
• Variable Scope & Qualifiers
• variable scope
• static
• volatile
• const
Arduino’s Instruction Set
Advanced I/O
tone()
noTone()
shiftOut()
shiftIn()
pulseIn()
Time
millis()
micros()
delay()
delayMicroseconds()
Math
min()
max()
abs()
constrain()
map()
pow()
sqrt()
Arduino’s Instruction Set
Trigonometry
sin()
cos()
tan()
Random Numbers
randomSeed()
random()
lowByte()
highByte()
bitRead()
bitWrite()
bitSet()
bitClear()
bit()
External Interrupts
attachInterrupt()
detachInterrupt()
Interrupts
interrupts()
noInterrupts()
Communication
Serial
Arduino IDE
• The open-source Arduino
environment makes it
easy to write code and
upload it to the i/o
board. It runs on
Windows, Mac OS X, and
Linux. The environment
is written in Java and
based on Processing, avr-
gcc (C/C++), and other
open source software.