Hacking Electronics: Learning Electronics with Arduino and Raspberry Pi, 2nd Edition

Simon Monk

Contents at a Glance

1 Getting Started
2 Components
3 Basic Hacks
4 LEDs
5 Batteries and Power
6 Hacking with Arduino 
7 Hacking with Raspberry Pi 
8 Hacking with Modules
9 Hacking with Sensors
10 Audio Hacks
11 Mending and Breaking Electronics
12 Tools
A Parts
Index

e-bookss shop
e-bookss shop
Purchase Now !
Just with Paypal


Book Details
 Price
 2.50 USD
 Pages
 305 p
 File Size
 7,912 KB
 File Type
 PDF format
 ISBN
 978-1-26-001221-7
 Copyright   
 2017 by McGraw-Hill Education  

About the Author
Dr. Simon Monk (Preston, UK) has a degree in Cybernetics and Computer Science and a
PhD in Software Engineering. Monk spent several years as an academic before he returned
to industry, co-founding the mobile software company Momote Ltd. He has been an active
electronics hobbyist since his early teens and is a full-time writer on hobby electronics and
open-source hardware. Dr. Monk is the author of numerous electronics books, specializing in
open-source hardware platforms, especially Arduino and Raspberry Pi. He is also co-author
with Paul Scherz of Practical Electronics for Inventors, Fourth Edition. You can follow
Simon on Twitter, where he is @simonmonk2.

Acknowledgments
Many thanks to all those at McGraw-Hill Education who have done such a great job in producing
this book. In particular, thanks to my editor Michael McCabe, Donna Martone, Lynn Messina,
Patricia Wallenburg, and Claire Splan.
And last but not least, thanks once again to Linda, for her patience and generosity in giving
me space to do this.

