MLH Localhost: Hardware Hacking 101

10831877bd394c902f1dda20524c86d6?s=47 Swift
December 13, 2017

MLH Localhost: Hardware Hacking 101

Slides from the MLH workshop at the TEALS CS4RI fair. During this workshop, we taught students the basics of hardware hacking using an Arduino and some basic sensors.

10831877bd394c902f1dda20524c86d6?s=128

Swift

December 13, 2017
Tweet

Transcript

  1. Hardware Hacking 101 Hardware Hacking 101 By @Swi Al a

    n
  2. Hardware Hacking 101 Swift @SwiftAlphaOne swift@mlh.io

  3. Hardware Hacking 101

  4. Hardware Hacking 101 empower hackers.

  5. Hardware Hacking 101 Learn. Build. Share.

  6. Hardware Hacking 101 What will you learn today? You’ll learn

    the basics of hardware hacking using an Arduino and some simple components. Read and assemble basic circuits Blink a light automatically Build a simple light switch
  7. Hardware Hacking 101 Circuits Crash Course Everything you need to

    know about how circuits work (for today).
  8. Hardware Hacking 101 Specifically, electricity wants to move from higher

    to lower voltages by following the shortest conductive path. If you place something useful in the path (like a light bulb), the electricity will do work for you (like lighting the light bulb). 5 Volts 0 Volts
  9. Hardware Hacking 101 There are two types of electronic signals

    we’ll be working with today – digital & analog. • Digital Signal - Signals that are either on or off. These are usually represented by either a 1 or a 0 respectively. • Analog Signal - The strength of the signal varies. You can see the range of values between 1 and 0. Digital Signal: Analog Signal:
  10. Hardware Hacking 101 So, what’s in your kits? Let’s review

    the components you’ll be using in your projects today.
  11. Hardware Hacking 101 Arduino. The Arduino is a Microcontroller. It

    makes it easy for us to interact with the real world through buttons, sensors, & lights. Effectively it’s a really simple computer.
  12. Hardware Hacking 101 Arduino Overview Despite being small, this board

    has a lot on it. There are 3 main parts you’ll need to know about today... 1 2 3 USB port Power & ground pins Digital I/O pins 1 2 3 Analog Input pins 4 4
  13. Hardware Hacking 101 Light Emitting Diode (LED) An LED is

    just a simple light that we can turn on and off. When power runs through it, the light turns on. Important Note: LEDs have a positive side and a negative side like a battery. The positive side (+) is the longer leg. If you reverse this, the LED will burn out.
  14. Hardware Hacking 101 Breadboard Breadboards enable us to build circuits

    without having to solder the wires together. They are great for rapid prototyping. Important Note: The rows of pin-holes are connected. The outside rows connect vertically and the inside rows connect horizontally.
  15. Hardware Hacking 101 Wires You can use wires to connect

    your Arduino to the breadboard and the various components on it. Important Note: While the wires are all the same, we use different colors to indicate different purposes. The black wires indicate a ground connection, red wires indicate a power connection, and blue wires indicate a connection to a specific port.
  16. Hardware Hacking 101 Resistors Resistors simply resist the flow of

    current through our circuits. We can use them to regulate the current and direct its flow. Important Note: Resistors come in multiple strengths. You can tell how strong a resistor is from the colored bands. Your pack has 10kΩ resistors in it.
  17. Hardware Hacking 101 Push Button A button is a simple

    input device. It has four legs, which are connected in groups of two (A’s & B’s). When the button is pressed, all four legs are connected together. When the button is released, the legs are disconnected again. A B B A
  18. Hardware Hacking 101 Photoresistor A photoresistor is a variable strength

    resistor. It’s resistance changes depending on how much light it is exposed to. Important Note: Unlike the button, the photoresistor can give us a variety of values (not just on or off). We’ll use the analog ports to read this value.
  19. Hardware Hacking 101 Build your first circuits! You know enough

    to assemble your first circuits – let’s get our hands dirty!
  20. Hardware Hacking 101 Blinking Light Goal: Build a circuit and

    write a program that blinks an LED with a 1 second delay between turning on and off. You can use the following components: • 1x Arduino • 1x LED Hint: Remember, LEDs have both positive & negative sides.
  21. Hardware Hacking 101 Blinking Light To recreate the circuit, connect

    the components to the following pins: • Pin 13 – LED (the positive side) • GND – LED (the negative side)
  22. Hardware Hacking 101 Blinking Light Here’s our first Arduino program.

    It has two main parts: • Setup – This code is run once during startup. It sets pin 13 (the LED) as an output. • Loop – This code is run continuously. It alternates setting pin 13 (the LED) to HIGH (on) and LOW (off), waiting 1 second in between. Hint: Save some time by navigating to: int led = 13; void setup() { pinMode(led, OUTPUT); } void loop() { digitalWrite(led, HIGH); delay(1000); digitalWrite(led, LOW); delay(1000); }
  23. Hardware Hacking 101 Goal: Build a circuit and write a

    program that causes an LED to turn on when a button is pressed and off when it is released. You can use the following components: Hint: The button requires a resistor to • 1x Arduino • 1x LED • 1x Button • 3x Wire • 1x 10kΩ Resistor • 1x Breadboard Light Switch
  24. Hardware Hacking 101 To recreate the circuit, connect the components

    to the following new pins: • 5V – Button (A side) • Pin 2 – Button (B side) • GND – Button (B side) through resistor Light Switch
  25. Hardware Hacking 101 Light Switch Here’s the code to make

    a light switch: • Setup – Configure pin 13 (the LED) as an output and pin 2 (the button) as an input. • Loop – Read the state of pin 2 (the button). If it’s HIGH (pressed), then turn the LED on. Otherwise turn the LED off. Hint: Save some time by navigating to: int led = 13; int button = 2; void setup() { pinMode(led, OUTPUT); pinMode(button, INPUT); } void loop() { if(digitalRead(button) == HIGH) { digitalWrite(led, HIGH); } else { digitalWrite(led, LOW); } }
  26. Hardware Hacking 101 Night Light Goal: Build a circuit and

    write a program that causes an LED to turn on when the room is dark and off when it is light. You can use the following components: Hint: The button requires a resistor to • 1x Arduino • 1x LED • 1x Photoresistor • 3x Wire • 1x 10kΩ Resistor • 1x Breadboard
  27. Hardware Hacking 101 To recreate the circuit, connect the components

    to the following new pins: • 5V – Photoresistor • Pin A0 – Photoresistor, Resistor • GND – Photoresistor through Resistor Night Light
  28. Hardware Hacking 101 The night light is very similar to

    the light switch. Here’s the code to make it work: • Setup – Configure pin 13 (the LED) as an output. Analog pins are always inputs. • Loop – Read the state of pin A0 (the photoresistor). This will be between 0 and 1023. If it’s a large value, then turn the LED on. Otherwise turn the LED off. int led = 13; int sensor = A0; void setup() { pinMode(led, OUTPUT); } void loop() { if(analogRead(sensor) > 512) { digitalWrite(led, HIGH); } else { digitalWrite(led, LOW); } } Night Light
  29. Hardware Hacking 101 What did you learn today? Today, you

    learned the basics of hardware hacking using an Arduino and some simple components. Read and assemble basic circuits Blink a light automatically Build a simple light switch
  30. Hardware Hacking 101 Bring cool events like this one to

    your school! MLH Localhost makes it easy for you to run fun hacker events for your local community where & when you want. We’ll train you to run the event and ship you a box with everything you need! Schedule your first event online at localhost.mlh.io
  31. Hardware Hacking 101 Want to build more projects? Attend a

    hackathon! Every year, MLH helps organize over 250 weekend-long invention competitions called “hackathons”. Show up, join a team, and bring a crazy idea to life over the course of 24 hours. Find a hackathon near you at mlh.io/events
  32. Hardware Hacking 101 Thank you! @SwiftAlphaOne swift@mlh.io