1 of 21

Physical Computing �with Arduino

Lab meeting July 22, 2013

Molly Roberts

Carrington Lab, University of Washington Friday Harbor Labs

2 of 21

Arduino Components

3 of 21

Electronics Primer

  • LED
  • Diode
  • Resistors
  • Transistor
  • Hobby Servo
  • DC Motor
  • Piezo element
  • Potentiometer
  • Photoresistor

LED

Photoresistor

Temperature sensor

4 of 21

Programming primer

Variables:

Int (integer) – No decimal places i.e. -1,0,1,2,3

Boolean – True or false

Float – Decimal places! ex. -3.402835*10^38

Char (character) – ex. a, b, c

Structure:

Void setup {…} – runs once

Void loop() {…} – runs again after it finishes

5 of 21

Programming primer

Digital (0 or 5V):

pinMode(pin #, Input or Output)

DigitalRead(pin #)

DigitalWrite (pin #, value)

Analog (between 0 and 5V):

int analogRead(pin)

int analogWrite(pin, value) (cheating a bit)

6 of 21

Don’t forget!

  • End each line of code with ;

  • //Comments follow slashes

7 of 21

Fun!

LED

8 of 21

Getting started: Blinking LED

Simple circuit:

Power from Arduino

LED

Current-limiting resistor and Ground

9 of 21

Breadboarding

Arduino output: pin #13

10 of 21

Sketch setup

//Declare variable

Int ledPin = 13; //variable set to 13

//Run Once

Void setup ()

{

pinMode(ledPin, OUTPUT); //set pin mode to “OUTPUT” (not input)

}

11 of 21

Sketch

//Runs as a loop!

Void loop ()

{

digitalWrite(ledPin, HIGH); //Send 5V to LED

delay(1000); //Wait 1000ms

digitalWrite(ledPin, LOW); //Send 0V to LED

delay(1000); //Wait

}

12 of 21

Do it!

LED

13 of 21

Changing the code

  • Change the pin
    • Int ledPin = 13;

  • Speed up the blink time
    • delay(1000)

  • Control the brightness

14 of 21

Changing the code

  • Change the pin
    • int ledPin = 10;

  • Change the blink time
    • Delay(1)

  • Control the brightness
    • Change on:off ratio!

15 of 21

For-loop review!

7 LEDs

16 of 21

Temp sensor

TMP 36 Gz

Solid state technique

Measure temperature across a diode

(As temp increases the voltage between the base and the emitter of a transistor increases)

17 of 21

Temp sensor

Serial.print(….)

Use a new function:

18 of 21

Temp sensor

Do it!

19 of 21

Temp and light sensor

Photoresistor

Changes resistance with light

20 of 21

ARDX arduino experimenter kit�

21 of 21

ARDX arduino experimenter kit