0% found this document useful (0 votes)
17 views

Contents

This document is an introduction to using Arduino boards to power various electronics projects. It covers basic concepts like how to set up an Arduino board and write code. It then provides instructions and code for 14 hands-on projects using LEDs, sensors and displays to teach programming and electronics skills.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Contents

This document is an introduction to using Arduino boards to power various electronics projects. It covers basic concepts like how to set up an Arduino board and write code. It then provides instructions and code for 14 hands-on projects using LEDs, sensors and displays to teach programming and electronics skills.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

Beginning Arduino

Michael McRoberts
Contents at a Glance

About the Author ............................................................................................................... xix


About the Technical Reviewers ......................................................................................... xxi
Acknowledgments ........................................................................................................... xxiii
Introduction ...................................................................................................................... xxv

■ Chapter 1: Getting Started .................................................................................................1


■ Chapter 2: Light ‘Em Up ...................................................................................................21
■ Chapter 3: LED Effects .....................................................................................................49
■ Chapter 4: Simple Sounders and Sensors .......................................................................79
■ Chapter 5: Driving a DC Motor .........................................................................................97
■ Chapter 6: Binary Counters and Shift Register I/O ........................................................111
■ Chapter 7: LED Displays.................................................................................................127
■ Chapter 8: Liquid Crystal Displays ................................................................................165
■ Chapter 9: Servos ..........................................................................................................183
■ Chapter 10: Steppers and Robots ..................................................................................199
■ Chapter 11: Pressure Sensors .......................................................................................223
■ Chapter 12: Touch Screens ............................................................................................251
■ Chapter 13: Temperature Sensors .................................................................................271
■ Chapter 14: Ultrasonic Rangefinders.............................................................................285

v
■ CONTENTS AT A GLANCE

■ Chapter 15: Reading and Writing to an SD Card ............................................................305


■ Chapter 16: Making an RFID Reader..............................................................................325
■ Chapter 17: Communicating over Ethernet ...................................................................341

Index .................................................................................................................................391

vi
Contents

About the Author ............................................................................................................... xix


About the Technical Reviewers ......................................................................................... xxi
Acknowledgments ........................................................................................................... xxiii
Introduction ...................................................................................................................... xxv

■ Chapter 1: Getting Started .................................................................................................1


How to Use This Book....................................................................................................................1
What You Will Need........................................................................................................................2
What Exactly Is an Arduino? ..........................................................................................................2
Setting Up Your Arduino.................................................................................................................5
Upload Your First Sketch .............................................................................................................13
The Arduino IDE ...........................................................................................................................14
Summary .....................................................................................................................................20

■ Chapter 2: Light ‘Em Up ...................................................................................................21


Project 1 — LED Flasher .............................................................................................................21
Parts Required ..................................................................................................................................................... 21
Connect It Up ....................................................................................................................................................... 22
Enter the Code ..................................................................................................................................................... 23
Project 1 — LED Flasher – Code Overview ......................................................................................................... 23
Project 1 — LED Flasher – Hardware Overview .................................................................................................. 27

Project 2 – S.O.S. Morse Code Signaler.......................................................................................31


Enter the code ..................................................................................................................................................... 31
Project 2 – S.O.S. Morse Code Signaler – Code Overview ................................................................................... 32

vii
■ CONTENTS

Project 3 – Traffic Lights .............................................................................................................34


Parts Required ..................................................................................................................................................... 34
Connect It Up ....................................................................................................................................................... 34
Enter the Code ..................................................................................................................................................... 35

Project 4 – Interactive Traffic Lights............................................................................................36


Parts Required ..................................................................................................................................................... 36
Connect It Up ....................................................................................................................................................... 37
Enter the Code ..................................................................................................................................................... 38
Project 4 – Interactive Traffic Lights - Code Overview......................................................................................... 40
Project 4 – Interactive Traffic Lights - Hardware Overview ................................................................................. 43
Logic States ......................................................................................................................................................... 43
Pull-Down Resistors ............................................................................................................................................ 44
Pull-Up Resistors ................................................................................................................................................. 45
The Arduino’s Internal Pull-Up Resistors ............................................................................................................. 47

Summary .....................................................................................................................................47