Table of Contents
Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxi
CHAPTER 1 Getting Started
Getting Stuff . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Buying Components. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Where to Buy Things to Hack . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
A Basic Toolkit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Stripping Wire . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
You Will Need . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Joining Wires Together by Twisting. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
You Will Need . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Joining Wires by Soldering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Safety . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
You Will Need . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Soldering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Joining Wires . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Testing a Connection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
You Will Need . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Hacking a Computer Fan to Keep Soldering Fumes Away . . . . . . . . . . . 14
You Will Need . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Construction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
CHAPTER 2 Components
A Starter Kit of Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Identifying Electronic Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Resistors. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Capacitors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Diodes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
LEDs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Transistors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Integrated Circuits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Other Stuff . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Surface Mount Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
What Are Current, Resistance, and Voltage? . . . . . . . . . . . . . . . . . . . . . . 25
Current . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Resistance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
Voltage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
Ohm’s Law. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
What Is Power? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
Reading a Schematic Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
The First Rule of Schematics: Positive Voltages Are Uppermost . . 29
Second Rule of Schematics: Things Happen Left to Right . . . . . . 29
Names and Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
Component Symbols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
CHAPTER 3 Basic Hacks
Making a Resistor Get Hot. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
You Will Need . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
The Experiment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
Using Resistors to Divide a Voltage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
You Will Need . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
Construction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
Converting a Resistance to a Voltage (and Make a Light Meter). . . . . . . 37
You Will Need . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
Hacking a Push Light to Make It Light Sensing . . . . . . . . . . . . . . . . . . . 39
You Will Need . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Breadboard. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
Construction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
MOSFET Transistors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
PNP and P-Channel Transistors. . . . . . . . . . . . . . . . . . . . . . . . . . . 45
Common Transistors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
Using a Power MOSFET to Control a Motor. . . . . . . . . . . . . . . . . . . . . . 46
You Will Need . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
Breadboard. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
Selecting a Switch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
Push-Button Switches . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
Microswitches . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
Toggle Switches . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
CHAPTER 4 LEDs
Preventing an LED from Burning Out . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
You Will Need . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
Diodes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
LEDs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
Trying It Out . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
Selecting the Right LED for the Job . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
Brightness and Angle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
Multicolor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
IR and UV . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
LEDs for Illumination . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
Experimenting with RGB LEDs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
You Will Need . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
Making a Constant Current Driver. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
You Will Need . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
Breadboard. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
Construction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
Powering Large Numbers of LEDs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
Making LEDs Flash . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
You Will Need . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
Breadboard. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
How to Use Protoboard (LED Flasher) . . . . . . . . . . . . . . . . . . . . . . . . . . 68
Using Stripboard (LED Flasher) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
Designing the Stripboard Layout. . . . . . . . . . . . . . . . . . . . . . . . . . 69
Construction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
Troubleshooting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
Laser Diode Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
Hacking a Slot Car Racer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
You Will Need . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
Storing Charge in a Capacitor . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
Construction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
Testing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
CHAPTER 5 Batteries and Power
Selecting the Right Battery . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
Battery Capacity. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
Maximum Discharge Rate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
Single-Use Batteries. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
Rechargeable Batteries. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
Charging Batteries (in General) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
C. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
Over-Charging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
Over-Discharging. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
Battery Life . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
Charging a NiMH Battery . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
Simple Charging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
Fast Charging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
Charging a Sealed Lead–Acid Battery . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
Charging with a Variable Power Supply . . . . . . . . . . . . . . . . . . . . 89
Charging a LiPo Battery. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
Hacking a Cell Phone Battery . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
Controlling the Voltage from a Battery . . . . . . . . . . . . . . . . . . . . . . . . . . 93
You Will Need . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
Breadboard. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
Boosting Voltage. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
Calculating How Long a Battery Will Last . . . . . . . . . . . . . . . . . . . . . . . 96
Battery Backup. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
Diodes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
Trickle Charging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
Using Solar Cells . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
Testing a Solar Panel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
Trickle Charging with a Solar Panel . . . . . . . . . . . . . . . . . . . . . . . 102
Minimizing Power Consumption. . . . . . . . . . . . . . . . . . . . . . . . . . 102
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
CHAPTER 6 Hacking with Arduino
Blinking an LED . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
You Will Need . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
Setting Up Arduino . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
Modifying the Blink Sketch. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
Controlling a Relay Using an Arduino. . . . . . . . . . . . . . . . . . . . . . . . . . . 112
Relays. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
Arduino Outputs. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
You Will Need . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
Construction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
Hacking a Toy for Arduino Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
You Will Need . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
Construction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
The Serial Monitor. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
Measuring Voltage with an Arduino. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
You Will Need . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
Construction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
Controlling an LED with an Arduino. . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
You Will Need . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
Construction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
Software (Flashing) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
Software (Brightness) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
Playing a Sound with an Arduino. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
You Will Need . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
Construction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
Using Arduino Shields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
Controlling a Relay from a Web Page . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
You Will Need . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
Switching with an Arduino and Transistor. . . . . . . . . . . . . . . . . . . . . . . . 135
You Will Need . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
Construction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
Using an Alphanumeric LCD Shield with Arduino . . . . . . . . . . . . . . . . . 138
You Will Need . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
Construction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
Controlling a Servo Motor with an Arduino . . . . . . . . . . . . . . . . . . . . . . 140
You Will Need . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
Construction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
Typing Passwords Automatically . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
You Will Need . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
Construction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
CHAPTER 7 Hacking with Raspberry Pi
Setting Up a Raspberry Pi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
Preparation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
Fetching the Example Code. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
Connecting to Your Pi from a Second Computer. . . . . . . . . . . . . . 150
Blinking an LED . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
You Will Need . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
Controlling a Relay with Raspberry Pi . . . . . . . . . . . . . . . . . . . . . . . . . . 156
Controlling a Relay from a Web Page . . . . . . . . . . . . . . . . . . . . . . . . . . . 157
Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160
CHAPTER 8 Hacking with Modules
Detecting Movement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
You Will Need (PIR and LED) . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
Breadboard. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
You Will Need (PIR and Arduino) . . . . . . . . . . . . . . . . . . . . . . . . . 163
Construction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
PIR and Raspberry Pi. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
Using Ultrasonic Rangefinder Modules . . . . . . . . . . . . . . . . . . . . . . . . . . 166
You Will Need . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167
The HC-SR04 Rangefinder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168
Using a Wireless Remote Module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
You Will Need . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
Breadboard. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
Using a Wireless Remote Module with Arduino . . . . . . . . . . . . . . 172
You Will Need . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172
Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
Using a Motor Control Module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174
You Will Need . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177
Breadboard. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177
Using the Control Pins. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178
Making a Robot Rover with Raspberry Pi . . . . . . . . . . . . . . . . . . . . . . . . 179
You Will Need . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180
Construction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180
Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
Using a Seven-Segment Display with Arduino . . . . . . . . . . . . . . . . . . . . 185
You Will Need . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
Construction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188
Using a Seven-Segment Display with Raspberry Pi . . . . . . . . . . . . . . . . 189
You Will Need . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189
Construction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189
Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190
Using RFID Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190
You Will Need . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191
Construction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191
Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193
CHAPTER 9 Hacking with Sensors
Measuring Temperature with an Arduino. . . . . . . . . . . . . . . . . . . . . . . . . 195
You Will Need . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195
Construction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195
Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196
Threshold Sensing with Raspberry Pi . . . . . . . . . . . . . . . . . . . . . . . . . . . 198
You Will Need . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198
Construction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199
Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199
Switching with a Sensor and Comparator Chip . . . . . . . . . . . . . . . . . . . . 201
You Will Need . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202
Construction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202
Using a Digital Temperature Sensor. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203
You Will Need . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204
Construction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204
Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205
Arduino Egg and Spoon . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207
You Will Need . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208
Construction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208
Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209
Measuring Something’s Color . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211
You Will Need . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212
Construction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212
Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215
CHAPTER 10 Audio Hacks
Hacking Audio Leads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217
General Principals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217
Soldering Audio Connectors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219
Converting a Stereo Signal to Mono . . . . . . . . . . . . . . . . . . . . . . . 221
Using a Microphone Module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222
Making an FM Bug . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224
You Will Need . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225
Construction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225
Testing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227
Selecting Loudspeakers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227
Making a 1-Watt Audio Amplifier . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 228
You Will Need . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229
Construction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230
Testing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231
Generating Tones with a 555 Timer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231
You Will Need . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233
Construction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233
Making a USB Music Controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233
You Will Need . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234
Construction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234
Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236
CHAPTER 11 Mending and Breaking Electronics
Avoiding Electrocution. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237
Taking Something Apart AND Putting It Back Together Again . . . . . . . 238
Checking a Fuse . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239
Testing a Battery. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241
Testing a Heating Element . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242
Finding and Replacing Failed Components . . . . . . . . . . . . . . . . . . . . . . . 242
Testing Components. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242
Desoldering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243
Replacement. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244
Scavenging Useful Components. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244
Reusing a Cell Phone Power Adapter. . . . . . . . . . . . . . . . . . . . . . . . . . . . 245
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246
CHAPTER 12 Tools
Using a Multimeter (General) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 247
Continuity and Diode Test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 247
Resistance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248
Capacitance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249
Temperature . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249
AC Voltage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250
DC Voltage. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251
DC Current. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251
AC Current. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 252
Frequency. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 252
Using a Multimeter to Test a Transistor . . . . . . . . . . . . . . . . . . . . . . . . . 252
Using a Lab Power Supply. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 253
Introducing the Oscilloscope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254
Software Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255
Simulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255
Fritzing. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255
EAGLE PCB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256
Online Calculators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 258
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 258
Appendix Parts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 259
Kits to Accompany This Book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 259
Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 260
Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 260
Component Starter Kits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 260
Resistors. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261
Capacitors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261
Semiconductors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262
Hardware and Miscellaneous. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263
Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 264
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265


