Arduino Fever - PHYSICAL COMPUTING

Wolf Paulus . com
Wolf Paulus

Arduino 955 - 1015
Taking advantage of strong disagreements inside Germany, the Italian feudatories rebelled and, in 1002, elected Arduino, Marquess of Ivrea, king of Italy. He distinguished himself particularly because of his fights against the Bishop of Ivrea.

Arduino Fever

2007 . 27.disruptive innovation © 2007 Wolf Paulus SoCal Code Camp Jan.

27. 2007 .disruptive innovation © 2007 Wolf Paulus SoCal Code Camp Jan.

and a development environment for writing software. 27. © 2007 Wolf Paulus 6 SoCal Code Camp Jan. 2007 .Arduino is an open-source computing platform based on a simple board.

27. 2007 .© 2007 Wolf Paulus SoCal Code Camp Jan.

.

© 2007 Wolf Paulus SoCal Code Camp Jan. 2007 . 27.

The 1st Arduino was produced in Jan. © 2007 Wolf Paulus SoCal Code Camp Jan. teachers of Physical Computing and Interaction Design at the Interaction Design Institute. 27. 2005 by David Cuartielles and Massimo Banzi. Milan Italy. 2007 .

actuators etc. 27. • © 2007 Wolf Paulus SoCal Code Camp Jan. dealing with electronic prototyping and turning micro-controllers.• Interaction Design design of any interactive experience One area of Interaction Design is Physical Computing. 2007 . into materials used by artists and designers. sensors.

“Physical Computing is an approach to learning how humans communicate through computers that starts by considering how humans express themselves physically” Physical Computing © 2007 Wolf Paulus SoCal Code Camp Jan. 27. 2007 .

27.Physical Computing © 2007 Wolf Paulus SoCal Code Camp Jan. 2007 .

cheap. 2007 . about US$ 30 based on a simple I/O board open-source physical computing platform standalone interactive object or connected to a computer Arduino Boards can be assembled or purchased pre-assembled © 2007 Wolf Paulus SoCal Code Camp Jan. 27.

2007 . 27.© 2007 Wolf Paulus 15 SoCal Code Camp Jan.

27. at ARTECH 2006 © 2007 Wolf Paulus 16 SoCal Code Camp Jan.0 (ALPHA) is released.• May 2005: Wiring 1. 2007 . • Aug 2005: Arduino boards are assembled in Europe • Aug 2005: Tom Igoe (NYU) assembles a small number of Arduino boards in the US. • Oct 2005: Board are printed in batches of 1000 • Mar 2006: Arduino feat. in O’Reilly Make Magazine • Nov 2006: Arduino feat.

2007 .Tom Igoe. August 2005 © 2007 Wolf Paulus SoCal Code Camp Jan. ITP NYU assembles Arduino Boards. 27.

27. 2007 © 2007 Wolf Paulus .• • • • really easy to program Java-like language allows quickly creation of prototypes cheap hardware makes mistakes tolerable SoCal Code Camp Jan.

while the arduino way is based on maybe getting lost in the way and finding C instead . “tinkering” © 2007 Wolf Paulus SoCal Code Camp Jan.. 27.Classic engineering relies on a strict process for getting from A to B. 2007 ..

27.© 2007 Wolf Paulus SoCal Code Camp Jan. 2007 .

2007 .• • • circuit board IDE Integrated Development Environment sample code © 2007 Wolf Paulus SoCal Code Camp Jan. 27.

2007 .© 2007 Wolf Paulus 22 SoCal Code Camp Jan. 27.

16 MHz-Crystal Power-LED digital I/O Reset-Button ATmega8 Micro analog input TX/RX LEDs Test LED USB FTDI USB Power Power Regulator .

• • • •

16 MHz 8 KByte Flash RAM
(1K taken by the boot loader)

1 KByte RAM
e.g. for auto/local variables and stack

14 digital Input/Output Ports