■ Chapter 3: LED Effects .....................................................................................................49


Project 5 – LED Chase Effect .......................................................................................................49
Parts Required ..................................................................................................................................................... 49
Connect It Up ....................................................................................................................................................... 49
Enter the Code ..................................................................................................................................................... 50
Project 5 – LED Chase Effect – Code Overview ................................................................................................... 51

Project 6 – Interactive LED Chase Effect .....................................................................................52


Parts Required ..................................................................................................................................................... 52
Connect It Up ....................................................................................................................................................... 53
Enter the Code ..................................................................................................................................................... 53
Project 6 – Interactive LED Chase Effect – Code Overview ................................................................................. 54
Project 6 – Interactive LED Chase Effect – Hardware Overview .......................................................................... 55

Project 7 – Pulsating Lamp .........................................................................................................56


Parts Required ..................................................................................................................................................... 56
Connect It Up ....................................................................................................................................................... 56

viii
■ CONTENTS

Enter the Code ..................................................................................................................................................... 57


Project 7 – Pulsating Lamp – Code Overview...................................................................................................... 57

Project 8 – RGB Mood Lamp........................................................................................................58


Parts Required ..................................................................................................................................................... 58
Connect It Up ....................................................................................................................................................... 59
Enter the Code ..................................................................................................................................................... 59
Project 8 – RGB Mood Lamp – Code Overview .................................................................................................... 60

Project 9 – LED Fire Effect ..........................................................................................................63


Parts Required ..................................................................................................................................................... 64
Connect It Up ....................................................................................................................................................... 64
Enter the Code ..................................................................................................................................................... 64
Project 9 – LED Fire Effect – Code Overview ....................................................................................................... 65

Project 10 – Serial Controlled Mood Lamp ..................................................................................66


Enter the Code ..................................................................................................................................................... 66
Project 10 – Serial-Controlled Mood Lamp – Code Overview.............................................................................. 68
Pointers in a Nutshell .......................................................................................................................................... 71

Summary .....................................................................................................................................77

■ Chapter 4: Simple Sounders and Sensors .......................................................................79


Project 11 – Piezo Sounder Alarm ...............................................................................................79
Parts Required ..................................................................................................................................................... 79
Connect It Up ....................................................................................................................................................... 80
Enter the Code ..................................................................................................................................................... 80
Project 11 – Piezo Sounder Alarm – Code Overview ........................................................................................... 81
Project 11 – Piezo Sounder Alarm – Hardware Overview.................................................................................... 82

Project 12 – Piezo-Sounder Melody Player .................................................................................83


Enter the Code ..................................................................................................................................................... 83
Project 12 – Piezo-Sounder Melody Player – Code Overview ............................................................................. 85

Project 13 – Piezo Knock Sensor ................................................................................................88


Parts Required ..................................................................................................................................................... 88
Connect It Up ....................................................................................................................................................... 88

ix
■ CONTENTS

Enter the Code ..................................................................................................................................................... 89


Project 13 – Piezo Knock Sensor – Code Overview ............................................................................................. 90

Project 14 – Light Sensor ............................................................................................................91


Parts Required ..................................................................................................................................................... 91
Connect It Up ....................................................................................................................................................... 91
Enter the Code ..................................................................................................................................................... 92
Project 14 – Light Sensor – Hardware Overview ................................................................................................. 93

Summary .....................................................................................................................................95
■ Chapter 5: Driving a DC Motor .........................................................................................97
Project 15 – Simple Motor Control ..............................................................................................97
Parts Required ..................................................................................................................................................... 98
Connect It Up ....................................................................................................................................................... 98
Enter the Code ..................................................................................................................................................... 99
Project 15 – Simple Motor Control – Code Overview ........................................................................................ 100
Project 15 – Simple Motor Control – Hardware Overview ................................................................................. 101
Transistors ......................................................................................................................................................... 101
Motors ............................................................................................................................................................... 102
Diodes................................................................................................................................................................ 102

Project 16 – Using an L293D Motor Driver IC ............................................................................103


Parts Required ................................................................................................................................................... 103
Connect It Up ..................................................................................................................................................... 103
Enter the Code ................................................................................................................................................... 104
Project 16 – Using an L293D Motor Driver IC – Code Overview ........................................................................ 105
Project 16 – Using an L293D Motor Driver IC – Hardware Overview ................................................................. 106

