(see also specific sketches) 12-button keypad, 149–152 actions based on conditions, 44 accelerometer selection guide, 214 actions based on variables, 50–52 Ardumoto shield, 286, 289 Arduino build process and, 533 Audio-Sound Module, 311 arrays in, 25–28 BOB-00099 data sheet, 387 bitwise operations, 56–58 Electret Microphone, 181 breaking out of loops, 49 green LEDs, 255 comparing character/numeric values, 52– LISY300AL breakout board, 206 MIDI breakout shield, 314 54 MP3 breakout board, 311 comparing strings, 54 PIR Motion Sensor, 171 compound operators, 58 PRT-00137 breadboard, 135 controlling build of, 543 ROB-08449 vibration motor, 274 converting numbers to strings, 34–36 ROB-09402 breakout board, 285 converting strings to numbers, 36 WRL-08770, 425 creating, 13–15 WRL-08946, 425 defined, 2, 9 XBee Explorer USB, 433 error messages, 10, 12 speakers, defined, 582 floating-point numbers in, 23 speed functional blocks in, 38–41 continuous rotation servos and, 267–269 LED blinking code example, 13–15–18 controlling for brushed motors, 280–282– libraries and, 517 logical comparisons, 55 287 manipulating strings, 28–34 tracking movement of dial, 190–192 preparing with IDE, 8–11 speed controllers repeating sequence of statements, 45 defined, 263 repeating statements with counters, 47–49 driving brushless motors, 271 returning multiple values from functions, SPI (Serial Peripheral Interface) about, 389–391 41–43 driving 7-segment displays, 418–421 saving, 11, 13–15 SPI library, 391, 517 simple primitive types, 21 SPI_MAX7221_0019 sketch, 418 structuring, 20 split method (Java), 97 slave devices SplitSplit sketch, 32, 33 address numbers and, 390 Sprite library, 517 communicating between Arduino boards, sqrt function, 68 square roots, 68 421–424 SREG (interrupt registers), 197 defined, 390 SSR (solid state relay), 273 identifying, 391 startMeasurement function, 211 sleep function, 573 statements SN754410 H-Bridge, 277 repeating sequence of, 45 snubber diodes, 275, 593 repeating with counters, 47–49 SoftwareSerial library, 126–127, 203, 516 static variables, 147 solderless breadboards, 135 Stepper library, 287, 517 solenoids and relays stepper motors about, 262, 582 about, 263, 582 controlling, 272–273 driving bipolar, 287–289, 290–293 solid state relay (SSR), 273 driving unipolar, 293–295 sound (see audio output) Stepper sketch, 294 Southern Hemisphere sketch, 202, 203 SparkFun Index | 627
Stepper_bipolar sketch, 287 determining state of, 136–139 Stepper_Easystepper sketch, 290 determining time in current state, 144–148 strcat function, 31 hacking remote control, 330–332 strcmp function, 31, 54 interrupts and, 548 strcpy function, 31 reading multiple analog inputs, 157–158 Streaming library, 91 tactile, 138, 583 String class, 35, 536 without external resistors, 139–141 string data type, 22 switchTime function, 146–148 String library SwitchTime sketch, 145 SwitchTimeMultiple sketch, 147 additional information, 30 symbols C language and, 30 creating custom, 347–349 manipulating strings, 28–30 displaying, 345–347 strings larger than single character, 349–352 allocating space for, 536 SyncArduinoClock sketch, 376 arrays and, 28–30, 31 synchronization C language and, 30 binary data and, 104 comparing, 31, 54 clock software, 502–507 concatenating, 31 synthesizers converting numbers to, 34–36 making, 314–316 converting to numbers, 36, 94 MIDI, 311–314 copying, 31 data type representing, 22 T declaring, 31 defined, 28 tactile switches, 138, 583 determining length of, 31 takePicture function, 329 manipulating, 28–30 tan function, 69 multiple fields in, 95–98 TCP (Transmission Control Protocol), 452 null in, 28 <td> tag, 482 splitting comma-separated text into groups, TellyBounce sketch, 364 TellyMate shield, 361–366 32–34 TellyMate sketch, 361 storing/retrieving in program memory, 540– temperature, measuring, 185–187, 408–412, 542 510–513 strlen function, 31 Texas Instrument TMP75, 408–412 strncmp function, 55 text fields/data strtok_r function, 34 structures displaying on TV, 361–366 formatting for LCD displays, 337–340 binary format considerations, 104 LCD displays and, 334–337 packing, 104, 105 receiving in messages, 98–101 substring function, 33 scrolling, 342–344 subtraction (-) operator, 61 sending formatted, 89–91 swap function, 42, 43 sending in messages, 95–98 swap sketch, 42 TextFinder library Sweep sketch, 264–265 about, 99, 452, 463 switch statement, 50–52 find method, 100 SwitchCase sketch, 50 findUtil method, 100 switches getFloat method, 100 about, 583 getString method, 100 detecting closing of, 141–144 getValue method, 100 detecting movement and, 167–169 628 | Index
TextString library, 28 clear method, 257 theremin, 316 init method, 256 thermometers, digital, 408–412 NUM_TLCS constant, 259 tilt sensors, 167–169, 342–344 set method, 257 tilt sketch, 167 setAll method, 257 time delays, 239 update method, 257 Todbot adapters, 397 (see also delay function) tone function animation effects and, 239 about, 297 creating, 367 multiple simultaneous tones, 303 setting delay period, 233 playing simple melodies, 301–303 time lapse photography, 327 playing tones, 299–301 Time library, 373–380, 383, 518 Tone library, 301, 303 time measurement, 239 Tone sketch, 299 (see also millis function) torque, motor, 263 alarms to call functions, 380–383 Toshiba FB6612FNG, 285 displaying time of day, 373–380 <tr> tag, 482 duration of delays, 368–372 transducers, 301 duration of pulses, 372 Transistor-Transistor Logic (TTL), 82 for pressed switches, 144–148 transistors real-time clocks, 384–387, 401–404 about, 583 reducing battery drain, 572–574 choosing for switching, 587 synchronizing clock software, 502–507 controlling solenoids and relays, 272 time conversion tools, 380 driving brushed motors, 276 Time sketch, 373 driving high-power LEDs, 224 TimeAlarmExample sketch, 381 Transmission Control Protocol (TCP), 452 TimeAlarms library, 381–383, 518–522 transmitCarrier function, 577 timebase, defined, 549 trigonometric functions, 69 TimedAction library, 371 troubleshooting timeout, specifying, 373 device connections, 264 timer registers, 549 hardware problems, 599–601 Timer1 library, 560 software problems, 595–598 timers XBee modules, 431 additional information, 550 TRS connector, 327 changing PWM frequency, 565–567 TTL (Transistor-Transistor Logic), 82 countdown, 144–148 TTL level, defined, 82 defined, 382 TV, displaying text on, 361–366 setting duration, 557–559 Twinkle sketch, 301 setting pulse width/duration, 559–562 Twitter library types supported, 548 downloading, 493 TimeRTC sketch, 384 post function, 494 TimeRTCSet sketch, 386 wait function, 494 TimeSerial sketch, 375 Twitter messages, sending, 493–496 Time_NTP sketch, 505 TinyGPS library, 201–206, 205 U TLC sketch, 255 TLC5940 chip, 255–259 UARTs, 131 Tlc5940 library UDP (User Datagram Protocol), 496–500, 504 about, 255 UdpNtp sketch, 502 additional information, 259 UDPSendReceive sketch, 498 Index | 629
UDPSendReceiveStrings sketch, 496 reading on analog pins, 152 UDPTest sketch, 500 responding to changes in, 161 ULN2003A Darlington driver chip, 293–295 reverse EMF, 272 unipolar steppers voltage divider, 162 VW_MAX_MESSAGE_LEN constant, 430 about, 263 driving, 293–295 W Unix time, 374, 380 unsigned keyword, 22 WAV files, playing, 308–311 USB protocol WaveShieldPlaySelection sketch, 308 boards and, 573 web pages digital pins and, 134 HID and, 115 creating with forms, 483–486 MIDI devices and, 314 handling requests for, 474–479 serial communications and, 82 large amounts of data and, 486–493 XBee adapters, 433 web servers User Datagram Protocol (UDP), 496–500, 504 formatting requests, 479–483 USGlobalSat EM-406A GPS module, 203 handling requests, 471–474 UTC (Coordinated Universal Time), 504 handling requests for specific pages, 474– V 479 requesting data from, 462–466 variable resistors, 135, 581 requesting data in XML, 466–468 variables setting up Arduino, 469–471 WebClientDHCP_DNS sketch, 460 actions based on, 50–52 WebClientDNS sketch, 458 defined, 42 WebClientGoogleFinance sketch, 464 global, 147, 536 WebClient_Babelfish sketch, 465 simple primitive types, 21 Webduino web server, 493 static, 147 WebServerMultiPage sketch, 475 volatile, 196, 556 WebServerMultiPageHTML sketch, 479 version control, 14 WebServerMultiPageHTMLProgmem sketch, Vibrate sketch, 274 Vibrate_Photocell sketch, 275 486 vibration WebServerParsing sketch, 472 detecting, 180 WebServerPost sketch, 483 making objects shake, 273–275 Web_Server sketch, 469 VirtualWire library, 427–431 while loop, 46 visual output (see LEDs) Wii nunchuck void data type, 22 volatile variables, 196, 556 accelerometer in, 214, 397–401 voltage controlling Google Earth via, 116, 120 changing range of values, 154 WiichuckSerial sketch, 120 digital monitoring, 137 Windows environment digital output and, 217 Arduino IDE installation, 6 displaying, 158–161 moving mouse cursor, 112–115 forward, 219 XBee Series 1 configuration, 435 knock sensors and, 180 XBee Series 2 configuration, 433 LCD displays and, 336 Wire library LED specifications, 219 about, 391, 517 measuring, 162–164 accessing RTCs, 401–404 measuring pulse duration, 372 adding, 394 additional information, 391 available function, 401 630 | Index
begin function, 400 connecting to networks, 431–437 beginTransmission function, 407 ZTerm program, 88 creating libraries example, 527 endTransmission function, 400 receive function, 401, 403, 410 requestFrom function, 400, 403, 407 send function, 400, 413 wireless communication activating actuators, 446–450 connecting to 802.15.4 network, 431–437 connecting to ZigBee networks, 431–437 remote controls and, 317 sending messages to XBees, 438–439 sending messages via, 425–431 sensor data between XBees, 440 word function, 79–80 X X-CTU application XBee Series 1 configuration, 435 XBee Series 2 configuration, 433 XBee Actuate sketch, 447 XBee modules about, 425 activating actuators, 446–450 connecting to 802.15.4 networks, 431–437 connecting to ZigBee networks, 431–437 Remote AT Command feature, 446 sending messages to, 438–439 sending sensor data between, 440–444 troubleshooting, 431 ZigBee compatibility, 431 XBeeAnalogReceive sketch, 442 XBeeAnalogReceiveSeries1 sketch, 444 XBeeEcho sketch, 432 XBeeMessage sketch, 438 XML format, 466–468 Z Zambetti, Nicholas, 254 zero ASCII value, 28 leading, 415 ZIGBEE COORDINATOR AT function, 434, 446 ZIGBEE ROUTER AT function, 434, 441, 446 ZigBee standard about, 431 Index | 631
About the Author Michael Margolis is a technologist in the field of real time computing with expertise in developing and delivering hardware and software for interacting with the environ- ment. He has over 30 years of experience in a wide range of relevant technologies, working with Sony, Microsoft, Lucent/Bell Labs, and most recently as Chief Technical Officer with Avaya. Colophon The animal on the cover of Arduino Cookbook is a toy rabbit. Mechanical toys like this one move by means of springs, gears, pulleys, levers, or other simple machines, powered by mechanical energy. Such toys have a long history, with ancient examples known from Greece, China, and the Arab world. Mechanical toy making flourished in early modern Europe. In the late 1400s, German inventor Karel Grod demonstrated flying wind-up toys. Prominent scientists of the day, including Leonardo da Vinci, Descartes, and Galileo Galilei, were noted for their work on mechanical toys. Da Vinci’s famed mechanical lion, built in 1509 for Louis XII, walked up to the king and tore open its chest to reveal a fleur-de-lis. The art of mechanical toy making is considered to have reached its pinnacle in the late eighteenth century, with the famed “automata” of the Swiss watchmaker Pierre Jaquet- Droz and his son Henri-Louis. Their human figures performed such lifelike actions as dipping a pen in an inkwell, writing full sentences, drawing sketches, and blowing eraser dust from the page. In the nineteenth century, European and American compa- nies turned out popular clockwork toys that remain collectible today. Because these original toys, which had complicated works and elaborate decorations, were costly and time-consuming to make, they were reserved for the amusement of royalty or the entertainment of adults. Only since the late nineteenth century, with the appearance of mass production and cheap materials (tin, and later, plastic), have me- chanical toys been considered playthings for children. These inexpensive moving nov- elties were popular for about a century, until battery-operated toys superseded them. The cover image is from the Dover Pictorial Archive. The cover font is Adobe ITC Garamond. The text font is Linotype Birka; the heading font is Adobe Myriad Con- densed; and the code font is LucasFont’s TheSansMonoCondensed.
Search
Read the Text Version
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
- 118
- 119
- 120
- 121
- 122
- 123
- 124
- 125
- 126
- 127
- 128
- 129
- 130
- 131
- 132
- 133
- 134
- 135
- 136
- 137
- 138
- 139
- 140
- 141
- 142
- 143
- 144
- 145
- 146
- 147
- 148
- 149
- 150
- 151
- 152
- 153
- 154
- 155
- 156
- 157
- 158
- 159
- 160
- 161
- 162
- 163
- 164
- 165
- 166
- 167
- 168
- 169
- 170
- 171
- 172
- 173
- 174
- 175
- 176
- 177
- 178
- 179
- 180
- 181
- 182
- 183
- 184
- 185
- 186
- 187
- 188
- 189
- 190
- 191
- 192
- 193
- 194
- 195
- 196
- 197
- 198
- 199
- 200
- 201
- 202
- 203
- 204
- 205
- 206
- 207
- 208
- 209
- 210
- 211
- 212
- 213
- 214
- 215
- 216
- 217
- 218
- 219
- 220
- 221
- 222
- 223
- 224
- 225
- 226
- 227
- 228
- 229
- 230
- 231
- 232
- 233
- 234
- 235
- 236
- 237
- 238
- 239
- 240
- 241
- 242
- 243
- 244
- 245
- 246
- 247
- 248
- 249
- 250
- 251
- 252
- 253
- 254
- 255
- 256
- 257
- 258
- 259
- 260
- 261
- 262
- 263
- 264
- 265
- 266
- 267
- 268
- 269
- 270
- 271
- 272
- 273
- 274
- 275
- 276
- 277
- 278
- 279
- 280
- 281
- 282
- 283
- 284
- 285
- 286
- 287
- 288
- 289
- 290
- 291
- 292
- 293
- 294
- 295
- 296
- 297
- 298
- 299
- 300
- 301
- 302
- 303
- 304
- 305
- 306
- 307
- 308
- 309
- 310
- 311
- 312
- 313
- 314
- 315
- 316
- 317
- 318
- 319
- 320
- 321
- 322
- 323
- 324
- 325
- 326
- 327
- 328
- 329
- 330
- 331
- 332
- 333
- 334
- 335
- 336
- 337
- 338
- 339
- 340
- 341
- 342
- 343
- 344
- 345
- 346
- 347
- 348
- 349
- 350
- 351
- 352
- 353
- 354
- 355
- 356
- 357
- 358
- 359
- 360
- 361
- 362
- 363
- 364
- 365
- 366
- 367
- 368
- 369
- 370
- 371
- 372
- 373
- 374
- 375
- 376
- 377
- 378
- 379
- 380
- 381
- 382
- 383
- 384
- 385
- 386
- 387
- 388
- 389
- 390
- 391
- 392
- 393
- 394
- 395
- 396
- 397
- 398
- 399
- 400
- 401
- 402
- 403
- 404
- 405
- 406
- 407
- 408
- 409
- 410
- 411
- 412
- 413
- 414
- 415
- 416
- 417
- 418
- 419
- 420
- 421
- 422
- 423
- 424
- 425
- 426
- 427
- 428
- 429
- 430
- 431
- 432
- 433
- 434
- 435
- 436
- 437
- 438
- 439
- 440
- 441
- 442
- 443
- 444
- 445
- 446
- 447
- 448
- 449
- 450
- 451
- 452
- 453
- 454
- 455
- 456
- 457
- 458
- 459
- 460
- 461
- 462
- 463
- 464
- 465
- 466
- 467
- 468
- 469
- 470
- 471
- 472
- 473
- 474
- 475
- 476
- 477
- 478
- 479
- 480
- 481
- 482
- 483
- 484
- 485
- 486
- 487
- 488
- 489
- 490
- 491
- 492
- 493
- 494
- 495
- 496
- 497
- 498
- 499
- 500
- 501
- 502
- 503
- 504
- 505
- 506
- 507
- 508
- 509
- 510
- 511
- 512
- 513
- 514
- 515
- 516
- 517
- 518
- 519
- 520
- 521
- 522
- 523
- 524
- 525
- 526
- 527
- 528
- 529
- 530
- 531
- 532
- 533
- 534
- 535
- 536
- 537
- 538
- 539
- 540
- 541
- 542
- 543
- 544
- 545
- 546
- 547
- 548
- 549
- 550
- 551
- 552
- 553
- 554
- 555
- 556
- 557
- 558
- 559
- 560
- 561
- 562
- 563
- 564
- 565
- 566
- 567
- 568
- 569
- 570
- 571
- 572
- 573
- 574
- 575
- 576
- 577
- 578
- 579
- 580
- 581
- 582
- 583
- 584
- 585
- 586
- 587
- 588
- 589
- 590
- 591
- 592
- 593
- 594
- 595
- 596
- 597
- 598
- 599
- 600
- 601
- 602
- 603
- 604
- 605
- 606
- 607
- 608
- 609
- 610
- 611
- 612
- 613
- 614
- 615
- 616
- 617
- 618
- 619
- 620
- 621
- 622
- 623
- 624
- 625
- 626
- 627
- 628
- 629
- 630
- 631
- 632
- 633
- 634
- 635
- 636
- 637
- 638
- 639
- 640
- 641
- 642
- 643
- 644
- 645
- 646
- 647
- 648
- 649
- 650
- 651
- 652
- 653
- 654
- 655
- 656
- 657
- 658
- 1 - 50
- 51 - 100
- 101 - 150
- 151 - 200
- 201 - 250
- 251 - 300
- 301 - 350
- 351 - 400
- 401 - 450
- 451 - 500
- 501 - 550
- 551 - 600
- 601 - 650
- 651 - 658
Pages: