10 Anne Roudaut hci 2 building interactive devices

#10 Anne Roudaut hci 2: building interactive devices hasso-plattner institute tangible & electronic

assignment • design, prototype, and laser cut a robotic vehicle that you can control by projecting on it • upload sketches, drawings, & photos to the wiki

light sensors, to allow sending commands to the tangible shape allows users to pick up and move your task: (onmi) wheels and motor, so it can move itself design & built a motorized tangible object

electronic part with an arduino board

and a set of components (battery / motors / photoresistors / chips / resistors …)

arduino

board




program on PC (simplified C++) upload to the board separate and run independently main advantage of Arduino!

when programming and testing some LEDs pins usb plug (5 V) reset button processor external power (max 12 v) to run independently pins

some LEDs pins usb plug (5 V) reset button processor external power (max 12 v) pins: to plug in components such as…

+ long leg is the + - LEDs

the LED blinks continuously pin “gnd” (ground) what’s happening? (we will see later why we need the resistor) pin “ 12”

step by step

0 configure

pin “gnd” (ground) pin “ 12” 1 pluging in


e. g. all these pins are connected It is the same here etc. test board

2 compiling

3 uploading

it is blinking: the board is uploading the binary code (1 = light on / 0 = light off) 3 uploading

1 st 4 loop executing

5 executes setup () reseting

test 1 (5 mn) blinking LED 1. plug in a resistor and an LED in pin 12 pin gnd - Blue LED + pin 12 (5 V) 82 ohm 2. launch the File/Examples/Basic/Blink arduino files 3. modify the code to make the LED says “SOS” in Morse (3 shorts, 3 longs, 3 shorts)

don’t forget your programming skills! write functions

test 2 (5 mn) more blinking (with the same circuit) 1. upload File/Examples/Basic/Blink to the board 2. change the first delay value to 1 and the second to 1. upload the code to the board 3. change the first delay value to 1 and the second to 10. upload the code to the board 4. compare three cases and tell me more!

1 delay(1000) … delay(1000) HIGH LOW 2 delay(1) … delay(1) 3 delay(1) … delay(10) blink bright blink less bright blink even less bright

1 delay(1000) … delay(1000) HIGH LOW 2 delay(1) … delay(1) 3 delay(1) … delay(10) voltage is either 0 or 5 v voltage is ½ of 5 V voltage is a 1/11 of 5 V