Summary ...................................................................................................................................108

■ Chapter 6: Binary Counters and Shift Register I/O ........................................................111


Project 17 – Shift Register 8-Bit Binary Counter .......................................................................111
Parts Required ................................................................................................................................................... 111
Connect It Up ..................................................................................................................................................... 111
Enter the Code ................................................................................................................................................... 112

x
■ CONTENTS

The Binary Number System ............................................................................................................................... 113


Project 17 – Shift Register 8-Bit Binary Counter - Hardware Overview ............................................................ 115
Project 17 – Shift Register 8-Bit Binary Counter – Code Overview ................................................................... 117
Bitwise Operators .............................................................................................................................................. 119
Project 17 – Code Overview (continued) ........................................................................................................... 120

Project 18 – Dual 8-Bit Binary Counters ...................................................................................122


Parts Required ................................................................................................................................................... 122
Connect It Up ..................................................................................................................................................... 123
Enter the Code ................................................................................................................................................... 124
Project 18 Code & Hardware Overview.............................................................................................................. 125

Summary ...................................................................................................................................126

■ Chapter 7: LED Displays.................................................................................................127


Project 19 – LED Dot Matrix Display – Basic Animation ............................................................127
Parts Required ................................................................................................................................................... 127
Connect It Up ..................................................................................................................................................... 128
Enter the Code ................................................................................................................................................... 130
Project 19 – LED Dot-Matrix – Basic Animation – Hardware Overview ............................................................. 131
Project 19 – LED Dot-Matrix – Basic Animation – Code Overview .................................................................... 134

Project 20 – LED Dot-Matrix Display – Scrolling Sprite.............................................................137


Enter the Code ................................................................................................................................................... 137
Project 20 – LED Dot-Matrix – Scrolling Sprite – Code Overview...................................................................... 138

Project 21 – LED Dot-Matrix Display – Scrolling Message ........................................................141


Parts Required ................................................................................................................................................... 141
Connect It Up ..................................................................................................................................................... 142
Enter the Code ................................................................................................................................................... 143
Project 21 – LED Dot-Matrix – Scrolling Message – Hardware Overview ......................................................... 147
Project 21 – LED Dot-Matrix – Scrolling Message – Code Overview................................................................. 151

Project 22 – LED Dot Matrix Display – Pong Game ...................................................................158


Parts Required ................................................................................................................................................... 158
Connect It Up ..................................................................................................................................................... 158

xi
■ CONTENTS

Upload the Code ................................................................................................................................................ 159


Project 22 – LED Dot Matrix – Pong Game ........................................................................................................ 160

Summary ...................................................................................................................................163

■ Chapter 8: Liquid Crystal Displays ................................................................................165


Project 23 – Basic LCD Control .................................................................................................165
Parts Required ................................................................................................................................................... 165
Connect It Up ..................................................................................................................................................... 166
Enter the Code ................................................................................................................................................... 167
Project 23 – Basic LCD Control – Code Overview .............................................................................................. 170
Project 23 – Basic LCD Control – Hardware Overview ...................................................................................... 174

Project 24 – LCD Temperature Display ......................................................................................174


Parts Required ................................................................................................................................................... 175
Connect It Up ..................................................................................................................................................... 175
Enter the Code ................................................................................................................................................... 176
Project 24 – LCD Temperature Display .............................................................................................................. 177

Summary ...................................................................................................................................181

■ Chapter 9: Servos ..........................................................................................................183


Project 25 – Servo Control ........................................................................................................184
Parts Required ................................................................................................................................................... 184
Connect It Up ..................................................................................................................................................... 185
Enter the Code ................................................................................................................................................... 186
Project 25 – Servo Control – Code Overview..................................................................................................... 186
Project 25 – Servo Control – Hardware Overview ............................................................................................. 187

Project 26 – Dual Servo Control ................................................................................................188


Parts Required ................................................................................................................................................... 188
Connect It Up ..................................................................................................................................................... 189
Enter the Code ................................................................................................................................................... 189
Project 26 – Dual Servo Control – Code Overview ............................................................................................ 191