ATmega8
© 2007 Wolf Paulus SoCal Code Camp Jan. 27, 2007

• • • •

USB 2.0 compatible Transmit and receive LED drive signals 256 Byte receive, 128 Byte transmit buffer Data transfer rate from 300 bit/s to 3 Mb/s

Single chip USB to async. serial data transfer interface
© 2007 Wolf Paulus 25 SoCal Code Camp Jan. 27, 2007

© 2007 Wolf Paulus

SoCal Code Camp Jan. 27, 2007

© 2007 Wolf Paulus SoCal Code Camp Jan. 2007 . 27.

1KOhm Resistor © 2007 Wolf Paulus SoCal Code Camp Jan. 2007 . 27.

LOW). delay(1000). } “hello world” © 2007 Wolf Paulus SoCal Code Camp Jan. } void loop() { digitalWrite(ledPin. digitalWrite(ledPin.the blinking LED int ledPin = 13.“hello world” . OUTPUT). 2007 . HIGH). 27. void setup() { pinMode(ledPin. delay(1000).

OUTPUT)..13) can be set as input or output ports.14 digital IO (pins 0. 27. int ledPin = 13. 2007 . } Digital I/O Ports © 2007 Wolf Paulus SoCal Code Camp Jan. void setup() { pinMode(ledPin.

27.Solderless Breadboards © 2007 Wolf Paulus SoCal Code Camp Jan. 2007 .

Digital I/O Ports .

} 6 analog input (pins 0.int analogPin = 3.. 27.. int val = 0. 2007 ..1023 Analog In © 2007 Wolf Paulus SoCal Code Camp Jan..5). void setup() { . } void loop() { val=analogRead(analogPin). . which take analog values (like voltage readings) and convert them into integer values 0.

27. 2007 .Analog Input © 2007 Wolf Paulus SoCal Code Camp Jan.

void setup() { pinMode(ledPin.11).. analogWrite(ledPin. } Analog Out © 2007 Wolf Paulus SoCal Code Camp Jan. 2007 . OUTPUT). val/4). } void loop() { val=analogRead(analogPin). 27. int ledPin = 9. reassigned digital pins take analog values 0.255 (0V.5V) int analogPin = 3.3 analog output (pins 9.10..

2007 .Analog Input © 2007 Wolf Paulus SoCal Code Camp Jan. 27.

2007 . 27.Sensors © 2007 Wolf Paulus SoCal Code Camp Jan.

• Temperature Probe • Digital Themometer • Temperature/Humidity Sensor Temperature Sensors © 2007 Wolf Paulus SoCal Code Camp Jan. 2007 . 27.

2007 .IR Sensor detects changing patterns of passive infrared to sense motion from up to 20 feet away! Passive Infra-Red Sensor © 2007 Wolf Paulus SoCal Code Camp Jan. 27.

and Z). 27. Y.3-Axis Accelerometer can sense gravitational (g) force of ±3g on three axes (X. Accelerometer © 2007 Wolf Paulus SoCal Code Camp Jan. 2007 .

• Color Sensor • Light to Frequency Converter • Touch Sensor Sensors © 2007 Wolf Paulus SoCal Code Camp Jan. 27. 2007 .

longitude. date. latitude.The module provides current time. altitude. speed and travel direction/ heading GPS Receiver Module © 2007 Wolf Paulus SoCal Code Camp Jan. 2007 . 27.

2007 . 27.Ultrasonic Sensor © 2007 Wolf Paulus SoCal Code Camp Jan.

27. 2007 .© 2007 Wolf Paulus 44 SoCal Code Camp Jan.

Arduino Board Life Cycle © 2007 Wolf Paulus SoCal Code Camp Jan. 2007 . 27.

and FALLING Ultrasonic Sensor .for “Hello World” of Embedded Computing Anlog In . 5.Demo 1. Blinky . 2. CHANGE. 4. 3.Recursive Programming on Arduino ? 46 SoCal Code Camp Jan. RISING.Photo Resistors and Infrared Detectors Interrupt . 27.pulseIn fibonacci . 2007 © 2007 Wolf Paulus .LOW.

void setup() { pinMode(ledPin. delay(1000). 2007 . } © 2007 Wolf Paulus lide t s nex on in “hello world” m zoo SoCal Code Camp Jan.“hello world” . 27.blinking LED int ledPin = 13. OUTPUT). HIGH). LOW). delay(1000). } void loop() { digitalWrite(ledPin. digitalWrite(ledPin.

OUTPUT ). } © 2007 Wolf Paulus // sets the LED on // waits for one second // sets the LED off // waits for one second Blinky . digitalWrite( p. delay( 1000 ). delay( 1000 ). HIGH ). 27.Hello World SoCal Code Camp Jan. LOW ). // define digital pin as output } void loop() { digitalWrite( p. 2007 . // LED connected to digital pin 13 void setup() { pinMode( p.int p = 13.

2007 . 27.Infrared Detectors © 2007 Wolf Paulus SoCal Code Camp Jan.

OUTPUT). } void loop() { irReader().println(val. } delay(250). // threshold boolean b = true. } © 2007 Wolf Paulus Infrared Detectors SoCal Code Camp Jan. if (val<900) { b=!b.begin(9600). 2007 . Serial. // LED connected to digital pin 13 int irPin = 1. Serial. 27. } // sets the digital pin 13 as output void irReader() { int val = analogRead(irPin)./* * Code Camp Example: IR on/off switch for external LED */ int ledPin = 13. DEC). // IR receiver connected to analog pin 1 int threshold = 512. void setup() { pinMode(ledPin. b). digitalWrite(ledPin.

2007 . whenever the pin is low CHANGE: interrupt is triggered whenever the pin changes value.• • LOW: interrupt is triggered. when the pin goes from low to high FALLING: interrupt is triggered when the pin goes from high to low External Interrupts © 2007 Wolf Paulus SoCal Code Camp Jan. 27. • • RISING: interrupt is triggered.

OUTPUT). 2007 . attachInterrupt(0. pinMode(pin. void setup(){ pinMode(sensePin.int sensePin = 2. state). digitalWrite(pin. } External Interrupts © 2007 Wolf Paulus SoCal Code Camp Jan. int pin = 13. CHANGE). 27. INPUT). int state = LOW. } void loop(){} void blink(){ state = !state. blink.

} void loop() { duration = pulseIn(pin.int pin = 7. HIGH). void setup() { pinMode(pin. 2007 . unsigned long duration. INPUT). } pulseIn © 2007 Wolf Paulus SoCal Code Camp Jan. 27.

At sea level. the speed of sound is 344 m/s (770 mph). at a temperature of 21!°C (70!°F) and under normal atmospheric conditions. 2007 . 27. SONAR © 2007 Wolf Paulus (SOund Navigation And Ranging) SoCal Code Camp Jan.

SONAR © 2007 Wolf Paulus (SOund Navigation And Ranging) SoCal Code Camp Jan. 27. 2007 .

delayMicroseconds(200). digitalWrite(pingPort. delayMicroseconds(5). delayMicroseconds(5). Serial. HIGH) / 63 . INPUT). } © 2007 Wolf Paulus UltraSonic SoCal Code Camp Jan. LOW). Serial. 2007 . Serial. HIGH).println("").println(dt). digitalWrite(pingPort.begin(9600). pinMode(pingPort. 27. OUTPUT). void setup() { Serial. } void loop() { // Ultrasound signal pin // Sets the baud rate to 9600 // Switch signalpin to output // // // // Send Wait Send Wait a square wave low high low for 2 microseconds high pulse for 5 microseconds // Wait for 200 microseconds (holdoff) // Switch signalpin to input squareWave(). } void squareWave() { pinMode(pingPort.int pingPort = 12. delay(500). unsigned long dt= pulseIn(pingPort.print("cm="). digitalWrite(pingPort. LOW).

27.int pingPort = 12. void setup() { Serial. 2007 . } // Ultrasound signal pin // Sets the baud rate to 9600 UltraSonic © 2007 Wolf Paulus SoCal Code Camp Jan.begin(9600).

delayMicroseconds(5). LOW). digitalWrite(pingPort. digitalWrite(pingPort. HIGH). OUTPUT). 27. } // Switch signalpin to output // // // // Send Wait Send Wait a square wave low high low for 2 microseconds high pulse for 5 microseconds // Wait for 200 microseconds (holdoff) // Switch signalpin to input UltraSonic © 2007 Wolf Paulus SoCal Code Camp Jan. digitalWrite(pingPort. LOW). delayMicroseconds(200). pinMode(pingPort. delayMicroseconds(5). INPUT).void squareWave() { pinMode(pingPort. 2007 .