pulse width modulation : : technique using a rectangular pulse wave whose pulse width is modulated resulting in the variation of the average value of the waveform it serves to create an analog signal from a digital one
![digital. Write("pin number", HIGH or LOW) or analog. Write("pin number", "value in [0; 255]") digital. Write("pin number", HIGH or LOW) or analog. Write("pin number", "value in [0; 255]")](http://slidetodoc.com/presentation_image_h2/671e7989a6f0ab0ac59162b78c4d4574/image-32.jpg)
digital. Write("pin number", HIGH or LOW) or analog. Write("pin number", "value in [0; 255]") (% of voltage) there are special pins that produce PWM signals (in addition to digital signals)

test 3 (5 mn) smooth blinking 1. change your circuit to use a PMW pin 1. write code with analog. Write() to make the led smoothly blink (the brightness progressively increases)

pins are input and output

digital. Write("pin number”, ”HIGH or LOW”) digital. Read("pin number”) -> 1 or 0 (0 if voltage < 3 v) digital pins are for input and output
![analog. Write("pin number”, [0; 255]) PWM pins are analog output analog. Write("pin number”, [0; 255]) PWM pins are analog output](http://slidetodoc.com/presentation_image_h2/671e7989a6f0ab0ac59162b78c4d4574/image-36.jpg)
analog. Write("pin number”, [0; 255]) PWM pins are analog output
![analog. Read("pin number”) -> [0; 1023] (1023 being the maximum voltage in the board) analog. Read("pin number”) -> [0; 1023] (1023 being the maximum voltage in the board)](http://slidetodoc.com/presentation_image_h2/671e7989a6f0ab0ac59162b78c4d4574/image-37.jpg)
analog. Read("pin number”) -> [0; 1023] (1023 being the maximum voltage in the board) analog pins are for analog input

both digital and analog pins deal with voltages reading input works with every components that generate voltages

battery

by the way, components that generate high voltage will damage the board, be careful! pin “gnd” pin “A 0” 1. 5 V battery on A 0 pin to read it voltage

digital. Write(A 0, HIGH)
![Monitor display Serial. print() Serial, println() 305 305 305 305 of [0; 1023] so Monitor display Serial. print() Serial, println() 305 305 305 305 of [0; 1023] so](http://slidetodoc.com/presentation_image_h2/671e7989a6f0ab0ac59162b78c4d4574/image-42.jpg)
Monitor display Serial. print() Serial, println() 305 305 305 305 of [0; 1023] so 305 x 5/1023 = 1, 49 V

so it works with components that generate voltages such as…

voltage increases when the intensity of light increases photodiode

voltage increases when pressure increases piezoelectric cells

but also with components that generate resistance (and we will see the trick later)

material in what components are plug in it removes electrostatic charges conductive foam

it lets the charge passing thought: it conduces charges the more you squeeze it, the less it resists to the travel of the charges conductive foam

pin “gnd” pin “A 0” let’s play with a piece of conductive foam

test 4 (5 mn) read pins 1. plug in two wires and a piece of foam between pin A 0 and GND 1. write code to display the change of voltage on pin A 0 1. write code to make an LED more or less bright when you squeeze the foam



it is a simple way to make a pressure sensor


at this point you know the basics of arduino you are almost ready to go what remains now is some math in order to understand…

1 why do we need a resistor with the LED? 2 how does an input pin read different values of resistance whereas we said it reads voltage?

let’s forget arduino for a moment

battery + resistor 3 electric quantities voltage / current / resistance

y g lo i f f ra am j c a n a t battery + voltage is the amount of cars it is measured in Volt resistor

10 Kilo OHM vs. 60 OHM vs highways let more cars passing through resistance defines the type of road it is measured in Ohm (Ω) current is the amount of cars that pass through the circuit per units of time (the flow) it is measured in Ampere

Current Voltage y g lo m u pl a n a g n i b

the smaller the road is (resistance increases), the slower the flow of cars is (current decreases) the harder a pipe is pressed, the smaller the water flow is

the relation between these 3 quantities is given by Ohm’s law U=Rx. I Volt Ohm Ω Ampere

Current (I) U=RI works for resistors 1 Ω resistor

color code = value resistors

1 meter silver (1. 59× 10− 8 Ω) Current (I) 1 meter sea water (0. 2 Ω) 1 Ω resistor conductors insulators 1 meter air (1. 3× 1016 Ω) Voltage (U) more generally, U=RI works for ohmic materials

most components are not ohmic e. g. light bulb / LED / motor

I U the resistance of the filament increases with its temperature ligh bulb

I U works in a small interval of voltage steep slope: small variations of voltage = large variations of current LED

I max current indicated on the spec working voltage interval indicated on the spec U LED off LED on LED blows (brightness increasing)

![5 V battery - + Red LED [1. 8; 2. 2] V 0, 02 5 V battery - + Red LED [1. 8; 2. 2] V 0, 02](http://slidetodoc.com/presentation_image_h2/671e7989a6f0ab0ac59162b78c4d4574/image-72.jpg)
5 V battery - + Red LED [1. 8; 2. 2] V 0, 02 A + (5 -2. 2) = R x 0, 02 R = 140Ω to reduce current we put a resistor in serie to know it value, we use Ohm’s law
![2 V battery - + Red LED [1. 8; 2. 2] V 0, 02 2 V battery - + Red LED [1. 8; 2. 2] V 0, 02](http://slidetodoc.com/presentation_image_h2/671e7989a6f0ab0ac59162b78c4d4574/image-73.jpg)
2 V battery - + Red LED [1. 8; 2. 2] V 0, 02 A + we can also adapt the voltage but …

I steep slope: when the voltage decreases a little bit, the current dramatically decreases, thus decreasing the brightness U LED off LED on LED blows (brightness increasing)
![5 V battery - Red LED [1. 8; 2. 2] V 0, 02 A 5 V battery - Red LED [1. 8; 2. 2] V 0, 02 A](http://slidetodoc.com/presentation_image_h2/671e7989a6f0ab0ac59162b78c4d4574/image-75.jpg)
5 V battery - Red LED [1. 8; 2. 2] V 0, 02 A + + 140Ω the resistor also regulates the LED voltage, that stays almost constant

so LEDs must always be mounted with a resistor in serie
![5 V battery + Red LEDs [1. 8; 2. 2] V 0, 02 A 5 V battery + Red LEDs [1. 8; 2. 2] V 0, 02 A](http://slidetodoc.com/presentation_image_h2/671e7989a6f0ab0ac59162b78c4d4574/image-77.jpg)
5 V battery + Red LEDs [1. 8; 2. 2] V 0, 02 A + + 30Ω (5 -2 x 2. 2) = R x 0, 02 R = 30Ω true for several LEDs in serie
![5 V battery - - - + + Red LEDs [1. 8; 2. 2] 5 V battery - - - + + Red LEDs [1. 8; 2. 2]](http://slidetodoc.com/presentation_image_h2/671e7989a6f0ab0ac59162b78c4d4574/image-78.jpg)
5 V battery - - - + + Red LEDs [1. 8; 2. 2] V 0, 02 A + 140Ω (5 -2. 2) = R x 0, 02 R = 140Ω true for several LEDs in parrallel (voltage is the same in each branch)

- 5 V battery - - + + + 0. 04 A is drained from the battery Red LEDs [1. 8; 2. 2] V 0, 02 A 70Ω (5 -2. 2) = R x (2 x 0, 02) R = 70Ω if LEDs are the same, we can also serialize the resistor (current splits in each branch)

1 2 why do we need a resistor with the LED? done and we know how to compute it value how does an input pin read different values of resistance whereas we said it reads voltage?

squeezing the foam changes the resistance but the voltage of A 0 pin was changing

Battery 5 V + conductive foam the resistance changes and thus the current (Ohm’s law) but still not the voltage

so there must be a trick somewhere … we must use a tension divider circuit layout

Vin + pull-up resistor Vout Rfoam x Vin Vout = Rfoam+ Rpullup tension divider

e. g. 10 KΩ (to have precise A 0 value) pin GND pull-up resistor pin 5 V pin A 0 Rfoam X 5 A 0 = Rfoam+ Rpullup so the arduino circuit can look like that

pin GND Optional if internal pull up resistor is enabled pull-up resistor pin 5 V pin A 0 but arduino also have an internal pull-up resistor -> we can plug in the foam between A 0 and gnd

by the way, a potentiometer is a tension divider circuit adjustable Vout Vin resistor gnd potentiometer

1 2 why do we need a resistor with the LED? done and we know how to compute it value how does an input pin read different values of resistance whereas we said it reads voltage? done and we know how to compute it value

use multimeter (in the shop) to check voltage: in parrallel current: in serie

more components

M motor

resistance decreases when the intensity of light increases photoresistor

to switch on higher voltage relays

a small current at the Base can control or switch a much larger current between the Collector and Emitter It serves as a switch or current amplifier transistors

they store electric charge capacitors

capacitors

(the notch shows the orientation when reading the spec) ! re o m s pin chips or integrated circuits

A B out = 4 NAND GATES example: A 0 B 0 out 1 0 1 1 1 0 chips 7400 serie

• Gleichrichter It can inverse the polarity of two motors (one on each side) It doesn't control the amount of voltage (i. e. the speed). For that, you must reduce or increase the voltage sent on pin 8 chips H-BRIDGE

chips H-BRIDGE

• Pin 8 is the power for the chip. It has to be max 5 V. Just plug in it to a digital pin always HIGH • Pin 6 is the control pin for the left motor. If it is HIGH the left motor do something, otherwise nothing (same principle for the pin 7 controlling the motor on the right) • If pin 2 LOW pin 3 HIGH, then the left motor will turn in one direction • If pin 2 HIGH pin 3 LOW, the left motor will turn in the other direction • If both pin 2 and 3 have the same value the left motor stop (same principle for right motor and pin 4 and 5) chips H-BRIDGE

• 555 timer (e. g. toaster timer) • 741 operational amplifier (amplify current) • Accelerometers • … chips etc.

without the computer

max 40 m. A per pins external power max 12 V (some versions can handle more) max 50 m. A on 3. 3 V pin

for your 9 V battery


assignment Go! design, prototype, and laser cut a robotic vehicle that you can control by projecting on it upload sketches, drawings, & photos to the wiki be sure your design is feasible : - check materials before - ask Professor or TA

end
- Slides: 108