xii
■ CONTENTS

Project 27 – Joystick Servo Control ..........................................................................................193


Parts Required ................................................................................................................................................... 193
Connect It Up ..................................................................................................................................................... 193
Enter the Code ................................................................................................................................................... 195
Project 27 – Joystick Servo Control – Code Overview....................................................................................... 196

Summary ...................................................................................................................................198

■ Chapter 10: Steppers and Robots ..................................................................................199


Project 28 – Basic Stepper Control ...........................................................................................199
Parts Required ................................................................................................................................................... 199
Connect It Up ..................................................................................................................................................... 200
Enter the Code ................................................................................................................................................... 201
Project 28 – Basic Stepper Control – Code Overview........................................................................................ 202
Project 28 – Basic Stepper Control – Hardware Overview ................................................................................ 203

Project 29 – Using a Motor Shield .............................................................................................205


Parts Required ................................................................................................................................................... 205
Connect It Up ..................................................................................................................................................... 206
Enter the Code ................................................................................................................................................... 207
Project 29 – Using a Motor Shield – Code Overview ......................................................................................... 208
Project 29 – Using a Motor Shield – Hardware Overview.................................................................................. 210

Project 30 – Line-Following Robot ............................................................................................211


Parts Required ................................................................................................................................................... 211
Connect It Up ..................................................................................................................................................... 212
Enter the Code ................................................................................................................................................... 215
Project 30 – Line-Following Robot – Code Overview ........................................................................................ 217

Summary ...................................................................................................................................221

■ Chapter 11: Pressure Sensors .......................................................................................223


Project 31 – Digital Pressure Sensor.........................................................................................223
Parts Required ................................................................................................................................................... 223
Connect It Up ..................................................................................................................................................... 224

xiii
■ CONTENTS

Enter the Code ................................................................................................................................................... 225


Project 31 – Digital Pressure Sensor – Code Overview ..................................................................................... 227
I2C Bus .............................................................................................................................................................. 228

Project 32 – Digital Barograph ..................................................................................................236


Parts Required ................................................................................................................................................... 236
Connect It Up ..................................................................................................................................................... 237
Enter the Code ................................................................................................................................................... 239
Project 32 – Digital Barograph – Code Overview .............................................................................................. 243

Summary ...................................................................................................................................249
Subjects and Concepts Covered in Chapter 11.................................................................................................. 249

■ Chapter 12: Touch Screens ............................................................................................251


Project 33 – Basic Touch Screen ...............................................................................................251
Parts Required ................................................................................................................................................... 251
Connect It Up ..................................................................................................................................................... 252
Enter the Code ................................................................................................................................................... 253
Project 33 – Basic Touch Screen – Hardware Overview .................................................................................... 254
Project 33 – Basic Touch Screen – Code Overview ........................................................................................... 256

Project 34 – Touch Screen Keypad ............................................................................................258


Parts Required ................................................................................................................................................... 258
Connect It Up ..................................................................................................................................................... 259
Enter the Code ................................................................................................................................................... 260
Project 34 –Touch Screen Keypad – Code Overview ......................................................................................... 262

Project 35 – Touch Screen Light Controller ...............................................................................264


Parts Required ................................................................................................................................................... 264
Connect It Up ..................................................................................................................................................... 265
Enter the Code ................................................................................................................................................... 266
Project 35 – Touch Screen Controller – Code Overview .................................................................................... 268

Summary ...................................................................................................................................270

xiv
■ CONTENTS

■ Chapter 13: Temperature Sensors .................................................................................271


Project 36 – Serial Temperature Sensor ....................................................................................271
Parts Required ................................................................................................................................................... 271
Connect It Up ..................................................................................................................................................... 272
Enter the Code ................................................................................................................................................... 273
Project 36 – Serial Temperature Sensor – Code Overview ................................................................................ 274

Project 37 – One-Wire Digital Temperature Sensor ...................................................................275


Parts Required ................................................................................................................................................... 275
Connect It Up ..................................................................................................................................................... 276
Enter the Code ................................................................................................................................................... 277
Project 37 – 1-Wire Digital Temperature Sensor – Code Overview ................................................................... 281

Summary ...................................................................................................................................284

