Arduino Board
“Strong Friend” Created in Ivrea, Italy
in 2005 by Massimo Banzi & David Cuartielles
Open Source Hardware
Atmel Processor
Coding is accessible (C++, Processing, ModKit and MiniBloq)
Arduino Software Installation
Open Source
Free
Available on-line with resources at:
www.arduino.cc
What can it do?
•Great for prototyping ideas
•Access to multiple I/O
•Drive motors, turn on lights,
trigger controls.
•Low Power requirements
•Flexible / Open-source
Who cares?
Makers
Engineers
Artists
Musicians
Kids!
Teachers!!
You!!!
Setup Board Type
Tools → Board → Arduino Uno
Setup Serial COM Port
Tools → Serial Port →
Notes:
PC –
Highest COM #
Mac –
/dev/tty.usbserial-A####xxx
Analog and Digital
• All Arduino signals are either Analog or Digital
• All computers including Arduino, only
understand Digital
• It is important to understand the difference
between Analog and Digital signals since Analog
signals require an Analog to Digital conversion
Input vs. Output
Everything is referenced from the perspective of the
microcontroller.
Inputs is a signal going into the board.
Output is any signal exiting an electrical system
•Almost all systems that use physical computing will have
some form of output
•Often – Outputs include LEDs, a motor, a servo, a piezo
element, a relay and an RGB LED
upload
Basic Program
Two required routines / methods
/ functions:
void setup()
{
// runs once
}
void loop()
{
// repeats forever!!!
}
Project #1 – Blink
“Hello World” of Physical Computing
Psuedo-code – how should this work?
Three commands to know…
pinMode(pin, INPUT/OUTPUT);
ex: pinMode(13, OUTPUT);
digitalWrite(pin, HIGH/LOW);
ex: digitalWrite(13, HIGH);
delay(time_ms);
ex: delay(2500);
LED Pin Configurations
LED1 = ~3;
LED2 = ~5;
10 3
LED3 = ~10;
LED4 = 13;
13 5
Can you figure out which LED is tied to which
pin? Write down a few notes in your notebook!
Output is always Digital
To output a signal that pretends to be Analog use this
code:
analogWrite (pinNumber, value );
Where pin is one of the analog output pins: 3, 5, 6, 9,
10, 11
Where value is a number ranging from: 0 – 255.
Output is always Digital
(ON or OFF)
Using a Digital signal that pretends to be an Analog signal is
called Pulse Width Modulation (PWM)
By varying the duty cycle, we can “fake” an analog signal
output.
PWM is available on Arduino pins # 3, 5, 6, 9, 10, and 11
P.W.M. Signal @ 25% P.W.M. Signal @ 75% P.W.M. Signal rising
SIMON_2b_BLINK
Using Variables
To clean-up code, for read-ability, and flexibility – we can create
placeholders in code.
Example:
int ledPin = 3;
void setup(){
pinMode(ledPin, OUTPUT);
}
void loop(){
digitalWrite(ledPin, HIGH);
}
Digital Input
int button_state = digitalRead(ButtonPin);
Value will be either: HIGH or LOW
Reading a button press
Button Input is normally HIGH –
when you press it, you pull it LOW.
The Code:
int buttonPress = digitalRead(2);
Activating the Internal Pull-up
Resistor
pinMode(pin, INPUT_PULLUP);
ex: pinMode(2, INPUT_PULLUP);
Notes:
BUTTON1 = 2;
BUTTON2 = 6;
BUTTON3 = 9;
BUTTON4 = 12;
Button Pin Configurations
BUTTON1 = 2;
BUTTON2 = 6;
9 2
BUTTON3 = 9;
BUTTON4 = 12;
12 6
Can you figure out which Button is tied to which
pin? Write down a few notes in your notebook!
Conditional Statements
If…
General Use Example
if(condition) if(button_State==HIGH)
{ {
// do this digitalWrite(ledPin,
HIGH);
delay(300);
}
digitalWrite(ledPin,
LOW);
delay(300);
}
Digital Input
• To connect digital input to your Arduino use Digital Pins
# 0 – 13 (Although pins # 0 & 1 are also used for serial)
• Digital Input needs a pinMode command:
pinMode ( pinNumber, INPUT );
Make sure to use caps for INPUT
• To get a digital reading: digitalRead ( pinNumber );
• Digital Input values are only HIGH (On) or LOW (Off)