HIGH) / 63 . the speed of sound is 344 m/s (770 mph). delay(500). at a temperature of 21!°C (70!°F) and under normal atmospheric conditions. This equates to 1 cm in 29. Serial.069 uS.print("cm="). 27. void loop() { squareWave(). Serial. } UltraSonic © 2007 Wolf Paulus SoCal Code Camp Jan. unsigned long dt= pulseIn(pingPort. 2007 . // theoretically we should divide by 58 (round trip) Serial.println("").At sea level.println(dt).

27.000 0 © 2007 Wolf Paulus 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! 45! 46! 47! 48! 49! 50! 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040 1346269 2178309 3524578 5702887 9227465 14930352 24157817 39088169 63245986 102334155 165580141 267914296 433494437 701408733 1134903170 1836311903 2971215073 4807526976 7778742049 12586269025 Fibonacci Numbers SoCal Code Camp Jan.Fibonacci Number 15.000. 2007 .000.

i<100. 27. } //repeat forever in oom z ne on lide xt s Fibonacci Numbers SoCal Code Camp Jan.print( i.print( "fib(" ). Serial. Serial. } void loop(void){ for(int i=0.print( ")= " ). } unsigned long fib(int n) { if (n<=1) return n. i++) { Serial.void setup(void){ Serial. DEC). } delay(20000). else return fib(n-1) + fib(n-2).println( fib(i). 2007 © 2007 Wolf Paulus . Serial. DEC ).begin(9600).