■ Chapter 14: Ultrasonic Rangefinders.............................................................................285


Project 38 – Simple Ultrasonic Rangefinder .............................................................................285
Parts Required ................................................................................................................................................... 285
Connect It Up ..................................................................................................................................................... 285
Enter the Code ................................................................................................................................................... 286
Project 38 – Simple Ultrasonic Rangefinder – Code Overview .......................................................................... 287
Project 38 – Simple Ultrasonic Rangefinder – Hardware Overview .................................................................. 288
Project 39 – Ultrasonic Distance Display ..................................................................................289
Parts Required ................................................................................................................................................... 289
Connect It Up ..................................................................................................................................................... 290
Enter the Code ................................................................................................................................................... 292
Project 39 – Ultrasonic Distance Display – Code Overview ............................................................................... 293

Project 40 – Ultrasonic Alarm....................................................................................................296


Parts Required ................................................................................................................................................... 296
Connect It Up ..................................................................................................................................................... 297
Enter the Code ................................................................................................................................................... 297
Project 40 – Ultrasonic Alarm – Code Overview ................................................................................................ 299

xv
■ CONTENTS

Project 41 – Ultrasonic Theremin ..............................................................................................302


Enter the Code ................................................................................................................................................... 302
Project 41 – Ultrasonic Theremin – Code Overview .......................................................................................... 303

Summary ...................................................................................................................................304
■ Chapter 15: Reading and Writing to an SD Card ............................................................305
Project 42 – Simple SD Card/Read Write ..................................................................................305
Parts Required ................................................................................................................................................... 305
Connect It Up ..................................................................................................................................................... 306
Enter the Code ................................................................................................................................................... 307
Project 42 – Simple SD Card Read/Write – Code Overview............................................................................... 309

Project 43 – Temperature SD Datalogger ..................................................................................312


Parts Required ................................................................................................................................................... 313
Connect It Up ..................................................................................................................................................... 313
Enter the Code ................................................................................................................................................... 315
Project 43 – Temperature SD Datalogger – Code Overview .............................................................................. 317
Project 43 – Temperature SD Datalogger – Hardware Overview ....................................................................... 322

Summary ...................................................................................................................................323
■ Chapter 16: Making an RFID Reader..............................................................................325
Project 44 – Simple RFID Reader ..............................................................................................325
Parts Required ................................................................................................................................................... 325
Connect It Up ..................................................................................................................................................... 326
Enter the Code ................................................................................................................................................... 327
Project 44 – Simple RFID Reader – CODE Overview .......................................................................................... 327
Project 44 – Simple RFID Reader – Hardware Overview ................................................................................... 328

Project 45—Access Control System .........................................................................................329


Parts Required ................................................................................................................................................... 329
Connect It Up ..................................................................................................................................................... 330
Enter the Code ................................................................................................................................................... 331
Project 45 – Access Control System – Code Overview ...................................................................................... 334

Summary ...................................................................................................................................339

xvi
■ CONTENTS

■ Chapter 17: Communicating over Ethernet ...................................................................341


Project 46 – Ethernet Shield .....................................................................................................341
Parts Required ................................................................................................................................................... 341
Connect It Up ..................................................................................................................................................... 341
Enter the Code ................................................................................................................................................... 342
Things You Need to Know about Networking..................................................................................................... 345
Project 46 – Ethernet Shield – Code Overview .................................................................................................. 346

Project 47 — Internet Weather Display.....................................................................................350


Enter the Code ................................................................................................................................................... 353
Project 47 – Internet Weather Display – Code Overview ................................................................................... 357

Project 48 — Email Alert System ..............................................................................................360


Enter the Code ................................................................................................................................................... 360
Project 48 – Email Alert System — Code Overview .......................................................................................... 364

Project 49 — Twitterbot ............................................................................................................369


Enter the Code ................................................................................................................................................... 369
Project 49 – Twitterbot – Code Overview .......................................................................................................... 372

Project 50 – RSS Weather Reader .............................................................................................377


Enter the Code ................................................................................................................................................... 377
Project 50 – RSS Weather Reader – Code Overview ......................................................................................... 381
Summary ...................................................................................................................................389

Index .................................................................................................................................391

xvii

You might also like