Bookscreen
e-books shop

Introduction
This is a book about “hacking” electronics. It is not a formal, theory-based book about electronics.
Its sole aim is to equip the reader with the skills he or she needs to use electronics to make
something, whether it’s starting from scratch, connecting together modules, or adapting existing
electronic devices for some new use.
You will learn how to experiment and get your ideas into some kind of order, so that what
you make will work. Along the way, you’ll gain an appreciation for why things work and the
limits of what they can do, and learn how to make prototypes on solderless breadboard, how
to solder components directly to each other, 
and how to use protoboard to make more complex soldered circuits.
You will also learn how to use the popular Arduino microcontroller board, which has become
one of the most important tools available to the electronics hacker. There are over 20 examples of
how to use an Arduino with electronics in this book.
You will also learn how to use the Raspberry Pi 
(a tiny Linux computer) as a tool for electronics hacking.
Electronics has changed. This is a modern book that avoids theory you will likely never use
and instead concentrates on how you can build things using readymade modules when they are
available. There is, after all, no point in reinventing the wheel.
Some of the things explained and described in the book include
● Using LEDs, including high-power Lumileds and Addressable LED strips (Neopixels)
● Using LiPo battery packs and buck-boost power supply modules
● Using sensors to measure light, temperature, acceleration, sound level, and color
● Interfacing the Raspberry Pi and Arduino with external electronics
● Using servo motors
Some of the things described in the book that you can make along the way include
● A smartcard RFID tag reader
● An Internet-controlled hacked electric toy
● A device for measuring color
● An ultrasonic rangefinder
● A remote control robotic rover
● An accelerometer-based version of the “egg and spoon” race
● An audio amplifier
● A bug made from a hacked MP3 FM transmitter
● Working brakes and head lights that can be added to a slot car
● A smart-card reader/spoofer