2007 . 27. } Fibonacci Numbers © 2007 Wolf Paulus SoCal Code Camp Jan.Fibonacci Number unsigned long fib(int n) { if (n<=1) return n. else return fib(n-1) + fib(n-2).

} else { Serial. } void loop(void){ for(int i=0.print(")= "). Serial. } } delay(20000). Serial.println(s. if (s == t) { Serial. } //repeat forever © 2007 Wolf Paulus oom z on in ext n de sli Sum 1.println("error").. } unsigned long sum(int n) { if (n<=1) return n. break.print(i.n = n(n+1)/2 SoCal Code Camp Jan. Serial. 27. unsigned long t = (i+1L)*i/2L.begin(9600).void setup(void){ Serial.DEC). else return n + sum(n-1). 2007 .DEC). i++) { unsigned long s = sum(i). i<1000.print("sum(").

n = n(n+1)/2 © 2007 Wolf Paulus SoCal Code Camp Jan. 2007 . else return n + sum(n-1). } Sum 1.Sum unsigned long sum(int n) { if (n<=1) return n. 27..

27. found everywhere pervasive spreading widely throughout an area or a group of people © 2007 Wolf Paulus SoCal Code Camp Jan.Has pervasive. ubiquitous computing finally arrived? ubiquitous present. 2007 . appearing.

com .Thanks for coming © 2003-2006 Carlsbad Cubes © 2007 wolfpaulus.

Sign up to vote on this title
UsefulNot useful