hardware hacking and arduinos
DESCRIPTION
Presentation from ADI's pre-HackNY hardware-hacking workshopTRANSCRIPT
![Page 1: Hardware Hacking and Arduinos](https://reader034.vdocuments.mx/reader034/viewer/2022042700/555925fdd8b42a3d028b5501/html5/thumbnails/1.jpg)
Hardware Hackingand Arduinos
Howard Mao and Mason Silber
![Page 2: Hardware Hacking and Arduinos](https://reader034.vdocuments.mx/reader034/viewer/2022042700/555925fdd8b42a3d028b5501/html5/thumbnails/2.jpg)
Downloading the Arduino IDE
● Go to www.arduino.cc/en/main/software○ Download whichever software fits your Operating
System● Linux users: find the "arduino" package in
your distro's repository● OSX users: make sure to also install USB
FTDI drivers○ http://www.ftdichip.com/Drivers/VCP.htm
![Page 3: Hardware Hacking and Arduinos](https://reader034.vdocuments.mx/reader034/viewer/2022042700/555925fdd8b42a3d028b5501/html5/thumbnails/3.jpg)
What you have in front of you:
● Arduino Duemilanove● USB Cable● Breadboard● Box of jumper wires● 4 1k-ohm resistors (Brown-Black-Red)● 1 100k-ohm resistor (Brown-Black-Yellow)● 1 100k-ohm potentiometer● 4 Light Emitting Diodes (LEDs)● 1 push button switch
![Page 4: Hardware Hacking and Arduinos](https://reader034.vdocuments.mx/reader034/viewer/2022042700/555925fdd8b42a3d028b5501/html5/thumbnails/4.jpg)
LED
● Light-emitting Diode● Produces light when current flows through● Current can only flow one way
![Page 5: Hardware Hacking and Arduinos](https://reader034.vdocuments.mx/reader034/viewer/2022042700/555925fdd8b42a3d028b5501/html5/thumbnails/5.jpg)
Rules for LEDs
● Always use inline resistor● Make sure direction is right (long pin is +)
![Page 6: Hardware Hacking and Arduinos](https://reader034.vdocuments.mx/reader034/viewer/2022042700/555925fdd8b42a3d028b5501/html5/thumbnails/6.jpg)
Digital Output
Voltage can be HIGH (+5 V) or LOW (0 V)pinMode(pin, OUTPUT) sets pin to outputdigitalWrite(pin, HIGH) sets voltage highdigitalWrite(pin, LOW) sets voltage low
![Page 7: Hardware Hacking and Arduinos](https://reader034.vdocuments.mx/reader034/viewer/2022042700/555925fdd8b42a3d028b5501/html5/thumbnails/7.jpg)
Breadboards● Red channel for power● Blue channel for ground● Slots on horizontal channels all
connected together internally● Except break in middle of
board● Bridge two unconnected lines
of breadboard to build your circuit
![Page 8: Hardware Hacking and Arduinos](https://reader034.vdocuments.mx/reader034/viewer/2022042700/555925fdd8b42a3d028b5501/html5/thumbnails/8.jpg)
Basic Arduino Program Structure
void setup(){
//All initial settings go here}
void loop(){
//Runs indefinitely after setup has completed}
![Page 9: Hardware Hacking and Arduinos](https://reader034.vdocuments.mx/reader034/viewer/2022042700/555925fdd8b42a3d028b5501/html5/thumbnails/9.jpg)
Lab 1: LED sweep
● Connect LEDs to Arduino pins 8, 9, 10, 11● Turn only one on at a time● Sweep left and then right
![Page 10: Hardware Hacking and Arduinos](https://reader034.vdocuments.mx/reader034/viewer/2022042700/555925fdd8b42a3d028b5501/html5/thumbnails/10.jpg)
"Analog Output" : PWM
● Higher voltage gives brighter LED● Use PWM to approximate lower voltages● More time spent high (duty cycle) means
higher average voltage● analogWrite(pin, level) sets PWM duty cycle● Levels are from 0 to 255 (8 bits)
thT
Duty Cycle = th / T
![Page 11: Hardware Hacking and Arduinos](https://reader034.vdocuments.mx/reader034/viewer/2022042700/555925fdd8b42a3d028b5501/html5/thumbnails/11.jpg)
Lab 2: Analog LED Sweep
● Sweep left and right as before● But keep a trail of dimmer LEDs behind● Divide the level of secondary LEDs down by
two after each step
![Page 12: Hardware Hacking and Arduinos](https://reader034.vdocuments.mx/reader034/viewer/2022042700/555925fdd8b42a3d028b5501/html5/thumbnails/12.jpg)
Voltage Division
Vout = R2 / (R1 + R2) * Vin
![Page 13: Hardware Hacking and Arduinos](https://reader034.vdocuments.mx/reader034/viewer/2022042700/555925fdd8b42a3d028b5501/html5/thumbnails/13.jpg)
Analog Input
● Arduino has an Analog-to-Digital Converter● Pins A0 - A5● Use analogRead(pin) to get voltage level● Levels go from 0 to 1023 (10 bits)
![Page 14: Hardware Hacking and Arduinos](https://reader034.vdocuments.mx/reader034/viewer/2022042700/555925fdd8b42a3d028b5501/html5/thumbnails/14.jpg)
Lab 3: Variable Speed
● Use potentiometer (variable resistor) and resistor to form variable voltage divider
● Connect output of voltage divider to pin A0● Read output voltage and use it to control
delay time
![Page 15: Hardware Hacking and Arduinos](https://reader034.vdocuments.mx/reader034/viewer/2022042700/555925fdd8b42a3d028b5501/html5/thumbnails/15.jpg)
Buttons and Switches
● Two kinds of switches○ Single Throw - open or closed○ Double Throw - one branch or another
● Closed switch has 0 resistance○ Acts as a wire
● Open switch has infinite resistance○ No current can flow
![Page 16: Hardware Hacking and Arduinos](https://reader034.vdocuments.mx/reader034/viewer/2022042700/555925fdd8b42a3d028b5501/html5/thumbnails/16.jpg)
Pull-up Resistors
● Open switch with no voltage driver is an antenna, not necessarily ground
● Use pull-up resistors when combining single-throw switches and digital logic
![Page 17: Hardware Hacking and Arduinos](https://reader034.vdocuments.mx/reader034/viewer/2022042700/555925fdd8b42a3d028b5501/html5/thumbnails/17.jpg)
Interrupts
● Tell the Arduino that a digital input has changed
● attachInterrupt(interrupt, function, mode) sets function to be run on interrupts
● Interrupt 0 -> pin 2, Interrupt 1 -> pin 3● Modes are CHANGE, RISING, FALLING,
LOW
![Page 18: Hardware Hacking and Arduinos](https://reader034.vdocuments.mx/reader034/viewer/2022042700/555925fdd8b42a3d028b5501/html5/thumbnails/18.jpg)
Lab 4: Pause Button
● Connect push button to Arduino pin 2● Set pin mode to INPUT_PULLUP● Attach interrupt for pin 2● When button pressed (switch closed), pause
the sweeping● When button released (switch open), resume
the sweeping
![Page 19: Hardware Hacking and Arduinos](https://reader034.vdocuments.mx/reader034/viewer/2022042700/555925fdd8b42a3d028b5501/html5/thumbnails/19.jpg)
Congratulations! You did it!
![Page 20: Hardware Hacking and Arduinos](https://reader034.vdocuments.mx/reader034/viewer/2022042700/555925fdd8b42a3d028b5501/html5/thumbnails/20.jpg)
Some safety rules to remember
● Do not use very high voltages○ microcontrollers like Arduino use either 5 V or 3.3 V
● Do not short power to ground● Do not touch small resistor (< 100 Ohm)
after voltage is applied○ power is inversely proportional to resistance○ power in resistor is dissipated as heat○ small resistor + normal voltage = hot! hot! hot!
● Make sure directional components are in right direction
![Page 21: Hardware Hacking and Arduinos](https://reader034.vdocuments.mx/reader034/viewer/2022042700/555925fdd8b42a3d028b5501/html5/thumbnails/21.jpg)
Learning More
● Arduino website (http://arduino.cc) has many good tutorials and resources
![Page 22: Hardware Hacking and Arduinos](https://reader034.vdocuments.mx/reader034/viewer/2022042700/555925fdd8b42a3d028b5501/html5/thumbnails/22.jpg)
The EndHave fun at HackNY