Arduino
CS4062 - Eoin Brazil - Semester 2 - 2009
http://www.flickr.com/photos/collinmel/2317520331/
What is Arduino?
The development
The hardware The community
environment
Why Arduino?
artists & designers
“opportunistic prototyping”
device hacking & reuse
open source
free to inspect & modify
community
wiki, forums, tutorials
The Nuts & Bolts
physical computing. er, what? ubiquitous computing,
pervasive computing, ambient intelligence, calm
computing, everyware, spimes, blogjects, smart
objects...
tiny computer you can program
completely stand-alone, talks to other devices
‘C’ Ruby
Flash Python
Processing PHP
PD Matlab
Max/MSP Squeak (Smalltalk)
``Physical Computing is about prototyping with electronics,
turning sensors, actuators and microcontrollers into materials for
designers and artists.’’
=
Intel 286 Arduino
16 kBytes of Flash program memory
1 kByte of RAM
16 MHz (Apple II: 1 MHz / Intel 286: 12.5 MHz / Intel Core 2: 3 GHz)
inputs and outputs
13 digital input/output pins
5 analog input pins
6 analog output pins (PWM only)
Digital I/O can read switches and buttons, control LEDs and motors
Analog input can read knobs or other varying sensors
Analog output can be done with PWM
Arduino Capabilities
16 kBytes of Flash program memory
1 kByte of RAM
16 MHz (Apple II: 1 MHz / Intel 286: 12.5 MHz /
Intel Core 2: 3 GHz)
inputs and outputs
13 digital input/output pins
5 analog input pins
6 analog output pins (PWM only)
Motors:
DC, Steppers, Servos
Arduino IO
Sensors:
Flex, IrDa, Switches,
FSR, Accelerometers
Arduino IO
Custom Hardware:
e.g. VMusic 2 MP3 player
Blinking a LED
Diagrams
Wiring
diagram
- 1 5 10 15 20 25
-
A A
B B
C C
D D
E E
F F
G G
H H
I I
J J
- 1 5 10 15 20 25
-
+ +
Track
(all connected)
Stripboard /
Perfboard
Example
Tips:
• Mark out the Vs and 0V power lines first, then Stripboard Layout Planning Sheet
place the ICs.
Project:
• Remember to cut the track between the pins of
an IC. Mark the cuts on the diagram with an X. Designed by:
• Try to make resistors and axial capacitors lay
Actual size stripboard. Hole spacing 0.1” (2.54mm) flat on the stripboard. Resistors usually require Version:
a gap of 4 holes, capacitors a gap of 8 holes.
• Use the actual size grid on th e left to check Date:
Tracks run this way component spacing.
• Number the pins of the ICs as
1
2
8
7
Notes:
3 6
shown. 4 5
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
22 22
21 2l1
20 20
19 19
18 18
17 17
16 16
15 15
14 14
13 13
12 12
11 11
10 10
9 9
8 8
7 7
6 6
5 5
4 4
3 3
2 2
1 1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
stripboard diagramming
VeeCAD Stripboard Editor, http://veecad.com/index.html
Not direction
Resistor
sensitive
LED
short leg is negative &
goes to the ground
Expensive but
user friendly
Expensive but
user friendly
Sufficient for
almost all needs
Expensive but
user friendly
ATMega168
Lego Mindstorm NXT
Arduino
Approx.
ATMega168
~€250
Lego Mindstorm NXT Approx.
Arduino ~€25
Approx.
ATMega168
~€250
Lego Mindstorm NXT Approx.
Arduino ~€25
Approx.
ATMega168
~€250
Approx.
~€4
Programming
Programming an
Arduino
Write program
Compile (check
for errors)
Reset board
Upload to board
Initialize
setup() – run once at beginning, set pins
Running
loop() – run repeatedly, after setup()
An Arduino “Sketch”
int ledPin = 13; – led
connected to control pin 13
pinMode(ledPin, Output); –
set the pin `ledPin' as an output
setup()
serial.Begin(9600); – talk to
the computer at 9600 baud rate
An Arduino “Sketch”
void loop() Before uploading your sketch, check the board and
the serial port are correct for your Arduino and for
{ your computer
Serial.print("Hello World!\n\r");
Menu -> Tools -> Board
// wait 2sec for next reading:
delay(2000); Menu -> Tools -> Serial Port
} Upload the code from the computer to the
Arduino using the upload button
/* Blinking LED ---
* turns on and off a light emitting diode(LED) connected to a digital
* pin, based on data coming over serial
*/
void setup()
{
pinMode(ledPin, OUTPUT); // sets the digital pin as output
Serial.begin(19200); // initiate serial communication
}
void loop()
{
while (Serial.available()>0) {
inByte = Serial.read();
}
if (inByte>0) {
digitalWrite(ledPin, HIGH); // sets the LED on
} else {
digitalWrite(ledPin, LOW); // sets the LED off
}
}
/* Blinking LED ---
* turns on and off a light emitting diode(LED) connected to a digital
* pin, based on data coming over serial
*/
Initialise
int ledPin = 13; // LED connected to digital pin 13
int inByte = 0; some of the
void setup()
{
variables
pinMode(ledPin, OUTPUT); // sets the digital pin as output
Serial.begin(19200); // initiate serial communication
}
void loop()
{
while (Serial.available()>0) {
inByte = Serial.read();
}
if (inByte>0) {
digitalWrite(ledPin, HIGH); // sets the LED on
} else {
digitalWrite(ledPin, LOW); // sets the LED off
}
}
/* Blinking LED ---
* turns on and off a light emitting diode(LED) connected to a digital
* pin, based on data coming over serial
*/
void setup()
{
pinMode(ledPin, OUTPUT); // sets the digital pin as output
Serial.begin(19200); // initiate serial communication
}
void loop()
{ Setup LED pin and
while (Serial.available()>0) {
}
inByte = Serial.read(); serial connection
if (inByte>0) {
digitalWrite(ledPin, HIGH); // sets the LED on
} else {
digitalWrite(ledPin, LOW); // sets the LED off
}
}
/* Blinking LED ---
* turns on and off a light emitting diode(LED) connected to a digital
* pin, based on data coming over serial
*/
void setup()
{
pinMode(ledPin, OUTPUT); // sets the digital pin as output
Serial.begin(19200); // initiate serial communication
}
Loop - Reading the
void loop()
{ serial for info, when
inByte = Serial.read(); something is received
while (Serial.available()>0) {
}
if (inByte>0) {
turn the
digitalWrite(ledPin, HIGH); // sets the LED on
LED on
} else {
digitalWrite(ledPin, LOW); // sets the LED off
}
}
/* Digital reading, turns on and off a light emitting diode (LED) connected to digital
* pin 13, when pressing a pushbutton attached to pin 7. It illustrates the concept of
* Active-Low, which consists in connecting buttons using a 1K to 10K pull-up resistor.
*/
void setup() {
pinMode(ledPin, OUTPUT); // set LED as output
pinMode(inPin, INPUT); // set pushbutton as input
Serial.begin(19200); // start serial communication to computer
}
void loop() {
buttonval = digitalRead(inPin); // read the pin and get the button's state
if (buttonval == HIGH) { // check if the input is HIGH (button released)
digitalWrite(ledPin, LOW); // turn LED OFF
Serial.write('0'); // Button off (0) sent to computer
} else {
digitalWrite(ledPin, HIGH); // turn LED ON
Serial.write('1'); // Button on (1) sent to computer
}
}
/* Digital reading, turns on and off a light emitting diode (LED) connected to digital
* pin 13, when pressing a pushbutton attached to pin 7. It illustrates the concept of
* Active-Low, which consists in connecting buttons using a 1K to 10K pull-up resistor.
Initialise
*/
void loop() {
buttonval = digitalRead(inPin); // read the pin and get the button's state
if (buttonval == HIGH) { // check if the input is HIGH (button released)
digitalWrite(ledPin, LOW); // turn LED OFF
Serial.write('0'); // Button off (0) sent to computer
} else {
digitalWrite(ledPin, HIGH); // turn LED ON
Serial.write('1'); // Button on (1) sent to computer
}
}
/* Digital reading, turns on and off a light emitting diode (LED) connected to digital
* pin 13, when pressing a pushbutton attached to pin 7. It illustrates the concept of
* Active-Low, which consists in connecting buttons using a 1K to 10K pull-up resistor.
*/
int ledPin = 13; // choose the pin for the LED Setup LED pin,
int inPin = 7; // choose the input pin (button)
switch pin and
int buttonval = 0; // variable for reading the pin status
void setup() {
pinMode(ledPin, OUTPUT); // set LED as output
serial connection
pinMode(inPin, INPUT); // set pushbutton as input
Serial.begin(19200); // start serial communication to computer
}
void loop() {
buttonval = digitalRead(inPin); // read the pin and get the button's state
if (buttonval == HIGH) { // check if the input is HIGH (button released)
digitalWrite(ledPin, LOW); // turn LED OFF
Serial.write('0'); // Button off (0) sent to computer
} else {
digitalWrite(ledPin, HIGH); // turn LED ON
Serial.write('1'); // Button on (1) sent to computer
}
}
/* Digital reading, turns on and off a light emitting diode (LED) connected to digital
* pin 13, when pressing a pushbutton attached to pin 7. It illustrates the concept of
* Active-Low, which consists in connecting buttons using a 1K to 10K pull-up resistor.
*/
Loop - Reading the
int ledPin = 13; // choose the pin for the LED
int inPin = 7; // choose the input pin (button) button for info, when
int buttonval = 0; // variable for reading the pin status
void setup() {
button is press turn
pinMode(inPin, INPUT); // set pushbutton asthe input LED on and
pinMode(ledPin, OUTPUT); // set LED as output
} signal the computer
Serial.begin(19200); // start serial communication to computer
void loop() {
of change
buttonval = digitalRead(inPin); // read the pin and get the button's state
if (buttonval == HIGH) { // check if the input is HIGH (button released)
digitalWrite(ledPin, LOW); // turn LED OFF
Serial.write('0'); // Button off (0) sent to computer
} else {
digitalWrite(ledPin, HIGH); // turn LED ON
Serial.write('1'); // Button on (1) sent to computer
}
}
Spooky Skull Example
http://todbot.com/
To / From
Other
Software
Pure Data
Pduino
SimpleMessageSystem
Flash
// arduino serial proxy helper
// send messages from arduino to your
Serial Proxy // serial port >> socket
// and read it through flash
(XMLSocket server) a
small program that runs #define inPin 2
on your Mac/PC and
void setup(){
keeps a live connection Serial.begin(9600);
between the serial port }
and Flash void loop(){
byte readValue=digitalRead(inPin);
if(readValue == HIGH){
Serial.print("high");
Serial.print(0, BYTE);
}
}
Flash Example
http://file-error.net/1o1o1o1o1/?Physical_Computing_and_Interaction:Arduino:Arduino_VS_Flash
http://protolab.pbwiki.com/Arduino2Flash
Animata
Animata
Processing
Interactive Objects /
Displays
Spooky Skull Example - Tod E. Kurt
Lilypad - Leah Buechley
Wanderlust - Hector Ouilhet
Ambient Auditory Group Presence
Display
Hanging Gardens
http://www.cs.colorado.edu/~buechley/diy/diy_lilypad_arduino.html
A Construction Kit for Electronic Textiles - IEEE International Symposium on Wearable Computers (ISWC) 2006.
Wanderlust
A mobile service, uses identities and
needs (in terms of time and distance)
to explore spaces as well to meet
people with similar interests.
Ad-Hoc Social Networking tool as it
provides suggestions from people and
places that can be relevant to you.
http://www.thejaguarhouse.com/blog/finalpresentation/wanderlust.html
Wanderlust Prototype
thesis: http://www.thejaguarhouse.com/blog/wanderlust.pdf
final presentation: http://www.thejaguarhouse.com/blog/finalpresentation/wanderlust.html
Ambient Auditory Group
Presence Display:
Designed to explore, using concurrent
auditory icons, the issue of group
awareness (ICAD07 paper)
Presence and activity are conveyed by
changes in the soundscape
Ruby, Python, C, Growl and Boodler
Semi-Public Display for Small, Co-
located Groups
Hanging Gardens:
Collaboration with Jurgen Simpson
Two Places - UL / Ormeau, Belfast
Network of Speakers and Sensors
Arduino, Ruby, Max/MSP
2 field of insects
Circadian rhythm
Walls and nodes
Hanging Gardens:
Collaboration with Jurgen Simpson
Two Places - UL / Ormeau, Belfast
Network of Speakers and Sensors
Arduino, Ruby, Max/MSP
2 field of insects
Circadian rhythm
Walls and nodes
Useful Links
Arduino - http://www.arduino.cc/
Wanderlust - http://www.thejaguarhouse.com/blog/
Lilypad - http://www.cs.colorado.edu/~buechley/diy/diy_lilypad_arduino.html
Usman Haque and Adam Somlai-Fischer - ``Low tech sensors and actuators
for artists and architects’’