How to Use This Book
The book contains the following chapters:
Chapter 1 Getting Started The book starts off by telling you where you can buy equipment and
components, as well as things to hack. This chapter also deals with the
basics of soldering and focuses on a project to hack an old computer fan
to make a fume extractor for use while soldering.
Chapter 2 Components This chapter introduces electronic components—or at least the ones you
are likely to use—and explains how to identify them and describes what
they do. It also introduces a small amount of essential theory, which you
will use over and over again.
Chapter 3 Basic Hacks This chapter contains a set of fairly basic “hacking” how-tos, introducing
concepts like using transistors with example projects. It includes hacking
a “push light” to make it automatically turn on when it gets dark and how
to control a motor using power MOSFETs.
Chapter 4 LEDs In addition to discussing regular LEDs and how to use them and make
them flash and so on, this chapter also looks at using constant current
drivers for LEDs and how to power large numbers of LEDs and laser diode modules.
Chapter 5 Batteries and Power
This chapter discusses the various types of battery, both single use and
rechargeable. It also covers how to charge batteries including LiPos.
Automatic battery backup, voltage regulation, and solar charging are also explained.
Chapter 6 Hacking Arduino
The Arduino has become the microcontroller board of choice for
electronics hackers. Its open-source hardware design makes using a
complex device like a microcontroller very straightforward. The chapter
gets you started with the Arduino and includes a few simple how-tos,
like controlling a relay, playing sounds, and controlling servo motors
from an Arduino. It also covers the use of Arduino expansion shields.
Chapter 7 Hacking with Raspberry Pi
The Raspberry Pi single board computer is great for hacking together
electronic projects that require a bit more power than an Arduino can
provide, or that need a network connection or large display. In this
chapter you will learn how to set up and use a Raspberry Pi, as well as
connect electronics to its GPIO pins.
Chapter 8 Hacking with Modules
When you want to make something, you can often use readymade
modules at least for part of the project. Modules exist for all sorts of
things, from wireless remotes to motor drivers.
Chapter 9 Hacking with Sensors
Sensor ICs and modules are available for sensing everything from
temperature to acceleration. In this chapter, we explore a good range
of them and explain how to use them and connect some of them to an Arduino.
Chapter 10 Audio Hacks This chapter has a number of useful how-tos relating to electronics and
sound. It includes making and adapting audio leads, as well as audio
amplifiers, and discusses the use of microphones.
Chapter 11 Mending and Breaking Electronics
Mending electronics and scavenging useful parts from dead electronics
are a worthy activity for the electronics hacker. This chapter explains
how to take things apart and sometimes put them back together again.
Chapter 12 Tools The final chapter of the book is intended as a reference to explain more
about how to get the most out of tools such as multimeters and lab power supplies.
Previous Post Next Post