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 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
6539
6540
6541
6542
6543
6544
6545
6546
6547
6548
6549
6550
6551
6552
6553
6554
6555
6556
6557
6558
6559
6560
6561
6562
6563
6564
6565
6566
6567
6568
6569
6570
6571
6572
6573
6574
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
6591
6592
6593
6594
6595
6596
6597
6598
6599
6600
6601
6602
6603
6604
6605
6606
6607
6608
6609
6610
6611
6612
6613
6614
6615
6616
6617
6618
6619
6620
6621
6622
6623
6624
6625
6626
6627
6628
6629
6630
6631
6632
6633
6634
6635
6636
6637
6638
6639
6640
6641
6642
6643
6644
6645
6646
6647
6648
6649
6650
6651
6652
6653
6654
6655
6656
6657
6658
6659
6660
6661
6662
6663
6664
6665
6666
6667
6668
6669
6670
6671
6672
6673
6674
6675
6676
6677
6678
6679
6680
6681
6682
6683
6684
6685
6686
6687
6688
6689
6690
6691
6692
6693
6694
6695
6696
6697
6698
6699
6700
6701
6702
6703
6704
6705
6706
6707
6708
6709
6710
6711
6712
6713
6714
6715
6716
6717
6718
6719
6720
6721
6722
6723
6724
6725
6726
6727
6728
6729
6730
6731
6732
6733
6734
6735
6736
6737
6738
6739
6740
6741
6742
6743
6744
6745
6746
6747
6748
6749
6750
6751
6752
6753
6754
6755
6756
6757
6758
6759
6760
6761
6762
6763
6764
6765
6766
6767
6768
6769
6770
6771
6772
6773
6774
6775
6776
6777
6778
6779
6780
6781
6782
6783
6784
6785
6786
6787
6788
6789
6790
6791
6792
6793
6794
6795
6796
6797
6798
6799
6800
6801
6802
6803
6804
6805
6806
6807
6808
6809
6810
6811
6812
6813
6814
6815
6816
6817
6818
6819
6820
6821
6822
6823
6824
6825
6826
6827
6828
6829
6830
6831
6832
6833
6834
6835
6836
6837
6838
6839
6840
6841
6842
6843
6844
6845
6846
6847
6848
6849
6850
6851
6852
6853
6854
6855
6856
6857
6858
6859
6860
6861
6862
6863
6864
6865
6866
6867
6868
6869
6870
6871
6872
6873
6874
6875
6876
6877
6878
6879
6880
6881
6882
6883
6884
6885
6886
6887
6888
6889
6890
6891
6892
6893
6894
6895
6896
6897
6898
6899
6900
6901
6902
6903
6904
6905
6906
6907
6908
6909
6910
6911
6912
6913
6914
6915
6916
6917
6918
6919
6920
6921
6922
6923
6924
6925
6926
6927
6928
6929
6930
6931
6932
6933
6934
6935
6936
6937
6938
6939
6940
6941
6942
6943
6944
6945
6946
6947
6948
6949
6950
6951
6952
6953
6954
6955
6956
6957
6958
6959
6960
6961
6962
6963
6964
6965
6966
6967
6968
6969
6970
6971
6972
6973
6974
6975
6976
6977
6978
6979
6980
6981
6982
6983
6984
6985
6986
6987
6988
6989
6990
6991
6992
6993
6994
6995
6996
6997
6998
6999
7000
7001
7002
7003
7004
7005
7006
7007
7008
7009
7010
7011
7012
7013
7014
7015
7016
7017
7018
7019
7020
7021
7022
7023
7024
7025
7026
7027
7028
7029
7030
7031
7032
7033
7034
7035
7036
7037
7038
7039
7040
7041
7042
7043
7044
7045
7046
7047
7048
7049
7050
7051
7052
7053
7054
7055
7056
7057
7058
7059
7060
7061
7062
7063
7064
7065
7066
7067
7068
7069
7070
7071
7072
7073
7074
7075
7076
7077
7078
7079
7080
7081
7082
7083
7084
7085
7086
7087
7088
7089
7090
7091
7092
7093
7094
7095
7096
7097
7098
7099
7100
7101
7102
7103
7104
7105
7106
7107
7108
7109
7110
7111
7112
7113
7114
7115
7116
7117
7118
7119
7120
7121
7122
7123
7124
7125
7126
7127
7128
7129
7130
7131
7132
7133
7134
7135
7136
7137
7138
7139
7140
7141
7142
7143
7144
7145
7146
7147
7148
7149
7150
7151
7152
7153
7154
7155
7156
7157
7158
7159
7160
7161
7162
7163
7164
7165
7166
7167
7168
7169
7170
7171
7172
7173
7174
7175
7176
7177
7178
7179
7180
7181
7182
7183
7184
7185
7186
7187
7188
7189
7190
7191
7192
7193
7194
7195
7196
7197
7198
7199
7200
7201
7202
7203
7204
7205
7206
7207
7208
7209
7210
7211
7212
7213
7214
7215
7216
7217
7218
7219
7220
7221
7222
7223
7224
7225
7226
7227
7228
7229
7230
7231
7232
7233
7234
7235
7236
7237
7238
7239
7240
7241
7242
7243
7244
7245
7246
7247
7248
7249
7250
7251
7252
7253
7254
7255
7256
7257
7258
7259
7260
7261
7262
7263
7264
7265
7266
7267
7268
7269
7270
7271
7272
7273
7274
7275
7276
7277
7278
7279
7280
7281
7282
7283
7284
7285
7286
7287
7288
7289
7290
7291
7292
7293
7294
7295
7296
7297
7298
7299
7300
7301
7302
7303
7304
7305
7306
7307
7308
7309
7310
7311
7312
7313
7314
7315
7316
7317
7318
7319
7320
7321
7322
7323
7324
7325
7326
7327
7328
7329
7330
7331
7332
7333
7334
7335
7336
7337
7338
7339
7340
7341
7342
7343
7344
7345
7346
7347
7348
7349
7350
7351
7352
7353
7354
7355
7356
7357
7358
7359
7360
7361
7362
7363
7364
7365
7366
7367
7368
7369
7370
7371
7372
7373
7374
7375
7376
7377
7378
7379
7380
7381
7382
7383
7384
7385
7386
7387
7388
7389
7390
7391
7392
7393
7394
7395
7396
7397
7398
7399
7400
7401
7402
7403
7404
7405
7406
7407
7408
7409
7410
7411
7412
7413
7414
7415
7416
7417
7418
7419
7420
7421
7422
7423
7424
7425
7426
7427
7428
7429
7430
7431
7432
7433
7434
7435
7436
7437
7438
7439
7440
7441
7442
7443
7444
7445
7446
7447
7448
7449
7450
7451
7452
7453
7454
7455
7456
7457
7458
7459
7460
7461
7462
7463
7464
7465
7466
7467
7468
7469
7470
7471
7472
7473
7474
7475
7476
7477
7478
7479
7480
7481
7482
7483
7484
7485
7486
7487
7488
7489
7490
7491
7492
7493
7494
7495
7496
7497
7498
7499
7500
7501
7502
7503
7504
7505
7506
7507
7508
7509
7510
7511
7512
7513
7514
7515
7516
7517
7518
7519
7520
7521
7522
7523
7524
7525
7526
7527
7528
7529
7530
7531
7532
7533
7534
7535
7536
7537
7538
7539
7540
7541
7542
7543
7544
7545
7546
7547
7548
7549
7550
7551
7552
7553
7554
7555
7556
7557
7558
7559
7560
7561
7562
7563
7564
7565
7566
7567
7568
7569
7570
7571
7572
7573
7574
7575
7576
7577
7578
7579
7580
7581
7582
7583
7584
7585
7586
7587
7588
7589
7590
7591
7592
7593
7594
7595
7596
7597
7598
7599
7600
7601
7602
7603
7604
7605
7606
7607
7608
7609
7610
7611
7612
7613
7614
7615
7616
7617
7618
7619
7620
7621
7622
7623
7624
7625
7626
7627
7628
7629
7630
7631
7632
7633
7634
7635
7636
7637
7638
7639
7640
7641
7642
7643
7644
7645
7646
7647
7648
7649
7650
7651
7652
7653
7654
7655
7656
7657
7658
7659
7660
7661
7662
7663
7664
7665
7666
7667
7668
7669
7670
7671
7672
7673
7674
7675
7676
7677
7678
7679
7680
7681
7682
7683
7684
7685
7686
7687
7688
7689
7690
7691
7692
7693
7694
7695
7696
7697
7698
7699
7700
7701
7702
7703
7704
7705
7706
7707
7708
7709
7710
7711
7712
7713
7714
7715
7716
7717
7718
7719
7720
7721
7722
7723
7724
7725
7726
7727
7728
7729
7730
7731
7732
7733
7734
7735
7736
7737
7738
7739
7740
7741
7742
7743
7744
7745
7746
7747
7748
7749
7750
7751
7752
7753
7754
7755
7756
7757
7758
7759
7760
7761
7762
7763
7764
7765
7766
7767
7768
7769
7770
7771
7772
7773
7774
7775
7776
7777
7778
7779
7780
7781
7782
7783
7784
7785
7786
7787
7788
7789
7790
7791
7792
7793
7794
7795
7796
7797
7798
7799
7800
7801
7802
7803
7804
7805
7806
7807
7808
7809
7810
7811
7812
7813
7814
7815
7816
7817
7818
7819
7820
7821
7822
7823
7824
7825
7826
7827
7828
7829
7830
7831
7832
7833
7834
7835
7836
7837
7838
7839
7840
7841
7842
7843
7844
7845
7846
7847
7848
7849
7850
7851
7852
7853
7854
7855
7856
7857
7858
7859
7860
7861
7862
7863
7864
7865
7866
7867
7868
7869
7870
7871
7872
7873
7874
7875
7876
7877
7878
7879
7880
7881
7882
7883
7884
7885
7886
7887
7888
7889
7890
7891
7892
7893
7894
7895
7896
7897
7898
7899
7900
7901
7902
7903
7904
7905
7906
7907
7908
7909
7910
7911
7912
7913
7914
7915
7916
7917
7918
7919
7920
7921
7922
7923
7924
7925
7926
7927
7928
7929
7930
7931
7932
7933
7934
7935
7936
7937
7938
7939
7940
7941
7942
7943
7944
7945
7946
7947
7948
7949
7950
7951
7952
7953
7954
7955
7956
7957
7958
7959
7960
7961
7962
7963
7964
7965
7966
7967
7968
7969
7970
7971
7972
7973
7974
7975
7976
7977
7978
7979
7980
7981
7982
7983
7984
7985
7986
7987
7988
7989
7990
7991
7992
7993
7994
7995
7996
7997
7998
7999
8000
8001
8002
8003
8004
8005
8006
8007
8008
8009
8010
8011
8012
8013
8014
8015
8016
8017
8018
8019
8020
8021
8022
8023
8024
8025
8026
8027
8028
8029
8030
8031
8032
8033
8034
8035
8036
8037
8038
8039
8040
8041
8042
8043
8044
8045
8046
8047
8048
8049
8050
8051
8052
8053
8054
8055
8056
8057
8058
8059
8060
8061
8062
8063
8064
8065
8066
8067
8068
8069
8070
8071
8072
8073
8074
8075
8076
8077
8078
8079
8080
8081
8082
8083
8084
8085
8086
8087
8088
8089
8090
8091
8092
8093
8094
8095
8096
8097
8098
8099
8100
8101
8102
8103
8104
8105
8106
8107
8108
8109
8110
8111
8112
8113
8114
8115
8116
8117
8118
8119
8120
8121
8122
8123
8124
8125
8126
8127
8128
8129
8130
8131
8132
8133
8134
8135
8136
8137
8138
8139
8140
8141
8142
8143
8144
8145
8146
8147
8148
8149
8150
8151
8152
8153
8154
8155
8156
8157
8158
8159
8160
8161
8162
8163
8164
8165
8166
8167
8168
8169
8170
8171
8172
8173
8174
8175
8176
8177
8178
8179
8180
8181
8182
8183
8184
8185
8186
8187
8188
8189
8190
8191
8192
8193
8194
8195
8196
8197
8198
8199
8200
8201
8202
8203
8204
8205
8206
8207
8208
8209
8210
8211
8212
8213
8214
8215
8216
8217
8218
8219
8220
8221
8222
8223
8224
8225
8226
8227
8228
8229
8230
8231
8232
8233
8234
8235
8236
8237
8238
8239
8240
8241
8242
8243
8244
8245
8246
8247
8248
8249
8250
8251
8252
8253
8254
8255
8256
8257
8258
8259
8260
8261
8262
8263
8264
8265
8266
8267
8268
8269
8270
8271
8272
8273
8274
8275
8276
8277
8278
8279
8280
8281
8282
8283
8284
8285
8286
8287
8288
8289
8290
8291
8292
8293
8294
8295
8296
8297
8298
8299
8300
8301
8302
8303
8304
8305
8306
8307
8308
8309
8310
8311
8312
8313
8314
8315
8316
8317
8318
8319
8320
8321
8322
8323
8324
8325
8326
8327
8328
8329
8330
8331
8332
8333
8334
8335
8336
8337
8338
8339
8340
8341
8342
8343
8344
8345
8346
8347
8348
8349
8350
8351
8352
8353
8354
8355
8356
8357
8358
8359
8360
8361
8362
8363
8364
8365
8366
8367
8368
8369
8370
8371
8372
8373
8374
8375
8376
8377
8378
8379
8380
8381
8382
8383
8384
8385
8386
8387
8388
8389
8390
8391
8392
8393
8394
8395
8396
8397
8398
8399
8400
8401
8402
8403
8404
8405
8406
8407
8408
8409
8410
8411
8412
8413
8414
8415
8416
8417
8418
8419
8420
8421
8422
8423
8424
8425
8426
8427
8428
8429
8430
8431
8432
8433
8434
8435
8436
8437
8438
8439
8440
8441
8442
8443
8444
8445
8446
8447
8448
8449
8450
8451
8452
8453
8454
8455
8456
8457
8458
8459
8460
8461
8462
8463
8464
8465
8466
8467
8468
8469
8470
8471
8472
8473
8474
8475
8476
8477
8478
8479
8480
8481
8482
8483
8484
8485
8486
8487
8488
8489
8490
8491
8492
8493
8494
8495
8496
8497
8498
8499
8500
8501
8502
8503
8504
8505
8506
8507
8508
8509
8510
8511
8512
8513
8514
8515
8516
8517
8518
8519
8520
8521
8522
8523
8524
8525
8526
8527
8528
8529
8530
8531
8532
8533
8534
8535
8536
8537
8538
8539
8540
8541
8542
8543
8544
8545
8546
8547
8548
8549
8550
8551
8552
8553
8554
8555
8556
8557
8558
8559
8560
8561
8562
8563
8564
8565
8566
8567
8568
8569
8570
8571
8572
8573
8574
8575
8576
8577
8578
8579
8580
8581
8582
8583
8584
8585
8586
8587
8588
8589
8590
8591
8592
8593
8594
8595
8596
8597
8598
8599
8600
8601
8602
8603
8604
8605
8606
8607
8608
8609
8610
8611
8612
8613
8614
8615
8616
8617
8618
8619
8620
8621
8622
8623
8624
8625
8626
8627
8628
8629
8630
8631
8632
8633
8634
8635
8636
8637
8638
8639
8640
8641
8642
8643
8644
8645
8646
8647
8648
8649
8650
8651
8652
8653
8654
8655
8656
8657
8658
8659
8660
8661
8662
8663
8664
8665
8666
8667
8668
8669
8670
8671
8672
8673
8674
8675
8676
8677
8678
8679
8680
8681
8682
8683
8684
8685
8686
8687
8688
8689
8690
8691
8692
8693
8694
8695
8696
8697
8698
8699
8700
8701
8702
8703
8704
8705
8706
8707
8708
8709
8710
8711
8712
8713
8714
8715
8716
8717
8718
8719
8720
8721
8722
8723
8724
8725
8726
8727
8728
8729
8730
8731
8732
8733
8734
8735
8736
8737
8738
8739
8740
8741
8742
8743
8744
8745
8746
8747
8748
8749
8750
8751
8752
8753
8754
8755
8756
8757
8758
8759
8760
8761
8762
8763
8764
8765
8766
8767
8768
8769
8770
8771
8772
8773
8774
8775
8776
8777
8778
8779
8780
8781
8782
8783
8784
8785
8786
8787
8788
8789
8790
8791
8792
8793
8794
8795
8796
8797
8798
8799
8800
8801
8802
8803
8804
8805
8806
8807
8808
8809
8810
8811
8812
8813
8814
8815
8816
8817
8818
8819
8820
8821
8822
8823
8824
8825
8826
8827
8828
8829
8830
8831
8832
8833
8834
8835
8836
8837
8838
8839
8840
8841
8842
8843
8844
8845
8846
8847
8848
8849
8850
8851
8852
8853
8854
8855
8856
8857
8858
8859
8860
8861
8862
8863
8864
8865
8866
8867
8868
8869
8870
8871
8872
8873
8874
8875
8876
8877
8878
8879
8880
8881
8882
8883
8884
8885
8886
8887
8888
8889
8890
8891
8892
8893
8894
8895
8896
8897
8898
8899
8900
8901
8902
8903
8904
8905
8906
8907
8908
8909
8910
8911
8912
8913
8914
8915
8916
8917
8918
8919
8920
8921
8922
8923
8924
8925
8926
8927
8928
8929
8930
8931
8932
8933
8934
8935
8936
8937
8938
8939
8940
8941
8942
8943
8944
8945
8946
8947
8948
8949
8950
8951
8952
8953
8954
8955
8956
8957
8958
8959
8960
8961
8962
8963
8964
8965
8966
8967
8968
8969
8970
8971
8972
8973
8974
8975
8976
8977
8978
8979
8980
8981
8982
8983
8984
8985
8986
8987
8988
8989
8990
8991
8992
8993
8994
8995
8996
8997
8998
8999
9000
9001
9002
9003
9004
9005
9006
9007
9008
9009
9010
9011
9012
9013
9014
9015
9016
9017
9018
9019
9020
9021
9022
9023
9024
9025
9026
9027
9028
9029
9030
9031
9032
9033
9034
9035
9036
9037
9038
9039
9040
9041
9042
9043
9044
9045
9046
9047
9048
9049
9050
9051
9052
9053
9054
9055
9056
9057
9058
9059
9060
9061
9062
9063
9064
9065
9066
9067
9068
9069
9070
9071
9072
9073
9074
9075
9076
9077
9078
9079
9080
9081
9082
9083
9084
9085
9086
9087
9088
9089
9090
9091
9092
9093
9094
9095
9096
9097
9098
9099
9100
9101
9102
9103
9104
9105
9106
9107
9108
9109
9110
9111
9112
9113
9114
9115
9116
9117
9118
9119
9120
9121
9122
9123
9124
9125
9126
9127
9128
9129
9130
9131
9132
9133
9134
9135
9136
9137
9138
9139
9140
9141
9142
9143
9144
9145
9146
9147
9148
9149
9150
9151
9152
9153
9154
9155
9156
9157
9158
9159
9160
9161
9162
9163
9164
9165
9166
9167
9168
9169
9170
9171
9172
9173
9174
9175
9176
9177
9178
9179
9180
9181
9182
9183
9184
9185
9186
9187
9188
9189
9190
9191
9192
9193
9194
9195
9196
9197
9198
9199
9200
9201
9202
9203
9204
9205
9206
9207
9208
9209
9210
9211
9212
9213
9214
9215
9216
9217
9218
9219
9220
9221
9222
9223
9224
9225
9226
9227
9228
9229
9230
9231
9232
9233
9234
9235
9236
9237
9238
9239
9240
9241
9242
9243
9244
9245
9246
9247
9248
9249
9250
9251
9252
9253
9254
9255
9256
9257
9258
9259
9260
9261
9262
9263
9264
9265
9266
9267
9268
9269
9270
9271
9272
9273
9274
9275
9276
9277
9278
9279
9280
9281
9282
9283
9284
9285
9286
9287
9288
9289
9290
9291
9292
9293
9294
9295
9296
9297
9298
9299
9300
9301
9302
9303
9304
9305
9306
9307
9308
9309
9310
9311
9312
9313
9314
9315
9316
9317
9318
9319
9320
9321
9322
9323
9324
9325
9326
9327
9328
9329
9330
9331
9332
9333
9334
9335
9336
9337
9338
9339
9340
9341
9342
9343
9344
9345
9346
9347
9348
9349
9350
9351
9352
9353
9354
9355
9356
9357
9358
9359
9360
9361
9362
9363
9364
9365
9366
9367
9368
9369
9370
9371
9372
9373
9374
9375
9376
9377
9378
9379
9380
9381
9382
9383
9384
9385
9386
9387
9388
9389
9390
9391
9392
9393
9394
9395
9396
9397
9398
9399
9400
9401
9402
9403
9404
9405
9406
9407
9408
9409
9410
9411
9412
9413
9414
9415
9416
9417
9418
9419
9420
9421
9422
9423
9424
9425
9426
9427
9428
9429
9430
9431
9432
9433
9434
9435
9436
9437
9438
9439
9440
9441
9442
9443
9444
9445
9446
9447
9448
9449
9450
9451
9452
9453
9454
9455
9456
9457
9458
9459
9460
9461
9462
9463
9464
9465
9466
9467
9468
9469
9470
9471
9472
9473
9474
9475
9476
9477
9478
9479
9480
9481
9482
9483
9484
9485
9486
9487
9488
9489
9490
9491
9492
9493
9494
9495
9496
9497
9498
9499
9500
9501
9502
9503
9504
9505
9506
9507
9508
9509
9510
9511
9512
9513
9514
9515
9516
9517
9518
9519
9520
9521
9522
9523
9524
9525
9526
9527
9528
9529
9530
9531
9532
9533
9534
9535
9536
9537
9538
9539
9540
9541
9542
9543
9544
9545
9546
9547
9548
9549
9550
9551
9552
9553
9554
9555
9556
9557
9558
9559
9560
9561
9562
9563
9564
9565
9566
9567
9568
9569
9570
9571
9572
9573
9574
9575
9576
9577
9578
9579
9580
9581
9582
9583
9584
9585
9586
9587
9588
9589
9590
9591
9592
9593
9594
9595
9596
9597
9598
9599
9600
9601
9602
9603
9604
9605
9606
9607
9608
9609
9610
9611
9612
9613
9614
9615
9616
9617
9618
9619
9620
9621
9622
9623
9624
9625
9626
9627
9628
9629
9630
9631
9632
9633
9634
9635
9636
9637
9638
9639
9640
9641
9642
9643
9644
9645
9646
9647
9648
9649
9650
9651
9652
9653
9654
9655
9656
9657
9658
9659
9660
9661
9662
9663
9664
9665
9666
9667
9668
9669
9670
9671
9672
9673
9674
9675
9676
9677
9678
9679
9680
9681
9682
9683
9684
9685
9686
9687
9688
9689
9690
9691
9692
9693
9694
9695
9696
9697
9698
9699
9700
9701
9702
9703
9704
9705
9706
9707
9708
9709
9710
9711
9712
9713
9714
9715
9716
9717
9718
9719
9720
9721
9722
9723
9724
9725
9726
9727
9728
9729
9730
9731
9732
9733
9734
9735
9736
9737
9738
9739
9740
9741
9742
9743
9744
9745
9746
9747
9748
9749
9750
9751
9752
9753
9754
9755
9756
9757
9758
9759
9760
9761
9762
9763
9764
9765
9766
9767
9768
9769
9770
9771
9772
9773
9774
9775
9776
9777
9778
9779
9780
9781
9782
9783
9784
9785
9786
9787
9788
9789
9790
9791
9792
9793
9794
9795
9796
9797
9798
9799
9800
9801
9802
9803
9804
9805
9806
9807
9808
9809
9810
9811
9812
9813
9814
9815
9816
9817
9818
9819
9820
9821
9822
9823
9824
9825
9826
9827
9828
9829
9830
9831
9832
9833
9834
9835
9836
9837
9838
9839
9840
9841
9842
9843
9844
9845
9846
9847
9848
9849
9850
9851
9852
9853
9854
9855
9856
9857
9858
9859
9860
9861
9862
9863
9864
9865
9866
9867
9868
9869
9870
9871
9872
9873
9874
9875
9876
9877
9878
9879
9880
9881
9882
9883
9884
9885
9886
9887
9888
9889
9890
9891
9892
9893
9894
9895
9896
9897
9898
9899
9900
9901
9902
9903
9904
9905
9906
9907
9908
9909
9910
9911
9912
9913
9914
9915
9916
9917
9918
9919
9920
9921
9922
9923
9924
9925
9926
9927
9928
9929
9930
9931
9932
9933
9934
9935
9936
9937
9938
9939
9940
9941
9942
9943
9944
9945
9946
9947
9948
9949
9950
9951
9952
9953
9954
9955
9956
9957
9958
9959
9960
9961
9962
9963
9964
9965
9966
9967
9968
9969
9970
9971
9972
9973
9974
9975
9976
9977
9978
9979
9980
9981
9982
9983
9984
9985
9986
9987
9988
9989
9990
9991
9992
9993
9994
9995
9996
9997
9998
9999
10000
10001
10002
10003
10004
10005
10006
10007
10008
10009
10010
10011
10012
10013
10014
10015
10016
10017
10018
10019
10020
10021
10022
10023
10024
10025
10026
10027
10028
10029
10030
10031
10032
10033
10034
10035
10036
10037
10038
10039
10040
10041
10042
10043
10044
10045
10046
10047
10048
10049
10050
10051
10052
10053
10054
10055
10056
10057
10058
10059
10060
10061
10062
10063
10064
10065
10066
10067
10068
10069
10070
10071
10072
10073
10074
10075
10076
10077
10078
10079
10080
10081
10082
10083
10084
10085
10086
10087
10088
10089
10090
10091
10092
10093
10094
10095
10096
10097
10098
10099
10100
10101
10102
10103
10104
10105
10106
10107
10108
10109
10110
10111
10112
10113
10114
10115
10116
10117
10118
10119
10120
10121
10122
10123
10124
10125
10126
10127
10128
10129
10130
10131
10132
10133
10134
10135
10136
10137
10138
10139
10140
10141
10142
10143
10144
10145
10146
10147
10148
10149
10150
10151
10152
10153
10154
10155
10156
10157
10158
10159
10160
10161
10162
10163
10164
10165
10166
10167
10168
10169
10170
10171
10172
10173
10174
10175
10176
10177
10178
10179
10180
10181
10182
10183
10184
10185
10186
10187
10188
10189
10190
10191
10192
10193
10194
10195
10196
10197
10198
10199
10200
10201
10202
10203
10204
10205
10206
10207
10208
10209
10210
10211
10212
10213
10214
10215
10216
10217
10218
10219
10220
10221
10222
10223
10224
10225
10226
10227
10228
10229
10230
10231
10232
10233
10234
10235
10236
10237
10238
10239
10240
10241
10242
10243
10244
10245
10246
10247
10248
10249
10250
10251
10252
10253
10254
10255
10256
10257
10258
10259
10260
10261
10262
10263
10264
10265
10266
10267
10268
10269
10270
10271
10272
10273
10274
10275
10276
10277
10278
10279
10280
10281
10282
10283
10284
10285
10286
10287
10288
10289
10290
10291
10292
10293
10294
10295
10296
10297
10298
10299
10300
10301
10302
10303
10304
10305
10306
10307
10308
10309
10310
10311
10312
10313
10314
10315
10316
10317
10318
10319
10320
10321
10322
10323
10324
10325
10326
10327
10328
10329
10330
10331
10332
10333
10334
10335
10336
10337
10338
10339
10340
10341
10342
10343
10344
10345
10346
10347
10348
10349
10350
10351
10352
10353
10354
10355
10356
10357
10358
10359
10360
10361
10362
10363
10364
10365
10366
10367
10368
10369
10370
10371
10372
10373
10374
10375
10376
10377
10378
10379
10380
10381
10382
10383
10384
10385
10386
10387
10388
10389
10390
10391
10392
10393
10394
ARDUINO 
PROJECTS 
BOOK

THE ARDUINO PROJECTS BOOK

EDITORS
Projects and text by Scott Fitzgerald and Michael Shiloh 
Additional text review by Tom Igoe

DESIGN AND ART DIRECTION
TODO
Giorgio Olivero, Mario Ciardulli, Vanessa Poli, Michelle Nebiolo
todo.to.it

DIGITAL FABRICATION AND PROJECT MANAGEMENT
Officine Arduino Torino
Katia De Coi, Enrico Bassi

ADVISORS AND SUPPORTERS
Massimo Banzi, Gianluca Martino, Smart Projects

PROJECT TESTERS AND PROOFREADERS
Michael Shiloh, Michelle Nebiolo, Katia De Coi, Alessandro Buat, 
Federico Vanzati, David Mellis

THANKS
Big thanks to the entire Arduino user community for their contin-
ued contributions, support, and feedback.
Special thanks to the Fritzing team: some of the electronic com-
ponents illustrations used in the book are taken or modified from 
the open-source Fritzing project (www.fritzing.org).
Heartfelt thanks to Paul Badger for the CapacitiveSensor library 
used in Project 13.

The text of the Arduino Projects Book is licensed under a Creative 
Commons  Attribution-NonCommercial-ShareAlike  3.0  License  2012  by 
Arduino LLC. This means that you can copy, reuse, adapt and build 
upon the text of this book non-commercially while attributing the 
original work (but not in any way that suggests that we endorse 
you or your use of the work) and only if the results are transmitted 
under the same Creative Commons license.
Full license terms: creativecommons.org/licenses/by-nc-sa/3.0/

© 2012 Arduino LLC. The Arduino name and logo are trademarks of 
Arduino, registered in the US and in the rest of the world. Other 
product and company names mentioned herein are trademarks of their 
respective companies.

The information in this book is distributed on an “As Is” basis 
without  any  further  warranties.  While  every  precaution  has  been 
taken in the design of this book, neither the authors nor Arduino 
LLC shall have any liability to any person or entity with respect 
to any loss or damage caused or declared to be caused directly or 
indirectly by the instructions contained in this book or by the 
software and hardware described in it.

This book cannot be sold separately from The Arduino Starter Kit.

Designed, printed and bound in Torino, Italy
September 2012

INDEX

4

20

32

42

52

62

70

78

86

94

102

114

124

136

144

156

162

00     INTRODUCTION

01     Get to Know Your Tools

02     Spaceship Interface

03     Love-o-Meter

04     Color Mixing Lamp

05     Mood Cue

06     Light Theremin

07     Keyboard Instrument

08     Digital Hourglass

09     Motorized Pinwheel

10     Zoetrope

11     Crystal Ball

12     Knock Lock

13     Touchy-feely Lamp

14     Tweak the Arduino Logo

15     Hacking Buttons

A/Z   GLOSSARY

00

BECOME EXTRAORDINARY

Everyone,  every  day,  uses  technology.  Most  of  us  leave  the 

programming  to  engineers  because  we  think  coding  and 

electronics  are  complicated  and  difficult;  actually,  they  can  be 

fun and exciting activities. Thanks to Arduino, designers, artists, 

hobbyists and students of all ages are learning to create things 

that light up, move, and respond to people, animals, plants, and 

the rest of the world. 

Over the years Arduino has been used as the “brain” in thousands 

of  projects,  one  more  creative  than  the  last.  A  worldwide 

community  of  makers  has  gathered  around  this  open-source 

platform,  moving  from  personal  computing  to  personal 

fabrication,  and  contributing  to  a  new  world  of  participation, 

cooperation and sharing.

Arduino is open and simple. It’s founded on lessons we’ve learned 

teaching our own classes: if you start with the assumption that 
learning  to  make  digital  technologies  is  simple  and  accessible, 

you  can  make  it  so.  Suddenly  electronics  and  code  become 

creative  tools  that  anyone  can  use  –  like  brushes  and  paint. 

This book walks you through the basics in a hands-on way, with 

creative  projects  you  build  by  learning.  Once  you’ve  mastered 

the basics, you’ll have a palette of software and circuits that you 

can use to create something beautiful, and make someone smile 

with what you invent.

WELCOME TO 
ARDUINO!

ARDUINO MAKES IT AS EASY AS POSSIBLE 
TO PROGRAM TINY COMPUTERS CALLED 
MICROCONTROLLERS, WHICH ARE WHAT MAKE 
OBJECTS INTERACTIVE

You are surrounded by dozens of them every day: they are embedded in timers, 

thermostats, toys, remote controls, microwave ovens, even some toothbrushes. 

They just do one specific task, and if you hardly notice them – which is often the 

case – it’s because they are doing it well. They have been programmed to sense 

and control activity using sensors and actuators.

Sensors listen to the physical world. They convert energy that you give off when 
you  press  buttons,  or  wave  your  arms,  or  shout,  into  electrical  signals.  Buttons 

and knobs are sensors that you touch with your fingers, but there are many other 

kinds of sensors.
Actuators take action in the physical world. They convert electrical energy back 
into physical energy, like light and heat and movement.
Microcontrollers listen to sensors and talk to actuators. They decide what to 
do based on a program that you write.

Microcontrollers and the electronics you attach to them are just the skeleton of 
your projects, though. You’ll need to bring skills you probably already have to put 

some flesh on the bones.

For example, in one of the projects we suggest, you’ll make an arrow and attach it 

to a motor, and put them both in a box with a knob, so you can make a meter to 

tell people whether you’re busy or not. In another, you’ll put some lights and a tilt 

switch on a cardboard frame to make an hourglass.

Arduino  can  make  your  projects  responsive,  but  only  you  can  make  them 
beautiful.  We’ll  provide  some  suggestions  along  the  way  as  to  how  you  might 
do that.

Arduino was designed to help you get things done. To make that happen, we kept 

the background material on programming and electronics to a minimum. If you 

decide you want to know more about these aspects, there are lots of good guides 

available. We’ll provide a couple of references, and you can find more online at:  

arduino.cc/starterkit 

6

Introduction
Welcome to Arduino!

+

PARTS IN
YOUR KIT

+

-

+

-

+

-

+

-

Breadboard - A board on which you can build 
electronic  circuits.  It’s  like  a  patch  panel,  with 

rows of holes that allow you to connect wires 

and  components  together.  Versions  that  re-

quire soldering are available, as well as the sol-

der-less type used here.

Capacitors  -  These  components  store  and  re-
lease  electrical  energy  in  a  circuit.  When  the 

Arduino  Uno  -  The  microcontroller  develop-
ment  board  that  will  be  at  the  heart  of  your 
projects.  It’s  a  simple  computer,  but  one  that 

circuit’s voltage is higher than what is stored in 

the capacitor, it allows current to flow in, giv-
ing  the  capacitor  a  charge.  When  the  circuit’s 

has no way for you to interact with it yet. You 

voltage is lower, the stored charge is released. 

will  be  building  the  circuits  and  interfaces  for 

Often placed across power and ground close to 

interaction, and telling the microcontroller how 

a sensor or motor to help smooth fluctuations 

to interface with other components.

in voltage.

Battery Snap - Used to connect a 9V battery to 
power  leads  that  can  be  easily  plugged  into  a 

breadboard or your Arduino.

DC motor - Converts electrical energy into me-
chanical  energy  when  electricity  is  applied  to 

its leads. Coils of wire inside the motor become 

magnetized when current flows through them. 

7

These  magnetic  fields  attract  and  repel  mag-

nets, causing the shaft to spin. If the direction 

of the electricity is reversed, the motor will spin 

in the opposite direction.

 -

+

Diode - Ensures electricity only flows in one di-
rection. Useful when you have a motor or other 

Jumper  wires  -  Use  these  to  connect  compo-
nents to each other on the breadboard, and to 

high  current/voltage  load  in  your  circuit.  Di-

the Arduino.

odes are polarized, meaning that the direction 

that  they’re  placed in a circuit matters. Placed 

one  way,  they  allow  current  to  pass  through. 

Placed the other way, they block it. The anode 

side  generally  connects  to  the  point  of  higher 

energy  in  your  circuit.  The  cathode  typically 

connects  to  the  point  of  lower  energy,  or  to 

ground.  The  cathode  is  usually  marked  with  a 

band on one side of the component’s body.

- 

+ 

Light Emitting Diodes (LEDs) - A type of diode 
that illuminates when electricity passes through 

it.  Like  all  diodes,  electricity  only  flows  in  one 

direction  through  these  components.  You’re 

probably familiar with these as indicators on a 

variety of electronic devices. The anode, which 

typically connects to power, is usually the long-
er leg, and the cathode is the shorter leg.

Gels (red, green, blue) - These filter out differ-
ent  wavelengths  of  light.  When  used  in  con-

junction  with  photoresistors,  they  cause  the 

sensor to only react to the amount of light in 

the filtered color.

H-bridge - A circuit that allows you to control 
the  polarity  of  the  voltage  applied  to  a  load, 

Liquid Crystal Display (LCD) - A type of alpha-
numeric or graphic display based on liquid crys-

usually a motor. The H-bridge in the kit is an in-

tals. LCDs are available in a many sizes, shapes, 

tegrated circuit, but it could also be construct-

and styles. Yours has 2 rows with 16 characters 

ed with a number of discrete components.

each. 

 
8

Introduction
Welcome to Arduino!

Male  header  pins  -  These  pins  fit  into  female 
sockets, like those on a breadboard. They help 

make connecting things much easier.

Optocoupler - This allows you to connect two 
circuits  that  do  not  share  a  common  power 

supply.  Internally  there  is  a  small  LED  that, 

when  illuminated,  causes  a  photoreceptor  in-

side to close an internal switch. When you ap-

ply voltage to the + pin, the LED lights and the 

internal switch closes. The two outputs replace 

a switch in the second circuit.

Piezo  -  An  electrical  component  that  can  be 
used to detect vibrations and create noises.

Potentiometer  -  A  variable  resistor  with  three 
pins. Two of the pins are connected to the ends 

of  a  fixed  resistor.  The  middle  pin,  or  wiper, 

moves  across  the  resistor,  dividing  it  into  two 

halves.  When  the  external  sides  of  the  poten-

tiometer are connected to voltage and ground, 

the middle leg will give the difference in voltage 

as you turn the knob. Often referred to as a pot. 

Pushbuttons - Momentary switches that close 
a  circuit  when  pressed.  They  snap  into  bread-

boards easily. These are good for detecting on/

off signals.

Photoresistor - (also called a photocell, or light-
dependent  resistor).  A  variable  resistor  that 

changes its resistance based on the amount of 

light that falls on its face.

Resistors - Resist the flow of electrical energy 
in  a  circuit,  changing  the  voltage  and  current 

as  a  result.  Resistor  values  are  measured  in 

ohms (represented by the Greek omega char-

acter:  Ω).  The  colored  stripes  on  the  sides  of 

resistors indicate their value (see resistor color 

code table).

9

ling high current/high voltage components like 

motors.  One  pin  connects  to  ground,  another 

to  the  component  being  controlled,  and  the 

third connects to the Arduino. When the com-

ponent receives voltage on the pin connected 

to an Arduino, it closes the circuit between the 

ground and the other component.

Servo  motor  -  A  type  of  geared  motor  that 
can only rotate 180 degrees. It is controlled by 

sending  electrical  pulses  from  your  Arduino. 

These  pulses  tell  the  motor  what  position  it 

should move to.

Temperature sensor - Changes its voltage out-
put depending on the temperature of the com-

USB  Cable  -  This  allows  you  to  connect  your 
Arduino  Uno  to  your  personal  computer  for 

ponent. The outside legs connect to power and 

programming. It also provides power to the Ar-

ground. The voltage on the center pin changes 

duino for most of the projects in the kit.

as it gets warmer or cooler.

Tilt sensor - A type of switch that will open or 
close  depending  on  its  orientation.  Typically 

they are hollow cylinders with a metal ball in-

side  that  will  make  a  connection  across  two 

leads when tilted in the proper direction.

Transistor - A three legged device that can op-
erate as an electronic switch. Useful for control-

UNCONNECTED WIRES

TRANSISTOR

PUSHBUTTON

TILT SWITCH

MOSFET

MOTOR

RESISTOR

PHOTO RESISTOR

POTENTIOMETER

LED

DIODE

PIEZO

POLARIZED CAPACITOR

CAPACITOR

BATTERY

In  this  book  we  will  show  you  circuits  both  with  realistic 

illustrations and with schematic diagrams. 

Illustrations  will  give  you  an 

idea  of  what  the  breadboard 

GROUND

might  look  like  in  one  possible  implementation  of  the  project. 

Schematics, 

instead,  use  symbols  to  capture  the  essence  of 

circuits:  they  present  the  components  and  the  ways  they  are 

connected  in  a  clear,  succinct,  and  unambiguous  form,  but  not 

their  physical  organization.  Schematics  and  schematic  symbols 

are how we communicate about circuits. As you explore the world 
of  electronics  you  will  discover  that  some  books  and  websites 

only provide schematic diagrams, so learning to read circuits this 

way is a valuable skill.

Here are the symbols we will be using throughout the book.

CONNECTED WIRES

TABLE OF SYMBOLS

11

THE BOARD

Power connector
This is how you power your 

Arduino when it's not plugged 

into a USB port for power. Can 

accept voltages between 7-12V.

USB port
Used for powering your 

Arduino Uno, uploading your 

sketches to your Arduino, and 

for communicating with your 

Arduino sketch (via Serial.

println() etc.)

GND and 5V pins
Use these pins to provide +5V 

power and ground to your 

circuits.

Analog in
Use these pins with 

analogRead().

Reset Button
Resets the ATmega 

microcontroller.

TX and RX LEDs
These LEDs indicate communi-

cation between your Arduino 

and your computer. Expect 

them to flicker rapidly during 

sketch upload as well as during 

serial communication. Useful 

for debugging.

Digital pins
Use these pins with digital-

Read(), digitalWrite(), and 

analogWrite(). analogWrite() 

works only on the pins with the 

PWM symbol.

Pin 13 LED
The only actuator built-it to 

your Arduino Uno. Besides 

being a handy target for your 

first blink sketch, this LED is 

very useful for debugging.

ATmega microcontroller
The heart of your Arduino Uno.

Power LED
Indicates that your Arudino 

is receiving power. Useful for 

debugging.

12

Introduction
Welcome to Arduino!

Your Starter Kit includes a pre-

cut, easy-to-assemble wooden 

base that will make working on

all  your  projects  –  whether 

they are from this book or not 

– even easier.

To build it, take the wood sheet 

out  of  the  box  and  follow  the 

instructions on the right.

Be  careful  to  use  only  the 

parts that are shown, but don’t 

misplace  any  of  the  other 

pieces:  you’ll  need  them  for 

some of the projects later.

Let’s start!

❶

Take the wood sheet and carefully separate the pieces.

❹

Secure your Arduino Uno to the base using 3 screws. Be 

careful not to overtightens.

13

❷

❸

Go on until you’ve separated all the parts.

Place the pieces marked with an “A” into the holes in 

the corners, in order to create the feet of the base.

❺

❻

Carefully peel the backing from the breadboard.

Stick the breadboard on the wooden sheet, next to the 

Arduino UNO.

14

Introduction
Welcome to Arduino!

-

THINGS YOU
NEED TO
SUPPLY

9V battery

Small light source like a

flashlight

Conductive material like

aluminum foil or copper mesh

Colored paper

Scissors

An old CD or DVD

Tape and glue

A box that you can make

holes into

Basic tools like a screwdriver

9V battery powered component
Any battery powered electronic device with at 

least one switch or pushbutton that you’re will-

ing to hack into will do the job. 

Soldering iron and solder
(necessary only in Project  15)

SETTING 
UP

WELCOME TO ARDUINO! BEFORE YOU START CONTROLLING 
THE WORLD AROUND YOU, YOU’LL NEED TO DOWNLOAD THE 
IDE TO PROGRAM YOUR BOARD

The Arduino IDE allows you to write programs and upload them 

to your Arduino.

Download the latest version of the IDE from:

arduino.cc/download

Have your Arduino board and USB cable near your computer. 

Don’t plug them in just yet.

Follow the appropriate procedures in the next pages for Windows, 

Mac OS X or Linux. 

The online version of this guide is available at:

arduino.cc/guide

16

Introduction
Setting Up

WINDOWS
INSTALLATION

Online version

arduino.cc/windows

INSTRUCTION FOR:

WINDOWS 7, VISTA, 

AND XP

❶

❷

❸

When the download of the IDE finishes, unzip the downloaded 

file. Make sure to preserve the folder structure. Double-click the 

folder  to  open  it.  There  should  be  a  few  files  and  sub-folders 

inside.

Connect the Arduino to your computer with the USB cable. Your 

Arduino will automatically draw power from either the USB con-

nection to the computer or an external power supply. 

The green power light (labeled PWR) should turn on.

Windows should initiate its driver installation process when the 

board is plugged in. Your computer won’t be able to find the driv-

ers by itself, so you’ll need to tell it where they are located.

 — Click on the Start Menu and open the Control Panel.
 — Navigate to “System and Security”. Open the Device Manager.
 — In Windows XP, look for the listing named "Ports (COM & LPT)" 
and right click on the "USB device" port; in Vista and Windows 7, 

right click on "Unknown device" under "Other devices".
 — Choose "Update Driver Software".
 — On  Windows  XP  and  Windows  7,  you  will  be  asked  whether 
to install automatically or "with a path". Chose the second option, 

"with a path". On Windows Vista proceed directly to the next step.
 — Select the “Browse my computer for Driver software” option.
 — Navigate  to  the  folder  you  unzipped  in  the  earlier  step. 
Locate and select the “Drivers” folder in the main Arduino folder 

(not the “FTDI USB Drivers” sub-directory). Press “OK” and “Next” 

to proceed.
 — If you are prompted with a warning dialog about not passing 
Windows Logo testing, click “Continue Anyway”.
 — Windows now will take over the driver installation.

In the Device Manager, you should now see a port listing similar 

to “Arduino UNO (COM4)”.

Congratulations!  You've  installed  the  Arduino  IDE  on  your 

computer.

 
 
 
 
 
 
 
 
 
 
 
 
17

MAC OS X
INSTALLATION

Online version

arduino.cc/mac

INSTRUCTION FOR:

OS X 10.5 AND 

LATER

❶

❷

❸

❹

❺

When the download of the IDE finished, double-click the .zip fle. 

This will expand the Arduino application.

Copy  the  Arduino  application  into  the  Applications  folder,  or 

wherever else you wish to install the software.

Connect  the  board  to  the  computer  with  the  USB  cable.  The 

green power LED (labeled PWR) should turn on.

You do not need to install any drivers to work with the board. 

Depending  on  the  version  of  OS  X  that  you  are  running,  you 

might get a dialog box asking if you wish to open the “Network 

Preferences”. Click the “Network Preferences...” button, and then 

click “Apply”. 

The Uno will show up as “Not Configured”, but it is still working. 

You can quit the System Preferences.

Congratulations! You have Arduino all set up and you're ready to 

start making projects.

LINUX
INSTALLATION

If you’re using Linux, please visit the website for instructions:

arduino.cc/linux

18

Introduction
Setting Up

COMMUNICATING 
WITH THE 
ARDUINO

Now  that  you’ve  installed  the  Arduino  IDE  and  made  sure  your 

computer can talk to the board, it’s time to make sure you can up-

load a program.

❶

❷

❸

❹

Double-click the Arduino application to open it. If the IDE loads 

in  the  wrong  language,  you  can  change  this  in  the  application 

preferences.  Look  for  “Language  Support”  on  this  page  for  de-
tails: arduino.cc/ide 

Navigate to the LED blink example sketch ('sketch' is what Ar-

duino programs are called). It's located under:

FILE > EXAMPLES > 01.BASICS > BLINK 

A window with some text in it should have opened. Leave the 

window be for now, and select your board under: 
TOOLS > BOARD menu

Choose  the  serial  port  your  Arduino  is  connected  to  from  the 
TOOLS > SERIAL PORT menu.

 — On  Windows.  This  is  likely  to  be  the  COM  with  the  highest 
number.  There  is  no  harm  in  guessing  wrong,  and  if  it  doesn’t 

work,  try  the  next  one.  To  find  out,  you  can  disconnect  your 

Arduino board and re-open the menu; the entry that disappears 

should  be  the  Arduino  board.  Reconnect  the  board  and  select 

that serial port.
 — On Mac. This should be something with /dev/tty.usbmodem 
in it. There are usually two of these; select either one.

Fig. 1

❺

To  upload  the  Blink  sketch  to  your  Arduino,  press  the  UPLOAD 
toggle in the top left corner of the window. See Fig. 1.

 
 
 
 
19

❻

❼

You should see a bar indicating the progress of the upload near the 

lower left corner of the Arduino IDE, and the lights labeled TX and 

RX on the Arduino board will be blinking. If the upload is successful, 
the IDE will display the message DONE UPLOADING.

A few seconds after the upload has completed, you should see the 
yellow LED with an L next to it start blinking. See Fig. 2.
If  this  is  the  case,  congratulations!  You’ve  successfully  pro-

grammed the Arduino to blink its onboard LED! 

Sometimes your brand new Arduino is already programmed with 

the Blink sketch, so you can’t tell if you are truly in control. If this is 
the case, change the delay time by changing the number in the 
parenthesis  to  100,  and  upload  the  Blink  sketch  again.  Now  the 

LED should blink much faster. 
Congratulations! You really are in control! Now it’s time to move 
on to Project  1. (You needn’t save any changes you have made.)

Fig. 2

ADDITIONAL
INFORMATION

If you have problems with any of the steps outlined above, please 

see the troubleshooting suggestions:

arduino.cc/trouble

While you’re getting ready to build your projects, you can look at 

the following page for additional information about the Arduino’s 

programming environment: 

arduino.cc/ide

You might also want to look at:

 — the examples for using various sensors and actuators
arduino.cc/tutorial

 — the reference for the Arduino language
arduino.cc/examples

 
 
 
 
 
01

R
O
T
S
I
S
E
R

M
H
O

0
2
2

H
C
T
I
W
S

D
E
L

INGREDIENTS

 
 
21

GET TO KNOW 
YOUR TOOLS

YOU’LL MAKE A SIMPLE CIRCUIT WITH SOME
SWITCHES, AN LED, AND A RESISTOR 

Discover: basic electrical theory, how a breadboard works, 

components in series and parallel

Time: 30 MINUTES
Level:

Electricity  is  a  type  of  energy,  much  like  heat,  gravity,  or  light.  Electrical  energy 

flows through conductors, like wire. You can convert electrical energy into other 

forms  of  energy  to  do  something  interesting,  like  turn  on  a  light  or  make  some 

noise out of a speaker. 

The components you might use to do this, like speakers or light bulbs, are electri-
cal transducers. Transducers change other types of energy into electrical energy 
and vice versa. Things that convert other forms of energy into electrical energy are 
often called sensors, and things that convert electrical energy into other forms 
of energy are sometimes called actuators. You will be building circuits to move 
electricity  through  different  components.  Circuits  are  closed  loops  of  wire  with 

a power source (like a battery) and something to do something useful with the 

energy, called a load.

In a circuit, electricity flows from a point of higher potential energy (usually re-

ferred to as power or +) to a point of lower potential energy. Ground (often repre-

sented with a - or GND) is generally the point of least potential energy in a circuit. 

In the circuits you are building, electricity only flows in one direction. This type of 

circuit is called direct current, or DC. In alternating current (AC) circuits electricity 

changes its direction 50 or 60 times a second (depending on where you live). This 

is the type of electricity that comes from a wall socket. 

There  are  a  few  terms  you  should  be  familiar  with  when  working  with  electri-
cal  circuits.  Current (measured  in  amperes,  or  amps;  with  the  A  symbol)  is  the 
amount of electrical charge flowing past a specific point in your circuit. Voltage 
(measured in volts; with the V symbol) is the difference in energy between one 
point in a circuit and another. And finally, resistance (measured in ohms; with the 
Ω symbol) is how much a component resists the flow of electrical energy. 

22

Project 01
Get to Know Your Tools

One way to imagine this is to think about a rockslide going down 

a cliff, as shown in Fig. 1. The higher the cliff, the more energy the 

rocks will have when they hit the bottom. The height of the cliff 

is like the voltage in a circuit: the higher the voltage at the energy 

source,  the  more  energy  you  have  to  use.  The  more  rocks  you 

have, the more energy is being carried down the cliff. The num-

ber of rocks is like the current in an electrical circuit. The rocks go 

through bushes on the side of the cliff, losing some energy in the 

process; the energy is used up to crush the bushes. The bushes 

are like resistors in a circuit, offering resistance to the electrical 

flow and converting it into other forms of energy.

Rockslide as a metaphor for 

electrical current flow.

Fig. 1

Current (I)

Voltage (V)

Resistance (R)

A COUPLE OF
THINGS ABOUT
CIRCUITS

5V

+5V 

GND

There needs to be a complete path from the energy source 

(power) to the point of least energy (ground) to make a circuit. 

If there’s no path for the energy to travel, the circuit won’t work.

All the electrical energy gets used up in a circuit by the com-

ponents in it. Each component converts some of the energy into 

another form of energy. In any circuit, all of the voltage is con-

verted to another form of energy (light, heat, sound, etc.).

The flow of current at a specific point in a circuit will always 

be the same coming in and going out.

Electrical  current  will  seek  the  path  of  least  resistance  to 

ground. Given two possible paths, more of the electrical current 

will go down the path with less resistance. If you have a connec-

tion that connects power and ground together with no resist-

ance,  you  will  cause  a  short  circuit,  and  the  current  will  try  to 

follow that path. In a short circuit, the power source and wires 

1
1

2

3

4  

The current at (1) = current at (2) 

convert the electrical energy into light and heat, usually as sparks 

+ current at (3) = current at (4).

or an explosion. If you’ve ever shorted a battery and seen sparks, 

Fig. 2 

you know how dangerous a short circuit can be.

23

WHAT’S A
BREADBOARD?

The breadboard is the primary place you will be building circuits. 

The one that comes in your kit is solderless, so named because 

you don’t have to solder anything together, sort of like LEGO in 

electronic form. The horizontal and vertical rows of the bread-

board, as shown in Fig. 3, carry electrictricity through thin metal 

connectors under the plastic with holes.

The 5 holes in each horizontal row are 
connected electrically through metal 
strips inside the breadboard.

The middle row breaks the 
connection between the two 
sides of the board.

The vertical strips that run the length 
of the breadboard are electrically 
connected. The strips are usually used 
for power and ground connections.

+ -

+ -

The top of a breadboard and the connections 

POWER BUS

POWER BUS

underneath.

Fig. 3 

Conductive metal strips.

PROTOTYPING AREA

The conductive plates inside a breadboard.

Fig. 4 

24

Project 01
Get to Know Your Tools

CIRCUIT
DRAWINGS

Throughout these projects, you’ll see two views of circuits: one in 

breadboard view (like in Fig. 5), that looks like the stuff in your kit. 

The other is a schematic view (like in Fig. 6), which is a more abstract 

way of showing the relationships between components in a circuit. 

Schematics don’t always show where components are placed rela-

tive to each other, but they show how they are connected.

+ -

+ -

Circuit illustration.

Fig. 5

+ -

+ -

Schematic view
Fig. 6 

25

YOUR FIRST
COMPONENTS

An  LED,  or  light-emitting  diode,  is  a  component  that  converts  electrical  energy 
into light energy. LEDs are polarized components, which means they only allow 

electricity  to  flow  through  them  in  one  direction.  The  longer  leg  on  the  LED  is 

called an anode, it will connect to power. The shorter leg is a cathode and will con-

nect to ground. When voltage is applied to the anode of the LED, and the cathode 

is connected to ground, the LED emits light.

E
D
O
H
T
A
C

- 

E
D
O
N
A

+ 

A resistor is a component that resists the flow of electrical energy (see the com-
ponents  list  for  an  explanation  on  the  colored  stripes  on  the  side).  It  converts 

some of the electrical energy into heat. If you put a resistor in series with a com-

ponent like an LED, the resistor will use up some of the electrical energy and the 

LED  will  receive  less  energy  as  a  result.  This  allows  you  to  supply  components 

with the amount of energy they need. You use a resistor in series with the LED to 

keep it from receiving too much voltage. Without the resistor, the LED would be 

brighter for a few moments, but quickly burn out.

A switch interrupts the flow of electricity, breaking the circuit when open. When a 
switch is closed, it will complete a circuit. There are many types of switches. The 

ones in your kit are called momentary switches, or pushbuttons, because they are 

only closed when pressure is applied.

SWITCH CONNECTIONS

SWITCH SCHEMATIC VIEW

These two pins of a switch are connected
to each other 

These two are not.
They form the switch

A - Toggle switch symbol

The switch

Fig. 7

B - Pushbutton symbol

26

Project 01
Get to Know Your Tools

BUILD THE
CIRCUIT

+ -

+ -

Fig. 8

+ -

+ -

Your first interactive circuit, using a 
switch, a resistor and an LED. 
Arduino is just the power source for 
this circuit; in later projects, you'll 
connect its input and output pins to 
control more complex circuits. 

Fig. 9

27

❶

❷

❸

❹

You’re  going  to  use  the  Arduino  in  this  project,  but  only  as  a 

source of power. When plugged into a USB port or a 9-volt bat-

tery, the Arduino will provide 5 volts between its 5V pin and its 

ground  pin  that  you  can  use.  5V  =  5  volts,  you’ll  see  it  written 

this way a lot.

If your Arduino is connected to a battery or computer via USB, 

unplug it before building the circuit!

Connect  a  red  wire  to  the  5V  pin  on  the  Arduino,  and  put  the 

other end in one of the long bus lines in your breadboard. Con-

nect ground on the Arduino to the adjacent bus line with a black 

wire. It’s helpful to keep your wire color consistent (red for pow-

er, black for ground) throughout your circuit.

Now  that  you  have  power  on  your  board,  place  your  switch 

across  the  center  of  the  board.  The  switch  will  sit  across  the 

center in one direction. The bend in the legs of the switch point 

to the center of the board. 

Use  a  220-ohm  resistor  to  connect  power  to  one  side  of  the 

switch. The illustrations in this book use 4 bands. Your kit may 

have a mix of 4 and 5 band resistors. Use the illustration on the 

side to check for the right one for this project. Look at page 41 for 

a detailed explanation of the color codes for resistors.

On  the  other  side  of  the  switch,  connect  the  anode  (long  leg) 

of the LED. With a wire connect the cathode (short leg) of the 

LED to ground. When you’re ready, plug the USB cable into the 

Arduino.

USE IT

Once everything is set to go, press the button.  You should see 

the LED light up. Congratulations, you just made a circuit! Once 

you’ve tired of pressing the button to turn the light on, it’s time 

to shake things up by adding a second button.

You’ll be placing components on the breadboard in series and in 

parallel. Components in series come one after another. 

Components in parallel run side by side. 

28

Project 01
Get to Know Your Tools

Series circuit 
COMPONENTS IN SERIES COME ONE AFTER ANOTHER

Once  you’ve  removed  your  power  source  add  a  switch  next 

to the one already on your breadboard. Wire them together in 

series as shown in Fig. 10. Connect the anode (long leg) up the 

LED to the second switch. Connect the LED cathode to ground. 

Power up the Arduino again: now to turn on the LED, you need 

to press both switches. Since these are in series, they both need 

to be closed for the circuit to be completed.

+ -

+ -

These two elements 
are in series

ALWAYS REMOVE 
POWER BEFORE 
CHANGING ANYTHING 
IN YOUR CIRCUIT

The two switches are in series. This means that the same electrical 

current flows through both of them, so that they both have to be 

pressed for the LED to light up.

Fig. 10

+ -

+ -

Fig. 11

Series circuit 

COMPONENTS IN SERIES COME ONE AFTER ANOTHER

29

Parallel circuit 
COMPONENTS IN PARALLEL RUN SIDE BY SIDE

Now that you’ve mastered the art of things in series, it’s time 

to  wire  up  switches  in  parallel.  Keep  the  switches  and  LED 

where they are, but remove the connection between the two 

switches. Wire both switches to the resistor. Attach the other 

end of both switches to the LED, as shown in Fig. 12. Now when 

you press either button, the circuit is completed and the light 

turns on.

+ -

+ -

These two elements 
are in parallel

These two switches are in parallel. This means that the electrical 

current is split between them. If either switch is pressed, the LED 

will light up.

Fig. 12

+ -

+ -

Fig. 13

30

Project 01
Get to Know Your Tools

UNDERSTANDING
OHM’S LAW

V

I

R

V = I * R

I = V / R

R = V / I 

V

I

R

V

I

R

V

I

R

You can use this circle to 

Current,  voltage,  and  resistance  are  all  related.  When  you 
change one of these in a circuit, it affects the others. The rela-

remember the relationships 

tionship between them is known as Ohm's Law, named for Georg 

between voltage, current, and 

resistance. Put your finger over 

any of the three, and you see 

Simon Ohm, who discovered it.
VOLTAGE (V) = CURRENT (I) * RESISTANCE (R)
When measuring amperage in the circuits you’ll be building, values 

how it relates to the other two. 

will be in the milliamp range. That’s thousandths of one amp. 

In the circuit shown in Fig. 5, you’re supplying 5 volts. The resistor offers 220 ohms 

resistance. To find the amperage used by the LED, replace the values in the equa-

tion. You should have 5=I*220. Dividing both sides of the equation by 220, you’ll 

find that I = .023. That’s 23 thousandths of an amp, or 23 milliamps (23 mA) used 

by the LED. That value is just about the maximum you can safely use with these 

LEDs, which is why you used a 220-ohm resistor.

You  can  expand  this  project  in  a  number  of  ways,  either  by  creating  your  own 

switch  (two  pieces  of  foil  with  wire  work  well),  or  creating  a  combination  of 

switches  and  LEDs  in  parallel  and  series.  What  happens  when  you  put  three  or 

four LEDs in series? What happens when they are in parallel? Why does it behave 

the way it does?

A multimeter is a tool that can verify the amount of resistance, current, and volt-
age in your circuit. While it’s not necessary to use one for these projects, it can be 

a useful part of any engineer’s toolbox. There’s a good description of how to use 
one online at arduino.cc/multimeter

You’ve  learned  about  the  electrical  properties  of  voltage, 
current,  and  resistance  while  building  a  circuit  on  a 
breadboard. With some components like LEDs, resistors and 
switches, you created the simplest interactive system: a user 
presses the button, the lights turn on. These fundamentals 
of working with electronics will be referenced and expanded 
upon in the upcoming projects.

Fig. 14 - A multimeter

02

R
O
T
S
I
S
E
R

M
H
O

0
2
2

R
O
T
S
I
S
E
R

M
H
O
L
I
K

0
1

H
C
T
I
W
S

D
E
L

INGREDIENTS

 
 
 
 
 
 
33

SPACESHIP 
INTERFACE

YOUR ARDUINO IS GOING TO STAR IN A SCIENCE 
FICTION MOVIE

Discover: digital input and output, your first program, variables

Time: 45 MINUTES
Level:

Builds on project: 1

Now that you’ve got the basics of electricity under control, it’s time to move onto 

controlling things with your Arduino. In this project, you’ll be building something 

that could have been a spaceship interface in a 1970s science fiction movie. You’ll 

make a cool control panel with a switch and lights that turn on when you press the 

switch. You can decide whether the lights mean “Engage Hyperdrive” or “Fire the 

lasers!”. A green LED will be on, until you press a button. When the Arduino gets 

a signal from the button, the green light will turn off and 2 other lights will start 

blinking.

The Arduino’s digital pins can read only two states: when there is voltage on an 

input  pin,  and  when  there’s  not.  This  kind  of  input  is  normally  called  digital  (or 

sometimes  binary,  for  two-states).  These  states  are  commonly  referred  to  as 
HIGH and LOW. HIGH is the same as saying “there’s voltage here!” and LOW means 
“there’s  no  voltage  on  this  pin!”.  When  you  turn  an  OUTPUT  pin  HIGH  using  a 
command  called  digitalWrite(),  you’re  turning  it  on.  Measure  the  voltage 
between  the  pin  and  ground,  you’ll  get  5  volts.  When  you  turn  an  OUTPUT  pin 
LOW, you’re turning it off. 
The Arduino’s digital pins can act as both inputs and outputs. In your code, you’ll 

configure them depending on what you want their function to be. When the pins 

are outputs, you can turn on components like LEDs. If you configure the pins as 

inputs, you can check if a switch is being pressed or not. Since pins 0 and 1 are used 

for communicating with the computer, it’s best to start with pin 2.

34

Project 02
Spaceship Interface

BUILD THE
CIRCUIT

+ -

+ -

Fig. 1

+ -

+ -

Fig. 2

35

❶

❷

Wire  up  your  breadboard  to  the  Arduino’s  5V  and  ground 

connections,  just  like  the  previous  project.  Place  the  two  red 

LEDs and one green LED on the breadboard. Attach the cathode 

(short leg) of each LED to ground through a 220-ohm resistor. 

Connect the anode (long leg) of the green LED to pin 3. Connect 

the red LEDs’ anodes to pins 4 and 5, respectively. 

Place the switch on the breadboard just as you did in the previous 

project. Attach one side to power, and the other side to digital 

pin 2 on the Arduino. You’ll also need to add a 10k-ohm resistor 

from  ground  to  the  switch  pin  that  connects  to  the  Arduino. 

That  pull-down  resistor  connects  the  pin  to  ground  when  the 
switch is open, so it reads LOW when there is no voltage coming 
in through the switch. 

You can cover the breadboard the template provided in the kit. Or you can deco-

rate it to make your own launch system. The lights turning on and off mean noth-

ing by themselves, but when you put them in a control panel and give them labels, 

they gain meaning. What do you want the green LED to mean? What do the flash-

ing red LEDs mean? You decide!

❶

❷

 Fold the pre-cut paper as shown.

Place the folded paper over the breadboard. The three LEDs 

and pushbutton will help keep it in place.

36

Project 02
Spaceship Interface

THE CODE

Some notes before you start

Every  Arduino  program  has  two  main  functions.  Functions  are 

parts of a computer program that run specific commands. Func-

tions  have  unique  names,  and  are  “called”  when  needed.  The 
necessary functions in an Arduino program are called setup() 
and loop(). These functions need to be declared, which means 
that you need to tell the Arduino what these functions will do. 
setup() and loop() are declared as you see on the right.
In this program, you’re going to create a variable before you get 

into the main part of the program. Variables are names you give 

to places in the Arduino’s memory so you can keep track of what 

is happening. These values can change depending on your pro-

gram’s instructions.

Variable names should be descriptive of whatever value they are 
storing. For example, a variable named switchState tells you 
what it stores: the state of a switch. On the other hand, a vari-
able named “x” doesn’t tell you much about what it stores.

To  create  a  variable,  you  need  to  declare  what  type  it  is.  The 
data type int will hold a whole number (also called an integer); 
that’s any number without a decimal point. When you declare a 

variable, you usually give it an initial value as well. The declaration 

of the variable as every statement must end with a semicolon (;).

The setup() runs once, when the Arduino is first powered on. 
This is where you configure the digital pins to be either inputs 
or  outputs  using  a  function  named  pinMode().  The  pins 
connected to LEDs will be OUTPUTs and the switch pin will be 
an INPUT. 

The  loop()  runs  continuously  after  the  setup()  has 
completed. The loop() is where you’ll check for voltage on the 
inputs, and turn outputs on and off. To check the voltage level 
on a digital input, you use the function digitalRead() that 
checks the chosen pin for voltage. To know what pin to check, 
digitalRead() expects an argument. 
Arguments  are 

information  that  you  pass  to  functions, 

telling  them  how  they  should  do  their  job.  For  example, 
digitalRead()  needs  one  argument:  what  pin  to  check.  In 
your program, digitalRead() is going to check the state of 

Let’s start coding

Configure pin functionality

Create the loop function

 
37

{ Curly brackets }
Any code you write inside the curly 
brackets will be executed when the 
function is called.

Case sensitivity 
Pay attention to the case 
sensitivity in your code. 
For example, pinMode is the name of 
a command, but pinmode will produce 
an error.

Comments
If you ever want to include natural 
language in your program, you can leave 
a comment. 
Comments are notes you leave for yourself 
that the computer ignores. To write a 
comment, add two slashes // 
The computer will ignore anything on the 
line after those slashes.

void setup(){

}

void loop(){

}

1

int switchState = 0; 

2

3

4

5

6

7

8

9

void setup(){

  pinMode(3,OUTPUT);

  pinMode(4,OUTPUT);

  pinMode(5,OUTPUT);

  pinMode(2,INPUT);

}

void loop(){

  switchState = digitalRead(2);

10

  // this is a comment

 
 
 
 
38

Project 02
Spaceship Interface

The if statement

Build up your spaceship

pin 2 and store the value in the switchState variable.
If there’s voltage on the pin when digitalRead() is called, the 
switchState variable will get the value HIGH (or 1). If there is 
no voltage on the pin, switchState will get the value LOW (or 0). 

Above,  you  used  the  word  if  to  check  the  state  of  something 
(namely,  the  switch  position).  An  if()  statement 
programming  compares  two  things,  and  determines  whether 

in 

the comparison is true or false. Then it performs actions you tell 

it to do. When comparing two things in programming, you use 
two equal signs ==. If you use only one sign, you will be setting a 
value instead of comparing it.

digitalWrite() is the command that allows you to send 5V 
or 0V to an output pin. digitalWrite() takes two arguments: 
what pin to control, and what value to set that pin, HIGH or LOW. 
If you want to turn the red LEDs on and the green LED off inside 
your if() statement, your code would look like this .

If you run your program now, 

the lights will change when you 

press the switch. That’s pretty 

neat, but you can add a little more 

complexity to the program for a 

more interesting output.

You’ve  told  the  Arduino  what  to  do  when  the  switch  is  open. 
Now define what happens when the switch is closed. The if() 
statement  has  an  optional  else  component  that  allows  for 
something to happen if the original condition is not met. In this 
case, since you checked to see if the switch was LOW, write code 
for the HIGH condition after the else statement.

To get the red LEDs to blink when the button is pressed, you’ll 
need to turn the lights off and on in the else statement you just 
wrote. To do this, change the code to look like this.

Now your program will flash the 

After setting the LEDs to a certain state, you’ll want the Arduino 

red LEDs when the switch button 

to pause for a moment before changing them back. If you don’t 

is pressed.

wait, the lights will go back and forth so fast that it will appear 

as  if  they  are  just  a  little  dim,  not  on  and  off.  This  is  because 
the Arduino goes through its loop() thousands of times each 
second, and the LED will be turned on and off quicker than we 
can perceive. The delay() function lets you stop the Arduino 
from executing anything for a period of time. delay() takes an 
argument that determines the number of milliseconds before it 

executes the next set of code. There are 1000 milliseconds in one 
second. delay(250) will pause for a quarter second.

39

It can be helpful to write out the flow of 
your program in pseudocode: a way of 
describing what you want the program 
to do in plain language, but structured 
in a way that makes it easy to write a 
real program from it. In this case you’re 
going to determine if switchState 
is HIGH (meaning the button is pressed) 
or not. If the switch is pressed, you’ll turn 
the green LED off and the red ones on. In 
pseudocode, the statement could look 
like this:

if the switchState is LOW:
  turn the green LED on 
  turn the red LEDs off

if the switchState is HIGH:
  turn the green LED off
  turn the red LEDs on

11

12

  if (switchState == LOW) {  

  // the button is not pressed

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

    digitalWrite(3, HIGH); // green LED

    digitalWrite(4, LOW);  // red LED

    digitalWrite(5, LOW);  // red LED

  } 

  else {  // the button is pressed

    digitalWrite(3, LOW); 

    digitalWrite(4, LOW);

    digitalWrite(5, HIGH);

    delay(250);  // wait for a quarter second

    // toggle the LEDs

    digitalWrite(4, HIGH); 

    digitalWrite(5, LOW);

    delay(250); // wait for a quarter second

  } 

} // go back to the beginning of the loop

 
 
40

Project 02
Spaceship Interface

USE IT

Once  your  Arduino  is  programmed,  you  should  see  the  green 

light turn on. When you press the switch, the red lights will start 

flashing, and the green light will turn off. Try changing the time of 
the two delay() functions; notice what happens to the lights 
and how the response of the system changes depending on the 
speed of the flashing. When you call a delay() in your program, 
it stops all other functionality. No sensor readings will happen until 

that time period has passed. While delays are often useful, when 

designing your own projects make sure they are not unnecessarily 

interfering with your interface. 

How would you get the red LEDs to be blinking when your program starts? 

How could you make a larger, or more complex interface for your interstellar ad-

ventures with LEDs and switches?

When you start creating an interface for your project, think about what people’s 

expectations are while using it. When they press a button, will they want immedi-

ate feedback? Should there be a delay between their action and what the Arduino 

does? Try and place yourself in the shoes of a different user while you design, and 

see if your expectations match up to the reality of your project.

In  this  project,  you  created  your  first  Arduino  program 
to  control  the  behavior  of  some  LEDs  based  on  a  switch. 
You’ve used variables, an if()...else statement, and functions 
to read the state of an input and control outputs.

41

HOW TO READ 
RESISTOR 
COLOR CODES

Resistor values are marked using colored bands, according to a code developed in the 1920s, 

when it was too difficult to write numbers on such tiny objects.

Each color corresponds to a number, like you see in the table below. Each resistor has either 

4 or 5 bands. In the 4-band type, the first two bands indicate the first two digits of the value 

while the third one indicates the number of zeroes that follow (technically it reprents the 

power of ten). The last band specifies the tolerance: in the example below, gold indicates 

that the resistor value can be 10k ohm plus or minus 5%.

4 BAND

1

0

x

103

±

5

= 10,000Ω  = 10kΩ  ±5% 

1 st DIGIT

2 nd DIGIT

3 rd DIGIT

MULTIPLIER

TOLERANCE

0

1

2

3

4

5

6

7

8

9

0

1

2

3

4

5

6

7

8

9

0

1

2

3

4

5

6

7

8

9

0

1

2

3

4

5

6

±1%

±2%

±5%  GOLD

±10% SILVER

5 BAND

1

0

0

x

102

±

5

= 10,000Ω  = 10kΩ  ±5% 

RESISTORS INCLUDED 

IN THE STARTER KIT

You’ll find either a 4 band or 

a 5 band version.

220Ω

560Ω

4.7kΩ

1kΩ

10kΩ

1MΩ

10MΩ

5 BAND

4 BAND

5 BAND

4 BAND

03

R
O
T
S
I
S
E
R

M
H
O

0
2
2

R
O
S
N
E
S

E
R
U
T
A
R
E
P
M
E
T

D
E
L

INGREDIENTS

 
 
 
 
 
43

LOVE-O-METER

TURN THE ARDUINO INTO A LOVE MACHINE. USING AN 
ANALOG INPUT, YOU’RE GOING TO REGISTER JUST HOW 
HOT YOU REALLY ARE! 

Discover: analog Input, using the serial monitor 

Time: 45 MINUTES
Level:

Builds on projects: 1, 2

While switches and buttons are great, there’s a lot more to the physical world than 

on and off. Even though the Arduino is a digital tool, it’s possible for it to get infor-

mation from analog sensors to measure things like temperature or light. To do this, 

you’ll take advantage of the Arduino’s built-in Analog-to-Digital Converter (ADC). 

Analog in pins A0-A5 can report back a value between 0-1023, which maps to a 

range from 0 volts to 5 volts.

You’ll be using a temperature sensor to measure how warm your skin is. This com-
ponent  outputs  a  changing  voltage  depending  on  the  temperature  it  senses.  It 

has  three  pins:  one  that  connects  to  ground,  another  that  connects  to  power, 

and a third that outputs a variable voltage to your Arduino. In the sketch for this 

project, you’ll read the sensor’s output and use it to turn LEDs on and off, indicat-

ing how warm you are. There are several different models of temperature sensor. 

This model, the TMP36, is convenient because it outputs a voltage that changes 

directly proportional to the temperature in degrees Celsius.

The Arduino IDE comes with a tool called the serial monitor that enables you to 
report back results from the microcontroller. Using the serial monitor, you can get 

information about the status of sensors, and get an idea about what is happening 

in your circuit and code as it runs.

Serial monitor

Fig. 1

44

Project 03
Love-o-Meter

BUILD THE
CIRCUIT

+ -

+ -

Fig. 2

+ -

+ -

Fig. 3

In  this  project,  you  need  to  check  the  ambient  temperature  of  the  room  before 

proceeding. You’re checking things manually right now, but this can also be accom-

plished through calibration. It’s possible to use a button to set the baseline tempera-
ture, or to have the Arduino take a sample before starting the loop() and use that 
as the reference point. Project 6 gets into details about this, or you can look at the 

Calibration example that comes bundled with the Arduino software: 

arduino.cc/calibration

45

❶

❷

❸

Just  as  you’ve  been  doing  in  the  earlier  projects,  wire  up  your 

breadboard so you have power and ground. 

Attach the cathode (short leg) of each of the LEDs you’re using to 

ground  through  a  220-ohm  resistor.  Connect  the  anodes  of  the 

LEDs to pins 2 through 4. These will be the indicators for the project.

Place the TMP36 on the breadboard with the rounded part fac-

ing away from the Arduino (the order of the pins is important!) 

as shown in Fig. 2. Connect the left pin of the flat facing side to 

power, and the right pin to ground. Connect the center pin to pin 

A0 on your Arduino. This is analog input pin 0.

Create an interface for your sensor for people interact with. A paper cutout in the 

shape of a hand is a good indicator. If you’re feeling lucky, create a set of lips for 

someone to kiss, see how well that lights things up! You might also want to label 

the LEDs to give them some meaning. Maybe one LED means you’re a cold fish, 

two LEDs means you’re warm and friendly, and three LEDs means you’re too hot 

to handle!

❶

❷

Cut out a piece of paper that will fit over the breadboard. 

Place the cutout over the breadboard so that the lips cover 

Draw a set of lips where the sensor will be, and cut some 

the sensor and the LEDs fit into the holes. Press the lips to 

circles for the LEDs to pass through.

see how hot you are!

46

Project 03
Love-o-Meter

THE CODE

A pair of useful constants

Constants  are  similar  to  variables  in  that  they  allow  you  to 

uniquely name things in the program, but unlike variables they 

cannot change. Name the analog input for easy reference, and 

create another named constant to hold the baseline temperature. 

For every 2 degrees above this baseline, an LED will turn on.

You’ve already seen the int datatype, used here to identify which 

pin the sensor is on. The temperature is being stored as a float, or 

floating-point number. This type of number has a decimal point, 

and is used for numbers that can be expressed as fractions.

In  the  setup  you’re  going  to  use  a  new  command,  Serial.
begin(). This opens up a connection between the Arduino and 
the computer, so you can see the values from the analog input 

on your computer screen.
The  argument  9600  is  the  speed  at  which  the  Arduino  will 
communicate,  9600  bits  per  second.  You  will  use  the  Arduino 

IDE’s  serial  monitor  to  view  the  information  you  choose  to 

send from your microcontroller. When you open the IDE’s serial 

monitor verify that the baud rate is 9600.

Next up is a for() loop to set some pins as outputs. These are 
the pins that you attached LEDs to earlier. Instead of giving them 
unique names and typing out the pinMode() function for each 
one, you can use a for() loop to go through them all quickly. 
This is a handy trick if you have a large number of similar things 
you wish to iterate through in a program. Tell the for() loop to 
run through pins 2 to 4 sequentially.

In  the  loop(),  you’ll  use  a  local  variable  named  sensorVal 
to  store  the  reading  from  your  sensor.  To  get  the  value  from 
the sensor, you call analogRead() that takes one argument: 
what pin it should take a voltage reading on. The value, which is 

between 0 and 1023, is a representation of the voltage on the pin.

The  function  Serial.print()  sends  information  from  the 
Arduino to a connected computer. You can see this information 
in  your  serial  monitor.  If  you  give  Serial.print()  an 
argument in quotation marks, it will print out the text you typed. 

If you give it a variable as an argument, it will print out the value 

of that variable.

Initialize the serial port to 

the desired speed

Initialize the digital pin 

directions and turn off

Read the temperature sensor

Send the temperature sensor 

values to the computer

47

1

2

3

4

5

6

7

8

const int sensorPin = A0;

const float baselineTemp = 20.0;

void setup(){

  Serial.begin(9600); // open a serial port

  for(int pinNumber = 2; pinNumber<5; pinNumber++){

for() loop tutorial

    pinMode(pinNumber,OUTPUT);

    digitalWrite(pinNumber, LOW);

  } 

arduino.cc/for

9 

}

10

void loop(){

11

  int sensorVal = analogRead(sensorPin);

12

  Serial.print(“Sensor Value: “); 

13

  Serial.print(sensorVal);

 
48

Project 03
Love-o-Meter

Convert sensor reading to 

With a little math, it’s possible to figure out what the real voltage 

voltage

on the pin is. The voltage will be a value between 0 and 5 volts, 

and  it  will  have  a  fractional  part  (for  example,  it  might  be  2.5 
volts), so you’ll need to store it inside a float. Create a variable 
named  voltage  to  hold  this  number.  Divide  sensorVal  by 
1024.0  and  multiply  by  5.0.  The  new  number  represents  the 

voltage on the pin.

Just like with the sensor value, you’ll print this out to the serial 

monitor.

Convert the voltage to 

If you examine the sensor’s datasheet, there is information about 

temperature and send the 

the  range  of  the  output  voltage.  Datasheets  are  like  manuals 

value to the computer

for  electronic  components.  They  are  written  by  engineers,  for 

other  engineers.  The  datasheet  for  this  sensor  explains  that 

every  10  millivolts  of  change  from  the  sensor  is  equivalent  to 

a temperature change of 1 degree Celsius. It also indicates that 

the sensor can read temperatures below 0 degrees. Because of 

this, you’ll need to create an offset for values below freezing (0 

degrees). If you take the voltage, subtract 0.5, and multiply by 

100, you get the accurate temperature in degrees Celsius. Store 

this new number in a floating point variable called temperature.

Now that you have the real temperature, print that out to the 

serial  monitor  too.  Since  the  temperature  variable  is  the  last 

thing  you’re  going  to  be  printing  out  in  this  loop,  you’re  going 
to use a slightly different command: Serial.println(). This 
command  will  create  a  new  line  in  the  serial  monitor  after  it 

sends the value. This helps make things easier to read in when 

they are being printed out.

Turn off LEDs for a low 

temperature

With  the  real  temperature,  you  can  set  up  an  if()...else 
statement to light the LEDs. Using the baseline temperature as 

a starting point, you’ll turn on one LED on for every 2 degrees 

of  temperature  increase  above  that  baseline.  You’re  going 

to  be  looking  for  a  range  of  values  as  you  move  through  the 

temperature scale. 

49

  // convert the ADC reading to voltage

  float voltage = (sensorVal/1024.0) * 5.0;

  Serial.print(“, Volts: “);

  Serial.print(voltage);

  Serial.print(“, degrees C: “); 

Starter Kit datasheets 

  // convert the voltage to temperature in degrees

arduino.cc/kitdatasheets

  float temperature = (voltage - .5) * 100;

  Serial.println(temperature);

  if(temperature < baselineTemp){

    digitalWrite(2, LOW);

    digitalWrite(3, LOW);

    digitalWrite(4, LOW);

14

15

16

17

18

19

20

21

22

23

24

25

 
 
50

Project 03
Love-o-Meter

Turn on one LED for a low 

temperature

The && operator means “and”, in a logical sense. You can check 
for  multiple  conditions:  “if  the  temperature  is  2  degrees  greater 

than the baseline, and it is less than 4 degrees above the baseline.”

Turn on two LEDs for a 

If the temperature is between two and four degrees above the 

medium temperature

baseline, this block of code turns on the LED on pin 3 as well.

Turn on three LEDs for a 

high temperature

The  Analog-to-Digital  Converter  can  only  read  so  fast,  so  you 
should put a small delay at the very end of your loop(). If you 
read from it too frequently, your values will appear erratic. 

USE IT

With the code uploaded to the Arduino, click the serial monitor 

icon. You should see a stream of values coming out, formatted 
like this : Sensor: 200, Volts: .70, degrees C: 17 

Try putting your fingers around the sensor while it is plugged into 

the breadboard and see what happens to the values in the serial 

monitor. Make a note of what the temperature is when the sen-

sor is left in the open air. 

Close the serial monitor and change the baselineTemp constant 

in your program to the value you observed the temperature to 

be. Upload your code again, and try holding the sensor in your 

fingers. As the temperature rises, you should see the LEDs turn 

on one by one. Congratulations, hot stuff!

51

26

  }else if(temperature >= baselineTemp+2 &&                               

    temperature < baselineTemp+4){

27

    digitalWrite(2, HIGH);

28

    digitalWrite(3, LOW);

29

    digitalWrite(4, LOW);

30

  }else if(temperature >= baselineTemp+4 &&   

    temperature < baselineTemp+6){

31

    digitalWrite(2, HIGH);

32

    digitalWrite(3, HIGH);

33

    digitalWrite(4, LOW);

34

  }else if(temperature >= baselineTemp+6){

35

    digitalWrite(2, HIGH);

36

    digitalWrite(3, HIGH);

37

    digitalWrite(4, HIGH);

38

  }

39

  delay(1);

40

} 

Create an interface for two people to test their compatibility with each other. You 

get to decide what compatibility means, and how you’ll sense it. Perhaps they have 

to hold hands and generate heat? Maybe they have to hug? What do you think?

Expanding  the  types  of  inputs  you  can  read,  you’ve  used 
analogRead() and the serial monitor to track changes inside 
your Arduino. Now it’s possible to read a large number of 
analog sensors and inputs.

04

R
O
T
S
I
S
E
R

M
H
O

0
2
2

R
O
T
S
I
S
E
R

M
H
O
L
I
K

0
1

R
O
T
S
I
S
E
R
O
T
O
H
P

L
E
G

D
E
L

INGREDIENTS

 
 
 
 
 
 
 
 
53

COLOR MIXING 
LAMP

USING A TRI-COLOR LED AND THREE PHOTORESISTORS, 
YOU’LL CREATE A LAMP THAT SMOOTHLY CHANGES COLORS 
DEPENDING ON EXTERNAL LIGHTING CONDITIONS

Discover: analog output, mapping values

Time: 45 MINUTES
Level:

Builds on projects: 1, 2, 3

Blinking LEDs can be fun, but what about fading them, or mixing colors? 

You might expect that it’s just a matter of providing less voltage to an LED to get 

it to fade.

The Arduino can’t vary the output voltage on its pins, it can only output 5V. Hence 
you’ll need to use a technique called Pulse Width Modulation (PWM) to fade LEDs. 
PWM  rapidly  turns  the  output  pin  high  and  low  over  a  fixed  period  of  time.  The 

change happens faster than the human eye can see. It’s similar to the way movies 

work, quickly flashing a number of still images to create the illusion of motion. 

When  you’re  rapidly  turning  the  pin  HIGH  and  LOW,  it’s  as  if 
you were changing the voltage. The percentage of time a pin is 
HIGH in a period is called duty cycle. When the pin is HIGH for 
half of the period and LOW for the other half, the duty cycle is 
50%. A lower duty cycle gives you a dimmer LED than a higher 

duty cycle.

The Arduino Uno has six pins set aside for PWM (digital pins 3, 
5, 6, 9, 10, and 11), they can be identified by the ~ next to their 
number on the board.

For inputs in this project, you’ll be using photoresistors (sensors 
that  change  their  resistance  depending  on  the  amount  of  light 

that hits them, also known as photocells or light-dependent resis-

tors). If you connect one end of the resistor to your Arduino, you 

can measure the change in resistance by checking the voltage on 

the pin. 

 
54

Project 04
Color Mixing Lamp

BUILD THE
CIRCUIT

+ -

+ -

Fig. 1

+ -

+ -

Fig. 2

Fig. 3

55

❶

❷

❸

❹

 R
-

G

B

Wire up your breadboard so you have power and ground on both 

sides, just like the earlier projects. 

Place the three photoresistors on the breadboard so they cross 

the center divide from one side to the other, as shown in Fig. 1. 

Attach  one  end  of  each  photoresistor  to  power.  On  the  other 

side, attach a 10-kilohm resistor to ground. This resistor is in se-

ries with the photoresistor, and together they form a voltage di-

vider. The voltage at the point where they meet is proportional 

to  the  ratio  of  their  resistances,  according  to  Ohm’s  Law  (see 

Project  1 for more on Ohm’s Law). As the resistance of the pho-

toresistor changes when light hits it, the voltage at this junction 

changes as well. On the same side as the resistor, connect the 

photoresistors to Analog In pins 0, 1, and 2 with hookup wire.

Take the three colored gels and place one over each of the pho-

toresistors. Place the red gel over the photoresistor connected 

to A0, the green over the one connected to A1, and the blue over 

the one connected to A2. Each of these filters lets only light of a 

specific wavelength through to the sensor it’s covering. The red 

filter passes only red light, the green filter passes only green light, 

and the blue filter passes only blue light. This allows you to de-

tect the relative color levels in the light that hits your sensors.

The LED with 4 legs is a common cathode RGB LED. The LED has 

separate red, green, and blue elements inside, and one common 

ground (the cathode). By creating a voltage difference between 

the cathode and the voltage coming out of the Arduino’s PWM 

pins (which are connected to the anodes through 220-ohm re-

sistors), you’ll cause the LED to fade between its three colors. 

Make note of what the longest pin is on the LED, place it in your 

breadboard, and connect that pin to ground. Connect the other 

three  pins  to  digital  pins  9,  10  and  11  in  series  with  220-ohm 

resistors. Be sure to connect each LED lead to the correct PWM 

pin, according to the figure on the left.

56

Project 04
Color Mixing Lamp

THE CODE

Useful constants

Set up constants for the pins you’re using for input and output, 

so you can keep track of which sensor pairs with which color on 

the LED. Use const int for the datatype.

Variables to store the sensor 

readings as well as the light 

level of each LED

Add variables for the incoming sensor values and for the output 
values  you’ll  be  using  to  fade  the  LED.  You  can  use  the  int 
datatype for all the variables.

Setting the direction of the 

digital pins and setting up 

In the setup(), begin serial communication at 9600 bps. Just 
like in the previous example, you will use this to see the values of 

the serial port

the sensors in the serial monitor. Additionally, you will be able to 

see the mapped values you’ll use to fade the LED. Also, define the 
LED pins as outputs with pinMode().

Reading the value of each 

light sensor

In  the  loop()  read  the  sensor  values  on  A0,  A1,  and  A2  with 
analogRead() and store the value in the appropriate variables. 
Put a small delay() between each analogRead() as the ADC 
takes a millisecond to do its work.

Report the sensor readings 

to the computer

Print out the sensor values on one line.
The  “\t”  is  the  equivalent  of  pressing  the “tab”  key  on  the 
keyboard.

57

1

2

3

4

5

6

7

8

9

const int greenLEDPin = 9;

const int redLEDPin = 11; 

const int blueLEDPin = 10; 

const int redSensorPin = A0;  

const int greenSensorPin = A1; 

const int blueSensorPin = A2; 

int redValue = 0; 

int greenValue = 0; 

int blueValue = 0; 

10

int redSensorValue = 0; 

11

int greenSensorValue = 0; 

12

int blueSensorValue = 0; 

13

void setup() { 

14    

  Serial.begin(9600); 

15

  pinMode(greenLEDPin,OUTPUT);

16

  pinMode(redLEDPin,OUTPUT);

17

  pinMode(blueLEDPin,OUTPUT);

18

}

19

void loop() {

20

  redSensorValue = analogRead(redSensorPin);

21

  delay(5);

22

  greenSensorValue = analogRead(greenSensorPin);

23

  delay(5);

24

  blueSensorValue = analogRead(blueSensorPin);

25

  Serial.print(“Raw Sensor Values \t Red: “);

26

  Serial.print(redSensorValue);

27

  Serial.print(“\t Green: “);

28

  Serial.print(greenSensorValue);

29

  Serial.print(“\t Blue: “);

30

  Serial.println(blueSensorValue);

 
58

Project 04
Color Mixing Lamp

Converting the sensor 

readings 

The function to change the LED’s brightness via PWM is called 
analogWrite(). It needs two arguments: the pin to write to, 
and a value between 0-255. This second number represents the 

duty cycle the Arduino will output on the specified pin. A value of 
255 will set the pin HIGH all the time, making the attached LED 
as bright as it can be. A value of 127 will set the pin HIGH half 
the time of the period, making the LED dimmer. 0 would set the 
pin LOW all the time, turning the LED off. To convert the sensor 
reading from a value between 0-1023 to a value between 0-255 
for analogWrite(), divide the sensor reading by 4.

Report the calculated LED 

Print out the new mapped values on their own line.

light levels

Set the LED light levels

USE IT

Once you have your Arduino programmed and wired up, open 

the  serial  monitor.  The  LED  will  probably  be  an  off-white 

color, depending on the predominant color of the light in your 

room. Look at the values coming from the sensors in the serial 

monitor, if you’re in an environment with stable lighting, the 

number should probably be fairly consistent. 

Turn off the light in the room you’re in and see what happens 

to the values of the sensors. With a flashlight, illuminate each 

of the sensors individually and notice how the values change 

in the serial monitor, and notice how the LED’s color changes. 

When the photoresistors are covered with a gel, they only re-

act to light of a certain wavelength. This will give you the op-

portunity to change each of the colors independently.

59

31

  redValue = redSensorValue/4;

32

  greenValue = greenSensorValue/4;

33

  blueValue = blueSensorValue/4;

34

  Serial.print(“Mapped Sensor Values \t Red: “);

35

  Serial.print(redValue);

36

  Serial.print(“\t Green: “);

37

  Serial.print(greenValue);

38

  Serial.print(“\t Blue: “);

39

  Serial.println(blueValue); 

40

  analogWrite(redLEDPin, redValue);

41

  analogWrite(greenLEDPin, greenValue);

42

  analogWrite(blueLEDPin, blueValue);

43

}

You may notice that the photoresistor’s output doesn’t range all the way from 0 

to 1023. That’s okay for this project, but for a more detailed explanation of how to 

calibrate for the range you’re reading, see Project 6.

You’ll probably notice that the LED’s fading is not linear. When the LED is about at 

half brightness, it appears to stop getting much brighter. This is because our eyes 

don’t perceive brightness linearly. The brightness of the light depends not only on 
the level that you analogWrite() but also on the distance of the light from the 
diffuser, the distance of your eye from the light, and the brightness of the light rela-

tive to other light in the room. 

How could you use this to let you know if it’s a nice day outside while you’re working

inside? What other sorts of sensors can you use to control the LED’s color?

60

Project 04
Color Mixing Lamp

The LED on its own is pretty neat, but it’s not much of a lamp. However, there are 

a number of different ways you can diffuse the light to make it resemble some-

thing like a traditional incandescent. A ping pong ball with a hole cut out for the 

LED to slide into makes for a nice diffuser. Other ways include covering the light 

in translucent glue, or sanding the surface of the light. No matter what route you 

take, you’re going to lose at least a little brightness when it’s diffused, but it will 

probably look a lot nicer. 

No  longer  limited  to  just  turning  lights  on  and  off,  you 
now  have  control  over  how  bright  or  dim  something  will 
be. analogWrite() is the function that allows you to PWM 
components attached to pins 3, 5, 6, 9, 10, or 11, varying the 
duty cycle.

The  ping  pong  ball  cut  in  order  to 

accommodate the LED

Fig.4

05

R
E
T
E
M
O
I
T
N
E
T
O
P

R
O
T
O
M

O
V
R
E
S

M
R
A

R
O
T
O
M

R
O
T
I
C
A
P
A
C

F
U
0
0
1

MALE HEADER PIN (3 pins)

INGREDIENTS

 
 
 
 
63

MOOD CUE

USE A SERVO MOTOR TO MAKE A MECHANICAL GAUGE TO 
POINT OUT WHAT SORT OF MOOD YOU’RE IN THAT DAY

Discover: mapping values, servo motors, using built-in libraries

Time: 1 HOUR
Level:

Builds on projects: 1, 2, 3, 4

Servo motors are a special type of motor that don’t spin around in a circle, but 
move  to  a  specific  position  and  stay  there  until  you  tell  them  to  move  again. 

Servos  usually  only  rotate  180  degrees  (one  half  of  a  circle).  Combining  one  of 

these motors with a little cardboard craft, you’ll be able to let people know if they 

should come and ask for your help on their next project or not.

Similar to the way you used pulses to PWM an LED in the Color Mixing Lamp Project, 

servo motors expect a number of pulses that tell them what angle to move to. The 

pulses always come at the same time intervals, but the width varies between 1000 

and 2000 microseconds. While it’s possible to write code to generate these pulses, 

the Arduino software comes with a library that allows you to easily control the motor.

Because  the  servo  only  rotates  180  degrees,  and  your  analog  input  goes  from 
0-1023,  you’ll  need  to  use  a  function  called  map()  to  change  the  scale  of  the 
values coming from the potentiometer.

One of the great things about the Arduino community are the talented people 

who extend its functionality through additional software. It’s possible for anyone 

to write libraries to extend the Arduino’s functionality. There are libraries for a wide 

variety of sensors and actuators and other devices that users have contributed to 

the community. A software library expands the functionality of a programming 

environment.  The  Arduino  software  comes  with  a  number  of  libraries  that  are 

useful for working with hardware or data. One of the included libraries is designed 

to  use  with  servo  motors.  In  your  code,  you’ll  import  the  library,  and  all  of  its 

functionality will be available to you.

+ -

+ -

+ -

+ -

64

Project 05
Mood Cue

BUILD THE
CIRCUIT

Fig. 1

Fig. 2

65

❶

❷

❸

❹

Attach 5V and ground to one side of your breadboard from the 

Arduino.

Place a potentiometer on the breadboard, and connect one side 

to 5V, and the other to ground. A potentiometer is a type of volt-

age  divider.  As  you  turn  the  knob,  you  change  the  ratio  of  the 

voltage  between  the  middle  pin  and  power.  You  can  read  this 

change on an analog input. Connect the middle pin to analog pin 

0. This will control the position of your servo motor.

The servo has three wires coming out of it. One is power (red), 

one is ground (black), and the third (white) is the control line that 

will receive information from the Arduino. Plug three male head-

ers into the female ends of the servo wires (see Fig. 3). Connect 

the headers to your breadboard so that each pin is in a different 

row. Connect 5V to the red wire, ground to the black wire, and 

the white wire to pin 9. 

When a servo motor starts to move, it draws more current than 

if it were already in motion. This will cause a dip in the voltage 

on  your  board.  By  placing  a  100uf  capacitor  across  power  and 

ground right next to the male headers as shown in Fig. 1, you can 

smooth out any voltage changes that may occur. You can also 

place a capacitor across the power and ground going into your 
potentiometer. These are called decoupling capacitors because 
they  reduce,  or  decouple,  changes  caused  by  the  components 

from the rest of the circuit. Be very careful to make sure you are 

connecting the cathode to ground (that’s the side with a black 

stripe  down  the  side)  and  the  anode  to  power.  If  you  put  the 

capacitors in backwards, they can explode.

Your servo motor comes with 

female connectors, so you’ll 

need to add header pins to 

connect it to the breadboard.

Fig. 3

66

Project 05
Mood Cue

THE CODE

Import the library

To use the servo library, you’ll first need to import it. This makes 

the additions from the library available to your sketch.

Creating the Servo object

To  refer  to  the  servo,  you’re  going  to  need  to  create  a  named 
instance of the servo library in a variable. This is called an object. 
When you do this, you’re making a unique name that will have all 

the functions and capabilities that the servo library offers. From 
this point on in the program, every time you refer to myServo, 
you’ll be talking to the servo object.

Variable declaration

Set  up  a  named  constant  for  the  pin  the  potentiometer  is 

attached  to,  and  variables  to  hold  the  analog  input  value  and 

angle you want the servo to move to.

Associating the Servo object 

with the Arduino pin, 

initializing the serial port

In the setup(), you’re going to need to tell the Arduino what 
pin your servo is attached to.

Include a serial connection so you can check the values from the 

potentiometer  and  see  how  they  map  to  angles  on  the  servo 

motor.

Reading the potentiometer 

value

In the loop(), read the analog input and print out the value to 
the serial monitor.

Mapping potentiometer 

value to the servo values

Rotating the servo

To create a usable value for the servo motor from your analog 
input, it’s easiest to use the map() function. This handy function 
scales numbers for you. In this case it will change values between 
0-1023  to  values  between  0-179.  It  takes  five  arguments  :  the 

number to be scaled (here it’s potVal), the minimum value of the 

input (0), the maximum value of the input (1023), the minimum 

value of the output (0), and the maximum value of the output 

(179). Store this new value in the angle variable.

Then, print out the mapped value to the serial monitor.

Finally,  it’s  time  to  move  the  servo.  The  command  servo.
write() moves the motor to the angle you specify.
At the end of the loop() put a delay so the servo has time to 
move to its new position.

67

Note that #include instractions have not 
semicolon at the end of the line.

1

#include <Servo.h>

2

Servo myServo;

3

4

5

6

7

8

9

int const potPin = A0; 

int potVal; 

int angle; 

void setup() {

  myServo.attach(9);

  Serial.begin(9600);

}

10

void loop() {

11

  potVal = analogRead(potPin); 

12

  Serial.print(“potVal: “); 

13 

  Serial.print(potVal);

14

  angle = map(potVal, 0, 1023, 0, 179);

15

  Serial.print(“, angle: “); 

16

  Serial.println(angle); 

17

  myServo.write(angle);

18

  delay(15);

19

}

68

Project 05
Mood Cue

USE IT

Once  your  Arduino  has  been  programmed  and  powered  up, 

open  the  serial  monitor.  You  should  see  a  stream  of  values 

similar to this: 

potVal : 1023, angle : 179

potVal : 1023, angle : 179

When you turn the potentiometer, you should see the num-

bers  change.  More  importantly,  you  should  see  your  servo 

motor  move  to  a  new  position.  Notice  the  relationship  be-

tween the value of potVal and angle in the serial monitor and 

the position of the servo. You should see consistent results as 

you turn the pot.

One nice thing about using potentiometers as analog inputs 

is that they will give you a full range of values between 0 and 

1023.  This  makes  them  helpful  in  testing  projects  that  use 

analog input.

Servo motors are regular motors with a number of gears and some circuits inside. 

The mechanics inside provide feedback to the circuit, so it is always aware of its posi-

tion. While it may seem like this is a limited range of motion, it’s possible to get it to 

make a wide variety of different kinds of movements with some additional mechanics. 
There are a number of resources that describe mechanisms in detail like robives.com/
mechs and the book Making Things Move by Dustyn Roberts.

The potentiometer is not the only sensor you can use for controlling the servo. 

Using the same physical setup (an arrow pointing to a number of different indi-

cators) and a different sensor, what sort of indicator can you make? How would 

this work with temperature (like in the Love-o-Meter)? Could you tell the time 

of  day  with  a  photoresistor?  How  does  mapping  values  come  into  play  with 

those types of sensors?

Servo  motors  can  easily  be  controlled  by  the  Arduino 
using a library, which is a collection of code that extends 
a  programming  environment.  Sometimes  it  is  necessary 
to  repurpose  values  by  mapping  them  from  one  scale  to 
another.

69

Now that you’re up and running with motion, it’s time to let people know if you’re 

available to help them on their projects, or if you want to be left alone to plan 

your next creation. 

With scissors, cut out a piece of cardboard in the shape of an arrow. Position your 

servo to 90 degrees (check the angle value in the serial monitor if you’re unsure). 

Tape the arrow so it’s oriented in the same direction as the motor’s body. Now you 

should be able to rotate the arrow 180 degrees when turning the potentiometer.

Take a piece of paper that is larger than the servo with the arrow attached and 

draw a half circle on it. On one end of the circle, write “Stay Out”. On the other end, 

write “Come in”. Put “Knock please!” in the middle of the arc. Place the servo with 

the arrow on top of the paper. Congratulations, you’ve got a way to tell people just 

how busy you are with your projects!

C O M E   I N
C O M E   I N

S
S

T
T

A
A

Y
Y

O
O

U
U

T
T

E
E
S
S
A
A
E
E
L
L
P
P

K
K
C
C
O
O
N
N
K
K

❶

❷

Attach a paper arrow to the servo arm.

Design a paper base and place it under the servo.

 
 
 
 
06

R
O
T
S
I
S
E
R
O
T
O
H
P

O
Z
E
I
P

R
O
T
S
I
S
E
R

M
H
O
L
I
K

0
1

INGREDIENTS

 
 
71

LIGHT 
THEREMIN

TIME TO MAKE SOME NOISE! USING A PHOTORESISTOR 
AND A PIEZO ELEMENT, YOU’RE GOING TO MAKE A 
LIGHT-BASED THEREMIN

Discover: making sound with the tone() function, calibrating 

analog sensors
Time: 45 MINUTES
Level:

Builds on projects: 1, 2, 3, 4

A  theremin  is  an  instrument  that  makes  sounds  based  on  the  movements  of 
a  musician’s  hands  around  the  instrument.  You’ve  probably  heard  one  in  scary 

movies. The theremin detects where a performer’s hands are in relation to two 

antennas by reading the capacitive change on the antennas. These antennas are 

connected  to  analog  circuitry  that  create  the  sound.  One  antenna  controls  the 

frequency of the sound and the other controls volume. While the Arduino can’t 

exactly  replicate  the  mysterious  sounds  from  this  instrument,  it  is  possible  to 
emulate them using the tone() function. Fig. 1 shows the difference between 
the pulses emitted by analogWrite() and tone(). This enables a transducer 
like a speaker or piezo to move back and forth at different speeds. 

Notice how the signal is low most of the time, 

but the frequency is the same as PWM 200.

PWM 50: analogWrite(50)

Notice how the voltage is high most of the 

time, but the frequency is the same as PWM 50.

PWM 200: analogWrite(200)

PERIOD

PERIOD

The duty cycle is 50% (on half the time, off half 

the time), but the frequency changes.

TONE 440: tone(9,440)

PERIOD

Same duty cycle as Tone 440; but twice the 

TONE 880: tone(9,880)

PERIOD

frequency.

Fig. 1

10 MILLISECONDS

5

0

5

0

5

0

5

0

72

Project 06
Light Theremin

Instead of sensing capacitance with the Arduino, you’ll be using a photoresistor 

to  detect  the  amount  of  light.  By  moving  your  hands  over  the  sensor,  you’ll 

change  the  amount  of  light  that  falls  on  the  photoresistor’s  face,  as  you  did 

in Project 4. The change in the voltage on the analog pin will determine what 

frequency note to play. 

You’ll connect the photoresistors to the Arduino using a voltage divider circuit like 

you did in Project 4. You probably noticed in the earlier project that when you read 
this circuit using analogRead(), your readings didn’t range all the way from 0 
to 1023. The fixed resistor connecting to ground limits the low end of the range, 

and the brightness of your light limits the high end. Instead of settling for a limited 

range, you’ll calibrate the sensor readings getting the high and low values, mapping 
them to sound frequencies using the map() function to get as much range out of 
your theremin as possible. This will have the added benefit of adjusting the sensor 

readings whenever you move your circuit to a new environment, like a room with 

different light conditions.

A piezo is a small element that vibrates when it receives electricity. When it moves, 
it displaces air around it, creating sound waves.

BUILD THE
CIRCUIT

+ -

+ -

Fig. 2

+ -

+ -

73

Fig. 3

Traditional theremins can control the frequency and the volume of sound. In this 

example, You’ll be able to control the frequency only. While you can’t control the 

volume through the Arduino, it is possible to change the voltage level that gets 

to the speaker manually. What happens if you put a potentiometer in series with 

pin 8 and the piezo? What about another photoresistor?

❶

❷

❸

On your breadboard, connect the outer bus lines to power and 

ground. 

Take your piezo, and connect one end to ground, and the other 

to digital pin 8 on the Arduino. 

Place  your  photoresistor  on  the  breadboard,  connecting  one 

end to 5V. Connect the other end to the Arduino’s analogIn pin 

0, and to ground through a 10-kilohm resistor. This circuit is the 

same as the voltage divider circuit in Project  4.

74

Project 06
Light Theremin

THE CODE

Create variables for 

calibrating the sensor

Create  a  variable  to  hold  the  analogRead()  value  from  the 
photoresistor. Next, create variables for the high and low values. 

You’re going to set the initial value in the sensorLow variable to 
1023, and set the value of the sensorHigh variable to 0. When 
you first run the program, you’ll compare these numbers to the 

sensor’s readings to find the real maximum and minimum values.

Name a constant for your 

calibration indicator

Create a constant named ledPin. You’ll use this as an indicator 
that your sensor has finished calibrating. For this project, use the 

on-board LED connected to pin 13.

Set digital pin direction and 

turn it high

In the setup(), change the pinMode() of ledPin to OUTPUT, 
and turn the light on.

Use a while() loop for 

calibration

The next steps will calibrate the sensor’s maximum and minimum 
values.  You’ll  use  a  while()  statement  to  run  a  loop  for  5 
seconds. while() loops run until a certain condition is met. In 
this  case  you’re  going to  use  the millis()  function to  check 
the current time. millis() reports how long the Arduino has 
been running since it was last powered on or reset.

Compare sensor values for 

calibration

In the loop, you’ll read the value of the sensor; if the value is less 
than  sensorLow  (initially  1023),  you’ll  update  that  variable.  If 
it is greater than sensorHigh (initially 0), that gets updated.

Indicate calibration has 

When 5 seconds have passed, the while() loop will end. Turn off 

finished

the  LED  attached  to  pin  13.  You’ll  use  the  sensor  high  and  low 

values just recorded to scale the frequency in the main part of 

your program.

75

1

2

3

int sensorValue;

int sensorLow = 1023;

int sensorHigh = 0;

4

const int ledPin = 13;

5

void setup() {

6

7

  pinMode(ledPin, OUTPUT);

  digitalWrite(ledPin, HIGH);

8

  while (millis() < 5000) {

while()

arduino.cc/while

9

    sensorValue = analogRead(A0);

10

    if (sensorValue > sensorHigh) {

11

      sensorHigh = sensorValue;

12

    }

13

    if (sensorValue < sensorLow) {

14

      sensorLow = sensorValue;

15

    }

16

  }

17

  digitalWrite(ledPin, LOW);

18

}

 
76

Project 06
Light Theremin

Read and store the sensor 

In the loop(), read the value on A0 and store it in sensorValue.

value

Map the sensor value to a 

frequency

Play the frequency

USE IT

Create  a  variable  named  pitch.  The  value  of  pitch  is  going 
to  be  mapped  from  sensorValue.  Use  sensorLow  and 
sensorHigh as the bounds for the incoming values. For starting 
values for output, try 50 to 4000. These numbers set the range 

of frequencies the Arduino will generate.

Next,  call  the  tone()  function  to  play  a  sound.  It  takes  three 
arguments : what pin to play the sound on (in this case pin 8), 
what frequency to play (determined by the pitch variable), and 
how long to play the note (try 20 milliseconds to start).

Then, call a delay() for 10 milliseconds to give the sound some 
time to play.

When you first power the Arduino on, there is a 5 second win-

dow  for  you  to  calibrate  the  sensor.  To  do  this,  move  your 

hand  up  and  down  over  the  photoresistor,  changing  the 

amount  of  light  that  reaches  it.  The  closer  you  replicate  the 

motions you expect to use while playing the instrument, the 

better the calibration will be.

After 5 seconds, the calibration will be complete, and the LED 

on  the  Arduino  will  turn  off.  When  this  happens,  you  should 

hear  some  noise  coming  from  the  piezo!  As  the  amount  of 

light that falls on the sensor changes, so should the frequency 

that the piezo plays.

77

19

void loop() {

20

  sensorValue = analogRead(A0);

21

  int pitch = 

    map(sensorValue,sensorLow,sensorHigh, 50, 4000);

22

  tone(8,pitch,20);

23

  delay(10);

24

}

The range in the map() function that determines the pitch is pretty wide, try 
changing the frequencies to find ones that are the right fit for your musical style.

The tone() function operates very much like the PWM in analogWrite() but with 
one significant difference. In analogWrite() the frequency is fixed; you change the 
ratio of the pulses in that period of time to vary the duty cycle. With tone() you’re 
still sending pulses, but changing the frequency of them. tone() always pulses at a 
50% duty cycle (half the time the pin is high, the other half the time it is low).

The tone() function gives you the ability to generate different 
frequencies when it pulses a speaker or piezo. When using 
sensors in a voltage divider circuit, you probably won’t get a 
full range of values between 0-1023. By calibrating sensors, 
it’s possible to map your inputs to a useable range.

07

R
O
T
S
I
S
E
R

M
H
O
L
I
K

0
1

O
Z
E
I
P

R
O
T
S
I
S
E
R

M
H
O
G
E
M

1

R
O
T
S
I
S
E
R

M
H
O

0
2
2

H
C
T
I
W
S

INGREDIENTS

 
 
 
 
 
 
79

KEYBOARD 
INSTRUMENT

WITH FEW RESISTORS AND BUTTONS YOU ARE GOING TO 
BUILD A SMALL MUSICAL KEYBOARD

Discover: resistor ladders, arrays

Time: 45 MINUTES
Level:

Builds on projects: 1, 2, 3, 4, 6

While it’s possible to simply hook up a number of momentary switches to digital 

inputs to key of different tones, in this project, you’ll be constructing something 
called a resistor ladder. 

This is a way to read a number of switches using the analog input. It’s a helpful 

technique if you find yourself short on digital inputs. You’ll hook up a number of 
switches that are connected in parallel to analog in 0. Most of these will connect 
to power through a resistor. When you press each button, a different voltage level 

will pass to the input pin. If you press two buttons at the same time, you’ll get a 

unique input based on the relationship between the two resistors in parallel.

A resistor ladder and five 

switches as analog input.

Fig. 1

80

Project 07
Keyboard Instrument

BUILD THE
CIRCUIT

+ -

+ -

+ -

+ -

The arrangement of resistors and switches 

feeding into an analog input is called a resistor 

ladder. 

Fig. 2

Fig. 3

81

❶

❷

Wire  up  your  breadboard  with  power  and  ground  as  in  the 

previous  projects.  Connect  one  end  of  the  piezo  to  ground. 

Connect the other end to pin 8 on your Arduino.

Place your switches on the breadboard as shown in the circuit. 

The  arrangement  of  resistors  and  switches  feeding  into  an 

analog  input  is  called  a  resistor  ladder.  Connect  the  first  one 

directly to power. Connect the second, third and fourth switches 

to power through a 220-ohm, 10-kilohm and 1-megohm resistor, 

respectively. Connect all the switches’ outputs together in one 

junction.  Connect  this  junction  to  ground  with  a  10-kilohm 

resistor, and also connect it to Analog In 0. Each of these acts as 

a voltage divider.

Think  about  an  enclosure  for  the  keyboard.  While  old  analog  synthesizers  had 

wires poking out all over the place, your keyboard is sleek and digital. Prepare a 

small piece of cardboard that can be cut out to accommodate your buttons. Label 

the keys, so you know what notes are triggered by each key.

❶

❷

Draw and cut a piece of paper with holes for the four 

Position the paper over the buttons and piezo.

buttons and piezo. Decorate it to look like a piano keyboard.

Enjoy your creation!

82

Project 07
Keyboard Instrument

THE CODE

The array

In this program, you’ll need to keep a list of frequencies you want 

to play when you press each of your buttons. You can start out 

with  the  frequencies  for  middle  C,  D,  E  and  F  (262Hz,  294Hz, 

330Hz, and 349Hz). To do this, you’ll need a new kind of variable 

called an array.

An  array  is  a  way  to  store  different  values  that  are  related  to 

each  other,  like  the  frequencies  in  a  musical  scale,  using  only 

one  name.  They  are  a  convenient  tool  for  you  to  quickly  and 

efficiently  access  information.  To  declare  an  array,  start  as  you 

would with a variable, but follow the name with a pair of square 

brackets: []. After the equals sign, you’ll place your elements in 

curly brackets. 

To read or change the elements of the array, you reference the 

individual element using the array name and then the index of 

the item you want to address. The index refers to the order in 

which the items appear when the array is created. The first item 

in the array is item 0, the second is item 1, and so forth. 

Create an array of 

frequencies

Set up an array of four notes using the frequencies listed above. 

Make  this  array  a  global  variable  by  declaring  it  before  the 
setup().

Begin serial communication

In your setup(), start serial communication with the computer.

Read the analog value and 

send it to the serial monitor

In  the  loop(),  declare  a  local  variable  to  hold  the  value 
read  on  pin  A0.  Because  each  switch  has  a  different  resistor 

value  connecting  it  to  power,  each  will  have  a  different  value 
associated  with  it.  To  see  the  values,  add  the  line  Serial.
println(keyVal) to send to the computer.

Use an if()...else statement to 

determine what note to play

Using an if()...else statement, you can assign each value to a 
different tone. The values included in the example program are 

ballpark figures for these resistor sizes. As all resistors have some 

tolerance for error, these may not work exactly for you. Use the 

information from the serial monitor to adjust as necessary.

83

int buttons[6]; 

// set up an array with 6 integers

int buttons[0] = 2; 

// give the first element of the array the value 2

1

int notes[] = {262,294,330,349};

2

3

4

5

6

7

8

9

void setup() {

  Serial.begin(9600);

}

void loop() {

  int keyVal = analogRead(A0);

  Serial.println(keyVal);

  if(keyVal == 1023){

    tone(8, notes[0]); 

10

  } 

 
84

Project 07
Keyboard Instrument

Play the notes that correspond 

to the analog value

After  each  if()  statement,  call  the  tone()  function.  The 
program  references  the  array  to  determine  what  frequency 

to  play.  If  the  value  of  A0  matches  one  of  your  if  statements, 

you can tell the Arduino to play a tone. It’s possible your circuit 

is  a  little  “noisy”  and  the  values  may  fluctuate  a  little  bit  while 

pressing a switch. To accommodate for this variation, it’s a good 

idea to have a small range of values to check against. If you use 
the comparison “&&”, you can check multiple statements to see 
if they are true. 

If you press the first button, notes[0] will play. If you press the 

second, notes[1] will play, and if you press the third, notes[2] will 

play. This is when arrays become really handy.

Stop playing the tone when 

Only  one  frequency  can  play  on  a  pin  at  any  given  time,  so  if 

nothing is pressed

you’re pressing multiple keys, you’ll only hear one sound. 

USE IT

To  stop  playing  notes  when  there  is  no  button  being  pressed, 
call the noTone() function, providing the pin number to stop 
playing sound on.

If your resistors are close in value to the values in the example 

program, you should hear some sounds from the piezo when 

you press the buttons. If not, check the serial monitor to make 

sure each of the buttons is in a range that corresponds to the 
notes in the if()...else statement. If you’re hearing a sound 
that seems to stutter, try increasing the range a little bit.

Press multiple buttons at the same time, and see what sort of 

values  you  get  in  the  serial  monitor.  Use  these  new  values  to 

trigger even more sounds. Experiment with different frequencies 

to  expand  your  musical  output.  You  can  find  frequencies  of 
musical notes on this page: arduino.cc/frequencies

If you replace the switches and resistor ladder with analog sensors, can you use the 

additional  information  they  give  you  to  create  a  more  dynamic  instrument?  You 

could use the value to change the duration of a note or, like in the Theremin Project, 

create a sliding scale of sounds.

85

11

  else if(keyVal >= 990 && keyVal <= 1010){

12

    tone(8, notes[1]); 

13

  } 

14

  else if(keyVal >= 505 && keyVal <= 515){

15

    tone(8, notes[2]); 

16

  } 

17

  else if(keyVal >= 5 && keyVal <= 10){

18

    tone(8, notes[3]);

19

  } 

20

  else{

21

    noTone(8);

22

  }

23

}

The tone() function is fun for generating sounds, but it does have a few limi-
tations.  It  can  only  create  square  waves,  not  smooth  sine  waves  or  triangles. 

Square waves don’t look much like waves at all. As you saw in Fig. 1 in Project 6, 

it’s a series of on and off pulses. 

As you start your band, keep some things in mind : only one tone can play at a time 
and tone() will interfere with analogWrite() on pins 3 and 11.

Arrays are useful for grouping similar types of information 
together; they are accessed by index numbers which refer 
to individual elements. Resistor ladders are an easy way to 
get more digital inputs into a system by plugging into an 
analog input.

08

R
O
T
S
I
S
E
R

M
H
O
L
I
K

0
1

R
O
T
S
I
S
E
R

M
H
O

0
2
2

H
C
T
I
W
S

D
E
L

INGREDIENTS

 
 
 
 
87

DIGITAL 
HOURGLASS

IN THIS PROJECT, YOU’LL BUILD A DIGITAL HOURGLASS 
THAT TURNS ON AN LED EVERY TEN MINUTES. KNOW HOW 
LONG YOU’RE WORKING ON YOUR PROJECTS BY USING THE 
ARDUINO’S BUILT-IN TIMER

Discover: long data type, creating a timer

Time: 30 MINUTES
Level:

Builds on projects: 1, 2, 3, 4

Up to now, when you’ve wanted something to happen at a specific time interval 

with the Arduino, you’ve used delay(). This is handy, but a little confining. When the 

Arduino calls delay(), it freezes its current state for the duration of the delay. That 

means  there  can  be  no  other  input  or  output  while  it’s  waiting.  Delays  are  also 

not very helpful for keeping track of time. If you wanted to do something every 10 

seconds, having a 10 second delay would be fairly cumbersome.

The millis() function helps to solve these problems. It keeps track of the time 
your Arduino has been running in milliseconds. You used it previously in Project 6 

when you created a timer for calibration. 

So far you’ve been declaring variables as int. An int (integer) is a 16-bit number, 
it holds values between -32,768 and 32,767. Those may be some large numbers, 
but if the Arduino is counting 1000 times a second with millis(), you’d run out 
of space in less than a minute. The long datatype holds a 32-bit number (between 
-2,147,483,648  and  2,147,483,647).  Since  you  can’t  run  time  backwards  to  get 
negative numbers, the variable to store millis() time is called an unsigned 
long. When a datatype is called unsigned, it is only positive. This allows you to 
count even higher. An unsigned  long can count up to 4,294,967,295. That’s 
enough space for milis() to store time for almost 50 days. By comparing the 
current millis() to a specific value, you can see if a certain amount of time has 
passed.

When you turn your hourglass over, a tilt switch will change its state, and that will 

set off another cycle of LEDs turning on. 

The tilt switch works just like a regular switch in that it is an on/off sensor. You’ll 

use it here as a digital input. What makes tilt switches unique is that they detect 

orientation. Typically they have a small cavity inside the housing that has a metal 

88

Project 08
Digital Hourglass

ball.  When  tilted  in  the  proper  way,  the  ball  rolls  to  one  side  of  the  cavity  and 

connects the two leads that are in your breadboard, closing the switch.

With six LEDs, your hourglass will run for an hour, just as its name implies. 

BUILD THE
CIRCUIT

+ -
+ -

+ -
+ -

Fig. 1

+ -
+ -

+ -
+ -

Fig. 2

89

❶
❷

❸

Connect power and ground to your breadboard. 

Connect  the  anode  (longer  leg)  of  six  LEDs  to  digital  pins  2-7. 

Connect the LEDs to ground through 220-ohm resistors.

Connect one lead of the tilt switch to 5V. Connect the other to 

a 10-kilohm resistor to ground. Connect the junction where they 

meet to digital pin 8.

You don’t need to have your Arduino tethered to the computer for this to work. 

Try building a stand with some cardboard or styrofoam and power the Arduino 

with a battery to make a portable version. You can create a cover with some nu-

meric indicators alongside the lights.

Tilt switches are great, inexpensive tools for determining the orientation of some-
thing. Accelerometers are another type of tilt sensor, but they give out much more 
information. They are also significantly more expensive. If you’re just looking to see if 

something is up or down, a tilt sensor works great.

90

Project 08
Digital Hourglass

THE CODE

Declare a named constant

You’re  going  to  need  a  number  of  global  variables  in  your 

program to get this all working. To start, create a constant named 

switchPin. This will be the name of the pin your tilt switch is on.

Create a variable to hold the 

time

Create a variable of type unsigned long, This will hold the time 
an LED was last changed.

Name variables for the inputs 

Create a variable for the switch state, and another to hold the 

and outputs

previous  switch  state.  You’ll  use  these  two  to  compare  the 

switch’s position from one loop to the next.

Declare a variable describing 

the interval between events

Create a variable named led. This will be used to count which LED 

is the next one to be turned on. Start out with pin 2.

The  last  variable  you’re  creating  is  going  to  be  the  interval 
between each LED turning on. This will be be a long datatype. 
In 10 minutes (the time between each LED turning on) 600,000 

milliseconds  pass.  If  you  want  the  delay  between  lights  to  be 

longer or shorter, this is the number you change.

Set the direction of your 

digital pins

In  your  setup(),  you  need  to  declare  the  LED  pins  2-7  as 
outputs. A for() loop declares all six as OUTPUT with just 3 lines 
of code. You also need to declare switchPin as an INPUT.

Check the time since the 

program started running

When the loop() starts, you’re going to get the amount of time 
the Arduino has been running with millis() and store it in a 
local variable named currentTime.

Evaluate the amount of 

time that has passed since 

the previous loop()

Using an if() statement, you’ll check to see if enough time has 
passed to turn on an LED. Subtract the currentTime from the 
previousTime and check to see if it is greater than the interval 
variable. If 600,000 milliseconds have passed (10 minutes), you’ll 
set the variable previousTime to the value of currentTime.

91

1

const int switchPin = 8; 

2

unsigned long previousTime = 0; 

3

4

int switchState = 0; 

int prevSwitchState = 0; 

5

int led = 2; 

6

long interval = 600000; 

7

8

9

void setup() { 

  for(int x = 2;x<8;x++){

    pinMode(x, OUTPUT);

10

  } 

11

  pinMode(switchPin, INPUT);

12

}

13

void loop(){

14

  unsigned long currentTime = millis();

15

  if(currentTime - previousTime > interval) {

16

    previousTime = currentTime;

 
 
 
 
92

Project 08
Digital Hourglass

Turn on an LED, prepare for 

the next one

previousTime indicates the last time an LED was turned on. 
Once you’ve set previousTime, turn on the LED, and increment 
the  led  variable.  The  next  time  you  pass  the  time  interval,  the 

next LED will light up.

Check to see if all lights 

Add one more if statement in the program to check if the LED on 

are on

pin 7 is turned on. Don’t do anything with this yet. You’ll decide 

what happens at the end of the hour later.

Read the value of the switch

Now  that  you’ve  checked  the  time,  you’ll  want  to  see  if  the 

Reset the variables to their 

defaults if necessary

switch  has  changed  its  state.  Read  the  switch  value  into  the 
switchState variable.

With an if() statement, check to see if the switch is in a different 
position than it was previously. The != evaluation checks to see 
if  switchState  does  not  equal  prevSwitchState.  If  they 
are different, turn the LEDs off, return the led variable to the first 
pin, and reset the timer for the LEDs by setting previousTime 
to currentTime.

Set the current state to the 

previous state

At  the  end  of  the  loop(),  save  the  switch  state 
in 
prevSwitchState  ,  so  you  can  compare  it  to  the  value  you 
get for switchState in the next loop().

USE IT

Once  you’ve  programmed  the  board,  check  the  time  on  a 

clock. After 10 minutes have passed, the first LED should have 

turned  on.  Every  10  minutes  after  that,  a  new  light  will  turn 

on.  At  the  end  of  an  hour,  all  six  light  should  be  on.  When 

you flip the circuit over, and cause the tilt switch to change 

its state, the lights will turn off and the timer will start again.

93

17

    digitalWrite(led, HIGH);

18

    led++;

19

    if(led == 7){

20

    }

21

  }

22

  switchState = digitalRead(switchPin);

23

  if(switchState != prevSwitchState){

24

    for(int x = 2;x<8;x++){ 

25

      digitalWrite(x, LOW);

26

    } 

27

    led = 2;

28

    previousTime = currentTime;

29

  }

30

  prevSwitchState = switchState;

31

}

When the clock reaches one hour and all six lights are on, they just stay on. Can 

you think of a way to get your attention when the hour is up? Sound or flashing 

the lights are both good indicators. The led variable can be checked to see if all 

the lights are on, that’s a good place to check for grabbing someone’s attention. 

Unlike an hourglass filled with sand, the lights go either up or down depending 

on the orientation of the switch. Can you figure out how you can use the switch-

State variable to indicate what direction the lights should go?

To  measure  the  amount  of  time  between  events,  use  the 
millis()  function.  Because  the  numbers  it  generates  are 
larger than what you can store in an int, you should use the 
datatype unsigned long for storing its values.

 
 
09

H
C
T
I
W
S

9v
battery

P
A
N
S

Y
R
E
T
T
A
B

Y
R
E
T
T
A
B

R
O
T
O
M

R
O
T
S
I
S
E
R

M
H
O
L
I
K

0
1

7
0
0
4
N
1

E
D
O
I
D

T
E
F
S
O
M

INGREDIENTS

 
 
 
 
95

MOTORIZED 
PINWHEEL

GET THE ARDUINO TO SPIN A COLORFUL PINWHEEL 
USING A MOTOR

Discover: transistors, high current/voltage loads

Time: 45 MINUTES
Level:

Builds on projects: 1, 2, 3, 4

Controlling motors with an Arduino is more complicated than just controlling LEDs 

for a couple of reasons. First, motors require more current than the Arduino’s out-

put pins can supply, and second, motors can generate their own current through 

a process called induction, which can damage your circuit if you don’t plan for it. 

However, motors make it possible to move physical things, making your projects 

much more exciting. They’re worth the complications!

Moving things takes a lot of energy. Motors typically require more current than 

the Arduino can provide. Some motors require a higher voltage as well. To start 

moving, and when it has a heavy load attached, a motor will draw as much cur-

rent as it can. The Arduino can only provide 40 milliamps (mA) from its digital pins, 

much less than what most motors require to work.

Transistors are components that allow you to control high current and high voltage 
power sources from the low current output of the Arduino. There are many differ-

ent kinds, but they work on the same principle. You can think of transistors as digital 

switches. When you provide voltage to one of the transistor’s pins, called the gate, it 

closes the circuit between the other two pins, called the source and drain. This way, 

you can turn a higher current/voltage motor on and off with your Arduino. 

Motors are a type of inductive device. Induction is a process by which a changing 
electrical current in a wire can generate a changing magnetic field around the wire. 

When a motor is given electricity, a tightly wound coil inside the housing of copper 

creates a magnetic field. This field causes the shaft (the part that sticks out of the 

housing) to spin around. 

9v

battery

96

Project 09
Motorized Pinwheel

The reverse is also true: a motor can generate electricity when the shaft is spun 

around. Try attaching an LED to the two leads of your motor, then spin the shaft 

with your hand. If nothing happens, spin the shaft the other way. The LED should 

light up. You’ve just made a tiny generator out of your motor.

When you stop supplying energy to a motor, it will continue to spin, because it 

has inertia. When it’s spinning, it will generate a voltage in the opposite direction 

than the current you gave it. You saw this effect when you made your motor light 
up an LED. This reverse voltage, sometimes called back-voltage, can damage your 

transistor. For this reason, you should put a diode in parallel with the motor, so 
that the back voltage passes through the diode. The diode will only allow electric-
ity to flow in one direction, protecting the rest of the circuit. 

BUILD THE
CIRCUIT

Fig. 1

Fig. 2

97

❶

❷

❸

❹

❺

Connect  power  and  ground  to  your  breadboard  through  the 

Arduino.

Add a momentary switch to the board, connecting one side to 

power,  and  the  other  side  to  digital  pin  2  on  the  Arduino.  Add 

a 10-kilohm pull-down resistor to ground on the output pin of 

the switch.

When  using  circuits  with  different  voltages,  you  have  to  con-

nect their grounds together to provide a common ground. Plug 

the 9V battery snap into your breadboard. Connect ground from 

the battery to ground of your Arduino on the breadboard with a 

jumper, as shown in Fig. 1. Then attach the motor’s free lead to 

the 9V power.

Place the transistor on the board. Look at the component so that 

the metal tab is facing away from you. Connect digital pin 9 to 
the left pin on the transistor. This pin is called the gate. A change 
in voltage on the gate makes a connection between the other 

two  pins.  Connect  one  end  of  the  motor  to  the  middle  pin  of 
the transistor. This pin is called the drain. When the Arduino ac-
tivates the transistor by supplying voltage to the gate, this pin 
will be connected to the third pin, called the source. Connect the 
source to ground. 

Next,  connect  the  motor’s  voltage  supply  to  the  motor  and 

breadboard. The last component to be added is the diode. The 

diode  is  a  polarized  component,  it  can  go  only  one  way  in  the 

circuit. Notice that the diode has a stripe on one end. That end is 
the negative end, or cathode, of the diode. The other end is the 

positive end, or anode. Connect the anode of the diode to the 

ground of the motor and the cathode of the diode to the power 

of the motor. See Fig. 1. This may seem backwards, and in fact, 

it is. The diode will help prevent any back-voltage generated by 

the  motor  from  going  back  into  your  circuit.  Remember,  back 

voltage  will  flow  in  the  opposite  direction  of  the  voltage  that 

you supply.

LEDs are diodes too, in case you were wondering why their leads were also called 

anodes and cathodes. There are many kinds of diodes, but they all share one trait. 

They allow current to flow from anode to cathode, but not the reverse.

98

Project 09
Motorized Pinwheel

THE CODE

Name your constants and 

The  code  is  remarkably  similar  to  the  code  you  first  used  for 

variables

turning  on  an  LED.  First  of  all,  set  up  some  constants  for  the 
switch and motor pins and a variable named switchState to 
hold the value of the switch.

Declare the pins’ direction

In your setup(), declare the pinMode() of the motor (OUTPUT) 
and switch (INPUT) pins. 

Read the input, pull the 

output high if pressed

Your loop() is straightforward. Check the state of the switch-
Pin with digitalRead(). 

If  the  switch  is  pressed,  turn  the  motorPin  HIGH.  If  it  is  not 
pressed, turn the pin LOW. When HIGH, the transistor will acti-
vate, completing the motor circuit. When LOW, the motor will not 
spin.

Motors have an optimal operating voltage. They will work on as little as 50% of the 

rated voltage and as much as 50% over that number. If you vary the voltage, you 

can change the speed at which the motor rotates. Don’t vary it too much, though, 

or you will burn out your motor.

Motors require special consideration when being controlled by a microcontroller. 

Typically  the  microcontroller  cannot  provide  enough  current  and/or  voltage  to 

power a motor. Because of this, you use transistors to interface between the two. 

It’s also smart to use diodes to prevent damaging your circuit.

99

1

2

3

4

5

6

7

8

9

10

11

const int switchPin = 2; 

const int motorPin = 9; 

int switchState = 0; 

void setup() {

  pinMode(motorPin, OUTPUT); 

  pinMode(switchPin, INPUT); 

}

void loop(){

  switchState = digitalRead(switchPin);

  if (switchState == HIGH) { 

    digitalWrite(motorPin, HIGH); 

12

  } 

13

14

  else {

    digitalWrite(motorPin, LOW); 

15

  }

16

}

Transistors are solid state devices, they have no moving parts. Because of this, you 

can  switch  them  on  and  off  very  quickly.  Try  hooking  up  a  potentiometer  to  an 

analog input and use that to PWM the pin that controls the transistor. What do you 

think will happen to the motor’s speed if you vary the voltage it’s getting? Using 

your patterns on your spinner, can you get different visual effects?

 
100

Project 09
Motorized Pinwheel

USE IT

Assemble  the  CD  hub  as  shown  in  step  1,  and  attach  it  to  the 

motor as shown in step 2. Attach the die-cut paper pattern to a 

CD as shown in step 3. Snap the CD to the hub and secure with a 

drop of glue. Allow to try before proceeding. Plug a 9V battery to 

your battery snap. Power your Arduino over USB. When you press 

the switch on the breadboard, the motor will spin very rapidly.

❶

Snap part C into part B, and then gently press part D on to 

them.

❸

Place the paper disk on the CD and secure it using the flaps 

on the back.

101

With the motor spinning as fast as it does, you can probably make a pretty large 

spinner. Be careful that it doesn’t fly off and poke someone in the eye. Experiment 

with different patterns on the outside to create visual effects.

❷

Gently press the motor shaft into the hole in the back of 

part B.

❹

Attach the CD to the cross formed by parts B and D. Use a 

drop of glue to keep the CD from coming off.

10

H
C
T
I
W
S

9v
battery

P
A
N
S

Y
R
E
T
T
A
B

Y
R
E
T
T
A
B

R
O
T
O
M

R
O
T
S
I
S
E
R

M
H
O
L
I
K

0
1

E
G
D
I
R
B
-
H

R
E
T
E
M
O
I
T
N
E
T
O
P

INGREDIENTS

 
 
 
103

ZOETROPE

CREATE MOVING IMAGES IN FORWARD AND REVERSE WITH 
YOUR ARDUINO WHEN YOU CONNECT A MOTOR TO AN 
H-BRIDGE AND SOME STILL IMAGES

Discover: H-bridges

Time: 30 MINUTES
Level:

Builds on projects: 1, 2, 3, 4, 9

Before the internet, television, even before movies, some of the first moving images 

were created with a tool called a zoetrope. Zoetropes create the illusion of motion 

from a group of still images that have small changes in them. They are typically 

cylinders with slits cut in the side. When the cylinder spins and you look through 

the slits, your eyes perceive the still images on the other side of the wall to be ani-

mated. The slits help keep the images from becoming a big blur, and the speed at 

which the images appear provide cause the images to appear to move. Originally, 

these novelties were spun by hand, or with a cranking mechanism.

In this project, you’ll build your own zoetrope that animates a carnivorous plant. 

You’ll power the motion with a motor. To make this system even more advanced, 

you’ll add a switch that lets you control direction, another to turn it off and on, 
and a potentiometer to control the speed. 

In the Motorized Pinwheel Project you got a motor to spin in one direction. If you 

were to take power and ground on the motor and flip their orientation, the motor 

would spin in the opposite direction. It’s not very practical to do that everytime 

you want to spin something in a different direction, so you’ll be using a compo-

nent called an H-bridge to reverse the polarity of the motor.

H-bridges  are  a  type  of  component  known  as  integrated  circuits  (IC).  ICs  are 
components  that  hold  large  circuits  in  a  tiny  package.  These  can  help  simplify 

more complex circuits by placing them in an easily replaceable component. For 

example, the H-bridge you’re using in this example has a number of transistors 

built in. To build the circuit inside the H-bridge you would probably need another 

breadboard.

9v

battery

104

Project 10
Zoetrope

1
2
3
4
5
6
7
8

16
15
14
13
12
11
10
9

With  an  IC,  you  can  access  the  circuits  through  the  pins  that 

come out the sides. Different ICs have different numbers of pins, 

and not all of them are used in every circuit. It’s sometimes con-

venient to refer to the pins by number instead of function. When 

looking at an IC, the part with a dimple is referred to as the top . 

You can identify pin numbers by counting from the top-left in a 

Fig. 1

“U” direction like in Fig. 1.

BUILD THE
CIRCUIT

+ -

+ -

9V

Fig. 2

+ -

+ -

Fig. 3

105

❶

❷

❸

❹

❺

❻

❼

❽

Connect power and ground from one side of your breadboard 

to the Arduino.

Add 2 momentary switches to the breadboard, connecting one 

side  of  each  to  power.  Add  a  10Kohm  pull-down  resistor  in 

series with ground on the output pin of both switches.

The switch on pin 4 will control direction, the switch on pin 5 

will turn the motor on and off.

Connect the potentiometer to the breadboard. Wire 5V to one 

side and ground to the other. Attach the center pin to analog 

input 0 on the Arduino. This will be used to control the speed 

of the motor.

Place  the  H-bridge  on  your  breadboard  so  it  straddles  the 

center (see Fig. 2 for detail of placement). Connect pin 1 of the 

H-bridge to digital pin 9 on the Arduino. This is the enable pin 

on  the  H-bridge.  When  it  receives  5V,  it  turns  the  motor  on, 

when it receives 0V, it turns the motor off. You will use this pin 

to PWM the H-bridge, and adjust the speed of the motor.

Connect pin 2 on the H-bridge to digital pin 3 on the Arduino. 

Connect pin 7 to digital pin 2. These are the pins you will use 

to communicate with the H-bridge, telling it which direction to 
spin. If pin 3 is LOW and pin 2 is HIGH, the motor will spin in one 
direction. If pin 2 is LOW and pin 3 is HIGH, the motor will spin 
in the opposite direction. If both the pins are HIGH or LOW at 
the same time, the motor will stop spinning.

The H-bridge get its power from pin 16, plug that into 5V. Pins 4 

and 5 both go to ground.

Attach your motor to pins 3 and 6 on the H-bridge. These two 

pins will switch on and off depending on the signals you send 

to pins 2 and 7. 

Plug  the  battery  connector  (without  the  battery  attached!) 

to the other power rails on your breadboard. Connect ground 

from your Arduino to the battery’s ground. Connect pin 8 from 

the  H-bridge  to  the  battery  power.  This  is  the  pin  that  the 

H-bridge powers the motor from. Make sure you do not have 

your 9V and 5V power lines connected. They must be separate, 

only ground should be connected between the two.

106

Project 10
Zoetrope

THE CODE

Name your constants

Create constants for the output and input pins.

Create variables for remem-

Use variables to hold the values from your inputs. You’ll be doing 

bering program state

state change detection for both switches, comparing the state 

from one loop to the next, similar to the Hourglass Project. So, 

in addition to storing the current state, you’ll need to record the 

previous state of each switch.

Create variables for motor 

control

motorDirection keeps track of which direction the motor is 
spinning, and motorPower keeps track of whether the motor is 
spinning or not.

Declare the digital pins as 

In setup(), set the direction of each input and output pin.

inputs and outputs

Turn the motor off

Turn the enable pin LOW to start, so the motor isn’t spinning right 
away.

Read sensor information

In your loop(), read the state of the On/Off switch and store it 
in the onOffSwitchState variable.

107

1

2

3

4

5

6

7

8

9

const int controlPin1 = 2;

const int controlPin2 = 3;

const int enablePin = 9;

const int directionSwitchPin = 4;

const int onOffSwitchStateSwitchPin = 5;

const int potPin = A0;

int onOffSwitchState = 0;

int previousOnOffSwitchState = 0;

int directionSwitchState = 0;

10

int previousDirectionSwitchState = 0;

11

int motorEnabled = 0;

12

int motorSpeed = 0;

13

int motorDirection = 1;

14

void setup(){

15

  pinMode(directionSwitchPin, INPUT);

16

  pinMode(onOffSwitchStateSwitchPin, INPUT);

17

  pinMode(controlPin1, OUTPUT);

18

  pinMode(controlPin2, OUTPUT);

19

  pinMode(enablePin, OUTPUT);

20

  digitalWrite(enablePin, LOW);

21

}

22

void loop(){ 

23

  onOffSwitchState = 

    digitalRead(onOffSwitchStateSwitchPin);

24

  delay(1);

25

  directionSwitchState = 

    digitalRead(directionSwitchPin);

26

  motorSpeed = analogRead(potPin)/4;

108

Project 10
Zoetrope

Check if on/off sensor has 

changed

If there is a difference between the current switch state and the 
previous, and the switch is currently HIGH, set the motorPower 
variable to 1. If it is LOW, set the variable to 0. 
Read the values of the direction switch and potentiometer. Store 

the values in their respective variables.

Check to see if the direction 

Check  to  see  if  the  direction  switch  is  currently  in  a  different 

has changed

position than it was previously.If it is different, change the motor 

direction variable. There are only 2 ways for the motor to spin, 

so you’ll want to alternate the variable between two states. One 

way to accomplish this is by  using the inversion operator like so: 
motorDirection =!motorDirection.

Change the pins to turn 

The  motorDirection  variable  determines  which  direction  the 

the motor in the proper 

direction

motor  is  turning.  To  set  the  direction,  you  set  the  control  pins 
setting  one  HIGH  and  the  other  LOW.  When  motorDirection 
changes, reverse the states of the control pins.

If  the  direction  switch  gets  pressed,  you’ll  want  to  spin  the 

motor  in  the  other  direction  by  reversing  the  state  of  the 
controlPins.

PWM the motor if it is 

enabled

If the motorEnabled variable is 1, set the speed of the motor using 
analogWrite() to PWM the enable pin. If motorEnabled is 
0, then turn the motor off by setting the analogWrite value 
to 0.

Save the current states for 

the next loop()

Before exiting the loop(), save the current state of the switches 
as the previous state for the next run through the program.

109

27

  if(onOffSwitchState != previousOnOffSwitchState){

28

    if(onOffSwitchState == HIGH){

29

      motorEnabled = !motorEnabled;

30

    } 

31

  }

32

   if (directionSwitchState != 

   previousDirectionSwitchState) {

33

   if (directionSwitchState == HIGH) { 

34

     motorDirection = !motorDirection;

35

    }

36

  }

37

  if (motorDirection == 1) {

38

    digitalWrite(controlPin1, HIGH);

39

    digitalWrite(controlPin2, LOW);

40

  }

41

  else {

42

    digitalWrite(controlPin1, LOW);

43

    digitalWrite(controlPin2, HIGH);

44

  } 

45

  if (motorEnabled == 1) { 

46

    analogWrite(enablePin, motorSpeed);

47

  }

48

  else {

49

    analogWrite(enablePin, 0);

50

  }

51

  previousDirectionSwitchState = 

    directionSwitchState;

52

  previousOnOffSwitchState = onOffSwitchState;

53

}

110

Project 10
Zoetrope

USE IT

Plug your Arduino into your computer. Attach the battery to the 

connector. When you press the On/Off switch, the motor should 

start spinning. If you turn the potentiometer, it should speed up 

and  slow  down.  Pressing  the  On/Off  button  another  time  will 

stop the motor. Try pressing the direction button and verify the 

Once you’ve verified that the circuit 

motor spins both ways. Also, if you turn the knob on the pot, you 

works as expected, disconnect the 

should see the motor speed up or slow down depending on the 

battery and USB from the circuit.

value it is sending.

❶

❷

Secure the CD onto the wooden base. Add a drop of glue to 

Use the tabs to close the cutout, forming a circle.

make sure it doesn’t spin loose when the motor starts.

111

In order to build your zoetrope, you must take the pinwheel you used in Project 9 

and the cutout with the vertical slits that is included in your kit. Once the CD is se-

curely attached to the shaft of the motor, plug everything back in. Hold your project 

up, so you can look through the slits (but make sure the CD is secured to the motor, 

and don’t get too close to it). You should see the sequence of still images “move”! 

If it is going too fast or too slow, turn the knob of the potentiometer to adjust the 

speed of the animation.

Try pressing the direction switch to see what the animation looks like when played 

backwards. The zoetrope and images provided in the kit are only your starting point: 

try experimenting with your own animations, using the cutout as a reference.

To do this, start with a basic image. Identify one fixed point in it, and make small 

changes to the rest in each frame. Try to gradually return to the original image so 

that you can play the animation in a continuous loop.

❶

❶

Insert the four tabs into the base of the zoetrope.

Insert the strip of paper with the images inside the 

zoetrope.

112

Project 10
Zoetrope

Zoetropes work because of a phenomena called “persistence of vision”, sometimes 

abbreviated to POV. POV describes the illusion of motion that is created when our 

eyes  observe  still  images  with  minor  variations  in  rapid  succession.  If  you  search 

online for “POV display”, you’ll find many projects made by people that leverage this 

effect, often with LEDs and an Arduino. 

Make a base to support the motor. A small cardboard box with a hole cut in it could 

work as a base, leaving your hands free to play with the switches and knob. This will 

make it easier to show off your work to everyone.

With a little work, you can get your zoetrope working in low light situations as well. 

Hook up an LED and resistor to one of your free digital output pins. Also add a sec-

ond potentiometer, and connect it to an analog input. Position the light so it shines 

on the images. Using the analog input to time the flashes of the LED, try and time it 

so the light flashes when the slit is in front of your eyes. This could take some fiddling 

with the knobs, but the resulting effect is really spectacular!

11

R
O
T
S
I
S
E
R

M
H
O
L
I
K

0
1

R
O
T
S
I
S
E
R

M
H
O

0
2
2

R
E
T
E
M
O
I
T
N
E
T
O
P

H
C
T
I
W
S

INGREDIENTS

N
E
E
R
C
S

D
C
L

 
 
 
 
 
115

CRYSTAL 
BALL

CREATE A CRYSTAL BALL TO TELL YOUR FUTURE

Discover: LCD displays, switch/case statements, random()

Time: 1 HOUR
Level:

Builds on projects: 1, 2, 3

Crystal balls can help “predict” the future. You ask a question to the all-knowing 

ball, and turn it over to reveal an answer. The answers will be predetermined, but 

you can write in anything you like. You’ll use your Arduino to choose from a total 

of 8 responses. The tilt switch in your kit will help replicate the motion of shaking 

the ball for answers.

The LCD can be used to display alphanumeric characters. The one in your kit has 

16 columns and 2 rows, for a total of 32 characters. There are a large number of 

connections  on  the  board.  These  pins  are  used  for  power  and  communication, 

so it knows what to write on screen, but you won’t need to connect all of them.

See Fig. 1 for the pins you need to connect. 

6
1

5
1

4
1

3
1

2
1

1
1

0 9 8 7 6 5 4 3 2 1
1

-
D
E
L

+
D
E
L

7
D

6
D

5
D

4
D

3
D

2
D

1
D

0 E
D

S
R

0
V

W
/
R

c
c
V

s
s
V

The pins on the LCD screen that are used in the 

project and labels.

Fig. 1

116

Project 11
Crystal Ball

BUILD THE
CIRCUIT

Fig. 2

Fig. 3

+ -

+ -

+ -

+ -

In this schematic the LCD pins arrangement does not match the physical order depicted in Fig. 2.

In a schematic, the pins are rearranged by logical grouping to make the schematic as clear as pos-

sible. This is a little confusing to newcomers until you get used to it.

117

❶
❷

❸

❹

❺

❻

❼

The circuit is not overly complex, but there are a lot of wires. 

Pay  attention  when  wiring  everything  up  to  make  sure  it’s 

correct.

Connect power and ground to one side of your breadboard.

Place the tilt switch on the breadboard and attach one lead to 
5V. Attach the other side to ground through a 10-kilohm resis-

tor, and to your Arduino’s pin 6. You’re wiring this as a digital 

input, just as you’ve done in several other projects.

The register select (RS) pin controls where the characters will 
appear  on  screen.  The  read/write  pin  (R/W)  puts  the  screen 
in  read  or  write  mode.  You’ll  be  using  the  write  mode  in  this 
project. The enable (EN) tells the LCD that it will be receiving 
a command. The data pins (D0-D7) are used to send charac-
ter data to the screen. You’ll only be using 4 of these (D4-D7). 
Finally,  there’s  a  connection  for  adjusting  the  contrast  of  the 

display. You’ll use a potentiometer to control this.

The LiquidCrystal library that comes with the Arduino software 

handles all the writing to these pins, and simplifies the process 

of writing software to display characters.
The  two  outside  pins  of  the  LCD  (Vss  and  LED-)  need  to  be 
connected to ground. Also, connect the R/W pin to ground. This 
places the screen in write mode. The LCD power supply (Vcc) 
should connect directly to 5V. The LED+ pin on the screen con-

nects to power through a 220-ohm resistor.

Connect: Arduino Digital pin 2 to LCD D7, Arduino Digital pin 3 
to LCD D6, Arduino Digital pin 4 to LCD D5, Arduino Digital pin 
5 to LCD D4. These are the data pins that tell the screen what 
character to display. 

Connect EN on the screen to pin 11 on your Arduino. RS on the 
LCD connects to pin 12. This pin enables writing to the LCD.

Place  the  potentiometer  on  the  breadboard,  connecting  one 

end  pin  to  power  and  the  other  to  ground.  The  center  pin 
should connect to V0 on the LCD. This will allow you to change 
the contrast of the screen. 

118

Project 11
Crystal Ball

Set up the LiquidCrystal 

library

First, you’ll need to import the LiquidCrystal library.
Next, you’ll initialize the library, somewhat similar to the way you 

did with the Servo library, telling it what pins it will be using to 

communicate.

Now  that  you’ve  set  up  the  library,  it’s  time  to  create  some 

variables  and  constants.  Create  a  constant  to  hold  the  pin  of 

the switch pin, a variable for the current state of the switch, a 

variable  for  the  previous  state  of  the  switch,  and  one  more  to 

choose which reply the screen will show.

Print your first line

Set  up  the  switch  pin  as  an  input  with  pinMode()  in  your 
setup(). Start the LCD library, and tell it how large the screen is.

Move the cursor

Choose a random anwser

Now it’s time to write a small introductory screen welcoming you 
to the 8-ball. The print() function writes to the LCD screen.
You’re going to write the words “Ask the” on the top line of the 

screen. The cursor is automatically at the beginning of the top line.

In order to write to the next line, you’ll have to tell the screen 

where to move the cursor. The coordinates of the first column on 

the second line are 0,1 (recall that computers are zero indexed. 
0,0 is the first column of the first row). Use the function lcd.
setCursor() to move the cursor to the proper place, and tell 
it to write “Crystal ball!”.

Now, when you start the program, it will say “Ask the Crystal ball!” 

on your screen.
In the loop(), you’re going to check the switch first, and put the 
value in the switchState variable.

Use an if() statement to determine if the switch is in a different 
position than it was previously. If it is different than it was before, 

and it is currently LOW, then it’s time to choose a random reply. 
The  random()  function  returns  a  number  based  on  the 
argument  you  provide  it.  To  start,  you’ll  have  a  total  number 

of  8  different  responses  for  the  ball.  Whenever  the  statement 

random(8) is called, it will give a number between 0-7. Store that 

number in your reply variable.

119

LCD library reference

arduino.cc/lcdlibrary

1

2

3

4

5

6

7

8

9

#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

const int switchPin = 6;

int switchState = 0;

int prevSwitchState = 0;

int reply;

void setup() { 

  lcd.begin(16, 2);

  pinMode(switchPin,INPUT);

10

  lcd.print(“Ask the”);

11

  lcd.setCursor(0, 1);

12

  lcd.print(“Crystal Ball!”);

13

}

14

void loop() {

15

  switchState = digitalRead(switchPin);

16

  if (switchState != prevSwitchState) {

17

    if (switchState == LOW) { 

18

      reply = random(8);

Random reference

arduino.cc/random

 
120

Project 11
Crystal Ball

Predict the future

Clear  the  screen  with  the  function  lcd.clear().  This  also 
moves  the  cursor  back  to  location  0,0;  the  first  column  in  the 

first row of the LCD. Print out the line “ The ball says:” and move 

the cursor for the output.

The  switch()  statement  executes  different  pieces  of  code 
depending on the value you give it. Each of these different pieces 
of  code  is  called  a  case.  switch()  checks  the  value  of  the 
variable  reply;  whatever  value  reply  holds  will  determine  what 

named case statement is executed. 

Inside the case statements, the code will be the same, but the 

messages  will  be  different.  For  example,  in  case  0  the  code 
says lcd.print (“Yes”). After the lcd.print() function, 
there’s another command: break. It tells the Arduino where the 
end of the case is. When it hits break, it skips to the end of the 
switch statement. You’ll be creating a total of 8 case statements 

to  start  out.  Four  of  the  responses  will  be  positive,  2  will  be 

negative, and the final 2 will ask you to try again.

The  last  thing  to  do  in  your  loop()  is  to  assign  switchState’s 
value  to  the  variable  prevSwitchState.  This  enables  you  to 
track changes in the switch the next time the loop runs.

121

Switch Case reference
arduino.cc/switchcase

19

      lcd.clear();

20

      lcd.setCursor(0, 0);

21

      lcd.print(“The ball says:”);

22

      lcd.setCursor(0, 1);

23

      switch(reply){

24

        case 0:

25

        lcd.print(“Yes”);

26

        break;

27

        case 1:

28

        lcd.print(“Most likely”);

29

        break;

30

        case 2:

31

        lcd.print(“Certainly”);

32

        break;

33

        case 3:

34

        lcd.print(“Outlook good”);

35

        break;

36

        case 4:

37

        lcd.print(“Unsure”);

38

        break; 

39

        case 5:

40

        lcd.print(“Ask again”);

41

        break; 

42

        case 6:

43

        lcd.print(“Doubtful”);

44

        break; 

45

        case 7:

46

        lcd.print(“No”);

47

        break;

48

      }

49

    }

50

  }

51

  prevSwitchState = switchState;

52

}

 
122

Project 11
Crystal Ball

USE IT

To use the magic ball, power the Arduino. Check the screen to 

make sure it says “Ask the Crystal ball!” If you can’t see the char-

acters, try turning the potentiometer. It will adjust the contrast 

of the screen.

Ask a question of your crystal ball, and try tilting the switch up-

side  down  and  back  again.  You  should  get  an  answer  to  your 

question. If the answer doesn’t suit you, ask again.

Try adding your own sayings to the print() statements, but be mindful of the 
fact that there are only 16 characters to use per line. You can also try adding more 

responses. Make sure when you add additional switch cases, you adjust the number 

of options that will randomly populate the reply variable.

LCDs  work  by  changing  the  electrical  properties  of  a  liquid  sandwiched  between 

polarized glass. The glass only allows certain kinds of light to pass through. When 

the liquid between the glass is charged, it starts to form into a semi-solid state. This 

new state runs in a different direction than the polarized glass, blocking light from 

passing through, thus creating the characters you see on the screen.

The  functions  covered  here  for  changing  the  LCD  screen’s  text  are  fairly  simple. 

Once you have a handle on how it works, look at some of the other functions the 

library has. Try getting text to scroll, or continually update. To find out more about 
how the LiquidCrystal library works, visit: arduino.cc/lcd

An LCD display enables you to show text on a screen, using 
the  LiquidCrystal  library.  With  a  switch...case  statements 
control  the  flow  of  programs  by  comparing  a  variable  to 
specified values.

12

R
O
T
S
I
S
E
R

M
H
O

O
L
I
K

0
1

R
O
T
S
I
S
E
R

M
H
O

0
2
2

R
O
T
S
I
S
E
R

M
H
O
G
E
M

1

R
O
T
I
C
A
P
A
C

F
u
0
0
1

H
C
T
I
W
S

D
E
L

MALE HEADER PIN (3 pins)

INGREDIENTS

R
O
T
O
M

O
V
R
E
S

O
Z
E
I
P

 
 
 
 
 
 
 
 
 
125

KNOCK 
LOCK

MAKE YOUR OWN SECRET LOCKING MECHANISM TO KEEP 
UNWANTED GUESTS OUT OF YOUR SPACE!

Discover: input with a piezo, writing your own functions

Time: 1 HOUR
Level:

Builds on projects: 1, 2, 3, 4, 5

The piezo you used for playing back sounds in the theremin and keyboard pro-

jects can also be used as an input device. When plugged into 5V, the sensor can 

detect vibrations that can be read by the Arduino’s analog inputs. You’ll need to 

plug in a high value resistor (like 1-megohm) as the reference to ground for this 

to work well. 

When the piezo is pressed flat against a solid surface that can vibrate, like a wood-

en table top, your Arduino can sense how intense a knock is. Using this informa-

tion you can check to see if a number of knocks fall in an acceptable range. In code 

you can track the number of knocks and see if they match your settings.

A switch will let you lock the motor in place. Some LEDs will give you status: a red 
LED will indicate the box is locked, a green LED will indicate the box is unlocked, 

and a yellow LED lets you know if a valid knock has been received.

You’ll also be writing your own function that will let you know if a knock is too loud 

or too soft. Writing your own function helps save time programming by reusing 

code  instead  of  writing  it  out  many  times.  Functions  can  take  arguments  and 

return values. In this case, you’ll give a function the volume of the knock. If it is in 

the right range, you’ll increment a variable.

It’s possible to build the circuit by itself, but it’s much more fun if you use this as 

a tool to lock something. If you have a wooden or a cardboard box you can cut 

holes into, use the servo motor to open and close a latch, keeping people from 

getting at your stuff.

+ -

+ -

+ -

+ -

126

Project 12
Knock Lock

BUILD THE
CIRCUIT

Fig. 1

Fig. 2

127

❶

❷

❸

❹

There  are  a  lot  of  connections  on  the  board,  be  sure  to  keep 

track of how things are wired up.

Connect  power  and  ground  to  both  sides  of  the  breadboard. 

Place  the  pushbutton  on  the  breadboard  and  connect  one 

end to 5V. On the other side of the switch, connect to ground 

through  a  10-kilohm  resistor.  Connect  this  junction  to  digital 
pin 2 on the Arduino.

Attach the wires from the piezo to the breadboard. Attach one 

wire to power. If your piezo has a red wire or one marked with 

a “+”, that is the one to connect to power. If your piezo doesn’t 

indicate  polarity,  then  you  can  hook  it  up  either  way.  Wire 

the  other  end  of  the  piezo  to  Analog  Pin  0  on  your  Arduino. 

Place a 1-megohm resistor between the ground and the other 

wire. Lower resistor values will make the piezo less sensitive to 

vibrations.

Wire  up  the  LEDs,  connecting  the  cathodes  (short  leg)  to 

ground, and placing a 220-ohm resistor in series with the an-

odes.  Through  their  respective  resistors,  connect  the  yellow 

LED to Arduino digital pin 3, the green LED to digital pin 4, and 

the red LED to digital pin 5.

Insert  the  male  headers  into  the  female  socket  on  the  servo 

motor (see Fig.3). Connect the red wire to power, and the black 

wire  to  ground.  Place  a  100uF  electrolytic  capacitor  across 

power and ground to smooth out any irregularities in voltage, 

making sure you have the capacitor’s polarity correct. Connect 
the servo’s data wire to pin 9 on your Arduino.

Your servo motor comes with 

female connectors, so you’ll 

need to add header pins to 

connect it to the breadboard.

Fig. 3

128

Project 12
Knock Lock

THE CODE

Servo library

Just as in the earlier Mood  Cue  Project, you’ll need to import the 
Servo library and create an instance to use the motor.

Useful constants

Create constants to name your inputs and outputs.

Variables to hold switch and 

Create variables to hold the values from your switch and piezo.

piezo values

Knock tresholds

Set  up  some  constants  to  use  as  thresholds  for  the  knock 

maximum and minimum levels.

Variables for lock state and 

number of knocks

The locked variable will let you know if the lock is enganged or 
not. A boolean is a data type that can only be true (1) or false 
(0). You should start with the mechanism unlocked.

The last global variable will hold the number of valid knocks you 

have received.

Setting the direction of the 

digital pins and initializing 

servo object and serial port

In your setup(), attach the servo to pin 9.
Set the LED pins as outputs and the switch pins as inputs.

Unlock

Initialize  serial  communication  with  the  computer  so  you  can 

monitor the knock volume, what the current state of the lock is, 

and how many more knocks you have to go.

Turn on the green LED, move the servo to the unlocked position, 

and print the current status to the serial monitor indicating the 

circuit is in the unlocked position.

Checking the switch

In the loop(), you’ll first check to see if the box is locked or not. 
This will determine what happens in the rest of the program. If it 

is locked, read the switch value.

129

1

2

3

4

5

6

7

8

9

#include <Servo.h>

Servo myServo;

const int piezo = A0; 

const int switchPin = 2; 

const int yellowLed = 3; 

const int greenLed = 4; 

const int redLed = 5; 

int knockVal; 

int switchVal; 

10

const int quietKnock = 10;

11

const int loudKnock = 100;

12

boolean locked = false;

13

int numberOfKnocks = 0;

14

void setup(){ 

15

  myServo.attach(9);

16

  pinMode(yellowLed, OUTPUT);

17

  pinMode(redLed, OUTPUT);

18

  pinMode(greenLed, OUTPUT);

19

  pinMode(switchPin, INPUT);

20

  Serial.begin(9600);

21

  digitalWrite(greenLed, HIGH);

22

  myServo.write(0); 

23

  Serial.println(“The box is unlocked!”); 

24

}

25

void loop(){

26

  if(locked == false){ 

27

    switchVal = digitalRead(switchPin);

130

Project 12
Knock Lock

Lock

If  the  switch  is  closed  (you’re  pressing  it),  change  the  locked 

variable  to  true,  indicating  the  lock  is  engaged.  Turn  the  green 

LED off, and the red LED on. If you don’t have the serial monitor 

on, this is helpful visual feedback to let you know the status of 

the lock. Move the servo into the lock position, and print out a 

message to the serial monitor indicating the box is now locked. 

Add a delay so the lock has plenty of time to move into place.

Checking the knock sensor

If the locked variable is true, and the lock is engaged, read the 
value of the vibration of the piezo and store it in knockVal.

Counting only valid knocks

The next statement checks to see if you have fewer than three 

valid knocks, and there is some vibration on the sensor. If these 

are both true, check to see if this current knock is valid or not and 
increment  the  numberOfKnocks  variable.  This  is  where  you’ll 
call your custom function checkForKnocks(). You’ll write the 
function once you’re finished with the loop(), but you already 
know you’re going to be asking it if this is a valid knock, so pass 

the knockVal along as an argument. After checking your function, 

print out the number of knock still needed.

Unlock

Check  to  see  if  you  have  three  or  more  valid  knocks.  If  this  is 

true, change the locked variable to false, and move the servo to 

the unlocked position. Wait for a few milliseconds to let it start 

moving, and change the status of the green and red LEDs. Print 

out a status message to the serial monitor, indicating the box is 

unlocked.

Close  up  the  else  statement  and  the  loop()  with  a  pair  of 
curly brackets.

Defining a function to check 

knock validity

Now  it’s  time  to  write  the  function  checkForKnock().  When 
you’re writing functions of your own, you need to indicate if it is going 

to return a value or not. If it is not going to return a value, you declare 
it as type void, similar to the loop() and setup() functions. If it 
is going to return a value, you must declare what kind (int, long, 
float, etc.). In this case, you’re checking to see if a knock is valid 
(true) or not (false). Declare the function as type boolean.

131

28

    if(switchVal == HIGH){ 

29

      locked = true; 

30

      digitalWrite(greenLed,LOW); 

31

      digitalWrite(redLed,HIGH); 

32

      myServo.write(90); 

33

      Serial.println(“The box is locked!”); 

34

      delay (1000);

35

    }

36

  }

37

  if(locked == true){

38

    knockVal = analogRead(piezo); 

39

    if(numberOfKnocks < 3 && knockVal > 0){ 

40

      if(checkForKnock(knockVal) == true){

41

        numberOfKnocks++;

42

      } 

43

      Serial.print(3-numberOfKnocks); 

44

      Serial.println(“ more knocks to go”); 

45

    }

46

    if(numberOfKnocks >= 3){ 

47

      locked = false; 

48

      myServo.write(0); 

49

      delay(20); 

50

      digitalWrite(greenLed,HIGH); 

51

      digitalWrite(redLed,LOW); 

52

      Serial.println(“The box is unlocked!”); 

53

    }

54

  }

55

}

56

boolean checkForKnock(int value){

132

Project 12
Knock Lock

Check validity of knock

This particular function will be checking a number (your variable 
knockVal) to see if it is valid or not. To pass this variable along 
to the function, you create a named parameter when you declare 

the function.

In your function, whenever you refer to value it will use whatever 
number it receives as an argument in the main program. At this 
point value will be set to whatever knockVal is.
Check to see if value is greater than your quiet knock, and less 
than your loud knock.

Indicating knock is valid

If the value falls between those two values it’s a valid knock. Blink 

the yellow LED once and print the value of the knock to the serial 

monitor.

Function returns true

To  let  the  main  program  know  what  the  outcome  of  the 
comparison  is,  you  use  the  command  return.  You  use  the 
return command, which also terminates the function: once it 
executes, you return to the main program.

Indicating invalid knock; 

function returns false

If value is either too quiet or too loud, print it out to the serial 
monitor and return false.

Close up your function with one more bracket .

USE IT

When  you  first  plug  in  the  circuit  to  your  Arduino,  open  the 

serial monitor. You should see the green LED turn on, and the 

servo will move to the unlocked position. 

The  serial  monitor  should  print  out  “The  box  is  unlocked!”. 

You’ll probably hear the piezo make a small “click” when it first 

gets power.

Try knocking soft and hard to see what sort of intensity knock 

triggers your function. You’ll know it’s working when the yel-

133

57

  if(value > quietKnock && value < loudKnock){ 

58

    digitalWrite(yellowLed, HIGH);

59

    delay(50);

60

    digitalWrite(yellowLed, LOW);

61

    Serial.print(“Valid knock of value “); 

62

    Serial.println(value);

63

    return true;

64

  }

65

  else { 

66

    Serial.print(“Bad knock value “); 

67

    Serial.println(value); 

68

    return false;

69

  }

70

}

low  LED  flashes  and  the  serial  monitor  tells  you  you  have  a 

valid knock with its value. It will also let you know the number 

of knocks you have to go before unlocking the box.

Once you’ve reached the right number of knocks, the red light 

will turn off, the green light will turn on, the servo will move 

90 degrees, and the serial monitor will let you know the lock 

is disengaged.

134

Project 12
Knock Lock

The values for your ideal knock may vary from the ones in the example. This de-

pends  on  a  number  of  different  variables,  like  the  type  of  surface  the  sensor  is 

attached to and how sturdily it is fixed on there. Using the serial monitor and the 

AnalogInSerialOut example in the Arduino IDE, find an appropriate knock value for 

your setup. You can find a detailed explanation of that example here: 

arduino.cc/analogtoserial

If you move the project into a box, you’ll need to make holes for the LEDs and 

the switch. You’ll also need to make a latch for the servo motor to spin into. It will 

probably also be helpful to have a hole to run your USB cable through to find out 

how sensitive your new environment is to knocks.

You may need to rearrange your breadboard and Arduino, or solder the LEDs and 

switch to make them accessible to the exterior of your enclosure. Soldering is a 

process of joining two or more metal components together with an adhesive that 

is melted between the joint. If you’ve never soldered before, ask someone who has 

experience to help you out, or try practicing on some scrap wire before attempting 

with another device in this project. When you solder something, it’s meant to be a 

permanent connection, so be sure it’s something that’s ok to hack. 
See arduino.cc/soldering for a good explanation of how to solder.

❶

Cut 2 holes in your box: one on the side, and a second 

through the cover flap. Place the servo in the box so that 

the arm can move in and out of the holes when closed.

135

Writing your own functions not only allows you to control the flow of your code more 

easily, it also helps keep it readable as your projects become larger and larger. Over 

time, as you write more code, you may find you have a large number of functions you 

can re-use in different projects, making the process quicker and unique to your style 

of programming.

This example simply counts the right number of knocks, no matter how long it takes. 
You can start to make a more complex example by creating a timer with millis(). 
Use the timer to identify if the knocks happen in a specific period of time. Look back 

at the Digital Hourglass Project for an example of how a timer works. You aren’t lim-

ited to simply finding knocks in a specific range. You can look for complex patterns of 

knocks based on the amount of vibration and timing together. There are a number 

of examples online that talk about how to do this, search for “Arduino knock lock” to 

discover more examples of this type of project. 

Piezo  elements  can  be  used  as  inputs  when  wired  up  as 
voltage  dividers  with  a  high  value  resistor.  Designing  a 
function is an easy way to write code that can be reused 
for specific tasks. 

❷

Secure the servo in place with some tape, again making sure 

the arm can easily rotate through the slot you made.

13

R
O
T
S
I
S
E
R

M
H
O

0
2
2

R
O
T
S
I
S
E
R

M
H
O
G
E
M

1

L
I
O
F

L
A
T
E
M

D
E
L

INGREDIENTS

 
 
 
 
 
 
137

TOUCHY-FEELY 
LAMP

YOU WILL CREATE A LAMP THAT TURNS A LIGHT ON AND 
OFF WHEN YOU TOUCH A PIECE OF CONDUCTIVE MATERIAL

Discover: installing third party libraries, creating a touch sensor

Time: 45 MINUTES
Level:

Builds on projects: 1, 2, 5

You’ll  be  using  the  CapacitiveSensor  library  by  Paul  Badger  for  this  project.  This 

library allows you to measure the capacitance of your body. 

Capacitance  is  a  measure  of  how  much  electrical  charge  something  can  store. 

The library checks two pins on your Arduino (one is a sender, the other a receiver), 

and measures the time it takes for them to have the same state. These pins will 

be connected to a metal object like aluminum foil. As you get closer to the object, 

your body will absorb some of the charge, causing it to take longer for the two 

pins to be the same.

Preparing the library

The most recent version of the CapacitiveSensor library is here: 
arduino.cc/capacitive.  Download  the  file  to  your  computer 
and unzip it. Open your Arduino sketch folder (it will be in your 

“Documents” folder by default). In the folder, create a new di-

rectory named “libraries”. Place the CapacitiveSensor folder you 

unzipped in this folder and restart the Arduino software.

Click the File>Examples menu in the Arduino software, and you’ll 

see  a  new  entry  for  “CapacitiveSensor”.  The  library  you  added 

included an example project. Open the CapacitiveSensorSketch 

example and compile it. If you don’t get any errors, you’ll know 

you installed it correctly. 

For more information on libraries:

arduino.cc/en/Reference/Libraries

138

Project 13
Touchy-feely Lamp

BUILD THE
CIRCUIT

Fig. 1

Fig. 2

139

❶

❷

Connect an LED to pin 12, and connect the cathode to ground 

through a 220-ohm resistor as shown. 

Connect  digital  pins  2  and  4  to  your  breadboard.  Connect  the 

two pins with a 1-megahom resistor. In the same row as pin 2, 

insert a long wire (8-10cm at least) that extends away from the 

breadboard,  not  connected  to  anything  on  the  other  end.  This 

will become your touch sensor.

There’s no need to supply 5V to your 
breadboard in this project. Digital pin 
4 supplies the current to the sensor.

Just like with other LED projects, diffusing the light will make this much more at-

tractive. Ping pong balls, little lampshades from paper or plastic, whatever you have 

handy will work.

You can hide the sensor behind something solid and it will still work. Capacitance 

can be measured through non-conductive materials like wood and plastic. Increas-

ing the surface area of the sensor with a larger conductive surface will make it more 

sensitve;  try  connecting  aluminum  foil,  or  copper  mesh  to  your  wire.  You  could 

make a base for the lamp out of cardboard, thin wood, or cloth, and line the inner 

surface with foil attached to your sensor wire. The whole base of the lamp would 

then act as a touch sensor. Update the threshold variable in the code when you 

make these changes to ensure that you’re still getting a reliable result.

140

Project 13
Touchy-feely Lamp

THE CODE

Import the CapacitiveSensor 

At the beginning of your program, include the CapacitiveSensor 

library

library. You include it the same way you would a native Arduino 
library like the Servo library in the earlier projects.
Create a named instance of the library. When you use this library, 

you tell the instance what pins it will be using to send and receive 

information.  In  this  case,  pin  4  sends  to  the  conductive  sensor 

material through the resistor, and pin 2 is the sense pin.

Set up the threshold 

Set  up  a  variable  for  the  sensing  threshold  at  which  the  lamp 

will turn on. You’ll change this number after you test the sensor’s 

Sensing touch

functionality.

Then define the pin your LED will be on.

In the setup() function, open a Serial connection at 9600 bps. 
You’ll use this to see the values the sensor reads. Also, make your 
ledPin an OUTPUT.

In the loop() function, create a variable of type long to hold the 
sensor’s value. The library returns the sensor value using a com-
mand  called  CapacitiveSensor()  that  takes  an  argument 
identifying the number of samples you want to read. If you read 

only a few samples, it’s possible you’ll see a lot of variation in the 

sensor. If you take too many samples, you could introduce a lag 

as it reads the sensor multiple times. 30 samples is a good start-

ing value. Print the sensor value to the serial monitor.

Lamp control

With  an  if()...else  statement,  check  to  see  if  the  sensor 
value is higher than the threshold. If it is, turn the LED on. If it is 

not, turn it off.

Then add a small delay() before ending the loop().

141

1

2

3

4

5

6

7

8

#include <CapacitiveSensor.h>

CapacitiveSensor capSensor = CapacitiveSensor(4,2);

int threshold = 1000;

const int ledPin = 12;

void setup() {

  Serial.begin(9600);

  pinMode(ledPin, OUTPUT);

}

9

void loop() {

10

  long sensorValue = capSensor.capacitiveSensor(30);

11

  Serial.println(sensorValue);

12

  if(sensorValue > threshold) {

13

    digitalWrite(ledPin, HIGH);

14

  }

15

  else {

16

    digitalWrite(ledPin, LOW);

17

  }

18

  delay(10); 

19

}

 
142

Project 13
Touchy-feely Lamp

USE IT

After  programming  the  Arduino,  you’ll  want  to  find  out  what 

the sensor values are when it’s touched. Open the serial moni-

tor and note the value coming from the sensor when you’re not 

touching it. Press gently on the bare wire you have exposed from 

your breadboard. The number should increase. Try pressing more 

firmly and see if it changes.

Once you have an idea of the range of values you’re getting from 

the sensor, go back to the sketch and change the threshold vari-

able  to  a  number  that  is  greater  than  the  sensor’s  value  when 

it is not touched, but less than its value when pressed. Upload 

the sketch with the new value. The light should come on reliably 

when you touch the wire, and turn off when it’s left alone. If you 

aren’t getting the light to turn on, try lowering the threshold a 

little more.

You probably noticed that the values from the sensor changed depending on how 

much  of  your  finger  was  touching  the  conductor.  Can  you  use  this  to  get  other 

interactions with the LED? What about multiple sensors for fading the light brighter 

and darker? If you place a different value resistor between pins 2 and 4 it will change 

the sensitivity. Is this useful for your interface?

Third party libraries like Paul Badger’s CapacitiveSensor are 
useful tools for expanding the capabilities of the Arduino. 
Once installed, they behave similarly to libraries that are 
bundled with the core software.

14

R
E
T
E
M
O
I
T
N
E
T
O
P

INGREDIENTS

145

TWEAK THE 
ARDUINO LOGO

USING SERIAL COMMUNICATION, YOU’LL USE YOUR 
ARDUINO TO CONTROL A PROGRAM ON YOUR COMPUTER

Discover: serial communication with a computer program, 

Processing
Time: 45 MINUTES
Level:

Builds on projects: 1, 2, 3

You’ve done a lot of cool stuff with the physical world, now it’s time to control 

your  computer  with  your  Arduino.  When  you  program  your  Arduino,  you’re 

opening  a  connection  between  the  computer  and  the  microcontroller.  You  can 

use this connection to send data back and forth to other applications.

The Arduino has a chip that converts the computer’s USB-based communication 

to the serial communication the Arduino uses. Serial communication means that 

the  two  computers,  your  Arduino  and  PC,  are  exchanging  bits  of  information 

serially, or one after another in time.

When communicating serially, computers need to agree on the speed at which 

they talk to one another. You’ve probably noticed when using the serial monitor 

there’s a number at the bottom right corner of the window. That number, 9600 
bits per second, or baud, is the same as the value you’ve declared using Serial.
begin(). That’s the speed at which the Arduino and computer exchange data. 
A bit is the smallest amount of information a computer can understand.

You’ve  used  the  serial  monitor  to  look  at  values  from  the  analog  inputs;  you’ll 

use  a  similar  method  to  get  values  into  a  program  you’re  going  to  write  in  a 
programming  environment  called  Processing.  Processing  is  based  on  Java,  and 
Arduino’s  programming  environment  is  based  on  Processing’s.  They  look  pretty 

similar, so you should feel right at home there. 

Before getting started with the project, download the latest version of Processing 
from  processing.org.  It  may  be  helpful  to  look  at  the  “Getting  started”  and 
“Overview” tutorials at processing.org/learning. These will help you to familiarize 
yourself with Processing before you start writing software to communicate with 

your Arduino.

146

Project 14
Tweak the Arduino Logo

The most efficient way to send data between the Arduino and Processing is by 
using  the  Serial.write()  function  in  Arduino.  It’s  similar  to  the  Serial.
print() function you’ve been using in that it sends information to an attached 
computer, but instead of sending human readable information like numbers and 

letters, it sends values between 0-255 as raw bytes. This limits the values that the 

Arduino can send, but allows for quick transmission of information.

On  both  your  computer  and  Arduino,  there’s  something  called  the  serial  buffer 

which holds onto information until it is read by a program. You’ll be sending bytes 

from the Arduino to Processing’s serial buffer. Processing will then read the bytes 

out of the buffer. As the program reads information from the buffer, it clears space 

for more.

When using serial communication between devices and programs, it’s important 

that  both  sides  not  only  know  how  fast  they  will  be  communicating,  but  also 

what they should be expecting. When you meet someone, you probably expect a 

“Hello!”; if instead they say something like “The cat is fuzzy”, chances are you will be 

caught off guard. With software, you will need to get both sides to agree on what 

is sent and received.

Fig. 1

147

BUILD THE
CIRCUIT

❶
❷

Connect power and ground to your breadboard. 

Connect each end of your potentiometer to power and ground. 

Connect the middle leg to analogIn pin 0.

Fig. 2

Fig. 3

148

Project 14
Tweak the Arduino Logo

THE ARDUINO
CODE

Open a serial connection

First,  program  your  Arduino.  In  setup(),  you’ll  start  serial 
communication, just as you did earlier when looking at the values 

from an attached sensor. The Processing program you write will 

have the same serial baud rate as your Arduino.

Send the sensor value

In  the  loop(),  you’re  going  to  use  the  Serial.write()
command  to  send  information  over  the  serial  connection. 
Serial.write() can only send a value between 0 and 255. To 
make sure you’re sending values that fit within that range, divide 

the analog reading by 4.

Let the ADC stabilize

After sending the byte, wait for one millisecond to let the ADC 

settle down. Upload the program to the Arduino then set it aside 

while you write your Processing sketch.

THE PROCESSING
CODE

Import the set up the serial 

The  Processing  language  is  similar  to  Arduino,  but  there  are 

object

enough  differences  that  you  should  look  at  some  of  their 

tutorials  and  the  “Getting  Started”  guide  mentioned  before  to 

familiarize yourself with the language.

Open  a  new  Processing  sketch.  Processing,  unlike  the  Arduino, 

doesn’t  know  about  serial  ports  without  including  an  external 

library. Import the serial library.

You need to create an instance of the serial object, just like you’ve 

done  in  Arduino  with  the  Servo  library.  You’ll  use  this  uniquely 

named object whenever you want to use the serial connection.

Create an object for the 

To use images in Processing, you need to create an object that 

image

will hold the image and give it a name.

149

SAVE AND CLOSE THE 
ARDUINO IDE NOW, 
LET’S START 
PROCESSING. 

1

2

3

4

5

6

7

1

2

void setup() {

  Serial.begin(9600);

}

void loop() {

  Serial.write(analogRead(A0)/4);

  delay(1);

}

import processing.serial.*;

Serial myPort;

3

PImage logo; 

150

Project 14
Tweak the Arduino Logo

Variable to store the 

background color

Create a variable that will hold the background hue of the Arduino 

logo. The logo is a .png file, and it has built-in transparency, so it’s 

possible to see the background color change.

Processing  has  a  setup()  function,  just  like  Arduino.  Here’s 
where you’ll open the serial connection and give the program a 

couple of parameters that will be used while it runs.

Setting the color mode

You can change the way Processing works with color information. 

Typically, it works with colors in a Red Green Blue (RGB) fashion. 

This is similar to the color mixing you did in Project  4, when you 

used values between 0 and 255 to change the color of an RGB 

LED.  In  this  program,  you’re  going  to  use  a  color  mode  called 

HSB,  which  stands  for  Hue,  Saturation,  and  Brightness.  You’ll 

change the hue when you turn the potentiometer.

colorMode() takes two arguments: the type of mode, and the 
maximum value it can expect.

Loading the image

To load the Arduino image into the sketch, read it into the logo 

Printing available serial 

ports

Creating the serial object

object you created earlier. When you supply the URL of an image, 

Processing will download it when you run the program.
With  the  size()  function,  you  tell  Processing  how  large  the 
display  window  will  be.  If  you  use  logo.width  and  logo.
height as the arguments, the sketch will automatically scale to 
the size of the image you’re using.

Processing  has  the  ability  to  print  out  status  messages  using  the 
println()  command.  If  you  use  this  in  conjunction  with  the 
Serial.list()  function,  you’ll  get  a  list  of  all  the  serial  ports 
your computer has when the program first starts. You’ll use this once 

you’re finished programming to see what port your Arduino is on.

You  need  to  tell  Processing  information  about  the  serial 
connection. To populate your named serial object myPort with 
the  necessary  information,  the  program  needs  to  know  it  is  a 

new instance of the serial object. The parameters it expects are 

which application it will be speaking to, which serial port it will 

communicate over, and at what speed.

151

4 int bgcolor = 0;

5

void setup() { 

6

  colorMode(HSB, 255);

7

8

  logo = loadImage(“http://arduino.cc/logo.png”);

  size(logo.width, logo.height); 

9

  println(“Available serial ports:”);

10

  println(Serial.list());

11

  myPort = 

    new Serial(this, Serial.list()[0], 9600);

12

}

 
152

Project 14
Tweak the Arduino Logo

The attribute this tells Processing you’re going to use the serial 
connection  in  this  specific  application.  The  Serial.list()
[0] argument specifies which serial port you’re using. Serial.
list() contains an array of all the attached serial devices. The 
argument  9600  should  look  familiar,  it  defines  the  speed  at 
which the program will communicate.

The draw() function is analogous to Arduino’s loop() in that 
it happens over and over again forever. This is where things are 

drawn to the program’s window.

Reading Arduino data from 

the serial port

Check  if  there  is  information  from  the  Arduino.  The  myPort.
available()  command  will  tell  you  if  there  is  something  in 
the serial buffer. If there are bytes there, read the value into the 
bgcolor variable and print it to the debug window.

Setting the image 

background and displaying 

The  function  background()  sets  the  color  of  the  window.  It 
takes three arguments. The first argument is the hue, the next 

the image

is brightness, and the last is saturation. Use the variable bgcolor 

as  the  hue  value,  and  set  the  brightness  and  saturation  to  the 

maximum value, 255.
You’ll  draw  the  logo  with  the  command  image().  You  need 
to  tell  image()  what  to  draw,  and  what  coordinates  to  start 
drawing it in the window. 0,0 is the top left, so start there.

USE IT

Connect your Arduino and open the serial monitor. Turn the 

pot on your breadboard. You should see a number of charac-

ters  as  you  twist  the  knob.  The  serial  monitor  expects  ASCII 

characters,  not  raw  bytes.  ASCII  is  information  encoded  to 

represent text in computers. What you see in the window is 

the serial monitor trying to interpret the bytes as ASCII. 

When  you  use  Serial.println(),  you  send  information 
formatted  for  the  serial  monitor.  When  you  use  Serial.
write(),  like  in  this  application  you  are  running  now,  you’re 
like  Processing  can 
sending 

information.  Programs 

raw 

understand these raw bytes.

153

13 

void draw() { 

14

  if (myPort.available() > 0) { 

15

    bgcolor = myPort.read(); 

16

    println(bgcolor);

17

  }

18

  background(bgcolor, 255, 255);

19

image(logo, 0, 0);

20

} 

154

Project 14
Tweak the Arduino Logo

Close the serial monitor. Run the Processing sketch by press-

ing the arrow button in the Processing IDE. Look at the Pro-

cessing  output  window.  You  should  see  a  list  similar  to  the 

figure below.

This is a list of all the serial ports on your computer. If you’re 

using  OSX,  look  for  a  string  that  says  something  like  “/dev/

tty.usbmodem411”,  it  will  most  likely  be  the  first  element  in 

the  list.  On  Linux,  it may  appear as  “/dev/ttyUSB0”,  or  simi-

lar. For Windows, it will appear as a COM port, the same one 

you would use when programming the board. The number in 
front of it is the Serial.list()[] array index. Change the 
number in your Processing sketch to match the correct port 

on your computer. 

Restart the Processing sketch. When the program starts run-

ning,  turn  the  potentiometer  attached  to  the  Arduino.  You 

should see the color behind the Arduino logo change as you 

turn  the  potentiometer.  You  should  also  see  values  printing 

out in the Processing window. Those numbers correspond to 

the raw bytes you are sending from the Arduino.

155

Once  you  have  twisted  and  turned  to  your  heart’s  desire,  try  replacing  the  pot 

with an analog sensor. Find something you find interesting to control the color. 

What does the interaction feel like? It’s probably different than using a mouse or 

keyboard, does it feel natural to you? 

When using serial communication, only one application can talk to the Arduino at a 

time. So if you’re running a Processing sketch that is connected to your Arduino, you 

won’t be able to upload a new Arduino sketch or use the serial monitor until you’ve 

closed the active application. 

With Processing and other programming environments, you can control media on 

your computer in some remarkable and novel ways. If you’re excited about the pos-

sibilities of controlling content on your computer, take some time to experiment 

with Processing. There are several serial communication examples in both the Pro-

cessing and Arduino IDEs that will help you explore further.

Serial  communication  enables  the  Arduino  to  talk  with 
programs  on  a  computer.  Processing  is  an  open  source 
programming  environment  that  the  Arduino  IDE  is  based 
upon. It’s possible to control a Processing sketch with the 
Arduino via serial communication.

15

R
O
T
S
I
S
E
R

M
H
O

0
2
2

R
E
L
P
U
O
C
O
T
P
O

INGREDIENTS

 
 
157

HACKING 
BUTTONS

GET CONTROL OF OTHER COMPONENTS AROUND YOU. 
USING SOME ADDITIONAL CIRCUITRY, YOU CAN “PRESS” 
BUTTONS WITH YOUR ARDUINO

Discover: optocoupler, connecting with other components

Time: 45 MINUTES
Level:

Builds on projects: 1, 2, 9

Warning: You’re no longer a beginner if you’re doing this project. You’ll be opening 

up an electronic device and modifying it. You’ll void your device’s warranty, and if 

you’re not careful, you might damage the device. Make sure you’re familiar with 

all the electronics concepts in the earlier projects before you attempt this one. We 

recommend you use inexpensive items you don’t mind damaging for your first few 

projects, until you develop experience and confidence. 

While the Arduino can control a lot of things, sometimes it’s easier to use tools 

that are created for specific purposes. Perhaps you want to control a television 

or a music player, or drive a remote control car. Most electronic devices have a 

control panel with buttons, and many of those buttons can be hacked so that 

you  can  “press”  them  with  an  Arduino.  Controlling  recorded  sound  is  a  good 

example. If you wanted to record and play back recorded sound, it would take 

a  lot  of  effort  to  get  the  Arduino  to  do  that.  It’s  much  easier  to  get  a  small 

device that records and plays back sound, and replace its buttons with outputs 

controlled by your Arduino. 

Optocouplers are integrated circuits that allow you to control one circuit from 
a  different  one  without  any  electrical  connection  between  the  two.  Inside  an 

optocoupler is an LED and a light detector. When the LED in the optocoupler 

is turned on by your Arduino, the light detector closes a switch internally. The 

switch  is  connected  to  two  of  the  output  pins  (4  and  5)  of  the  optocoupler. 

When the internal switch is closed, the two output pins are connected. When the 

switch is open, they’re not connected. This way, it’s possible to close switches on 

other devices without connecting them to your Arduino.

158

Project 15
Hacking Buttons

In this example, the diagrams are for controlling a digital recording module that allows you to 

record and playback 20 seconds of sound, but the basic premise holds for any device that has 

a switch you can access. While it’s possible to use this example without soldering any wires, it 

certainly makes things easier. For more information on soldering, see p. 134.

BUILD THE
CIRCUIT

Fig. 1

Fig. 2

159

❶
❷

❸

❹

❺

❻

❼

❽

Connect ground to your breadboard through the Arduino.

Place the optocoupler on your breadboard so that it straddles 

the center of the board (see circuit diagram). 

Connect pin 1 on the optocoupler to Arduino pin 2 in series with 

a 220-ohm resistor (remember, you’re powering an LED inside, 
you don’t want to burn it out). Connect pin 2 of the optocou-

pler to ground.

On the main board of the sound module there are a number of 

electrical components, including a playback button. 

To control the switch, you’re going to have to remove the but-

ton. Flip the circuit board over and find the tabs that hold the 

button in place. Gently bend the tabs back and remove the but-

ton from the board. 

Under  the  button  are  two  small  metal  plates.  This  pattern  is 

typical of many electronic devices with pushbuttons. The two 

“forks” of this pattern are the two sides of the switch. A small 

metal  disc  inside  the  pushbutton  connects  these  two  forks 

when you press the button.

When the forks are connected, the switch is closed on the circuit 

board. You will be closing the switch with the optocoupler. 

This method, closing a switch with an optocoupler, works only if 

one of the two sides of the pushbutton’s switch is connected to 

ground on your device. If you’re not sure, take a multimeter and 

measure the voltage between one of the forks and the ground 
on your device. You need to do this with the device turned on, so 

be careful not to touch anywhere else on the board. 

Once you know which fork is ground, disconnect the power to 

your device.

Next, connect one wire to each of the small metal plates. If you 

are  soldering  these  wires,  be  careful  to  not  join  the  two  sides 

of the switch together. If you are not soldering and using tape, 

make sure your connection is secure, or the switch won’t close. 

Make sure neither wire connects to the other fork, or your switch 

will be closed all the time.

Attach the two wires to pins 4 and 5 of the optocoupler. Connect 

the side of the switch that is grounded to pin 4 of the optocou-

pler. Connect the other fork to pin 5 of the optocoupler.

160

Project 15
Hacking Buttons

THE CODE

Name a constant

Most  of  the  fun  with  this  project  is  in  the  circuit  and  the 

optocoupler.  The  code  is  similar  to  the  first  project  you  made 

with the Arduino. You’re going to play the sound once every 20 
seconds by turning pin 2 HIGH.
Create a constant for the optocoupler control pin.

Configure the pin direction

In setup(), set the optocoupler pin into an output.

Pull the pin high and low

The  loop()  turns  optoPin  HIGH  for  a  few  milliseconds,  long 
enough for the optocoupler to close the switch on the device. 
Then the optoPin becomes LOW.

Wait for a little while

Wait for 21 seconds for the whole message to play back before 
starting the loop() again.

USE IT

Attach the battery to the sound recorder. Press and hold the 

record button on the device. While you’re holding the button, 

you can record audio into the microphone. Use your voice, the 

cat, or the pots and pans in the kitchen to make some noise 

(but be careful with the cat). 

Once you’ve satisfactorily recorded a sound, power your Ar-

duino with the USB cable. Your recording should start to play. 

If you recorded for the full 20 seconds, the sound should start 

again just a few moments after it ends.

Try experimenting with different sounds and durations of toggling the playback 
with the delay() in your program. 
If you trigger the switch while a sound is playing, it will stop. How can you take 

advantage of this to create unique sequences of sounds?

161

1 const int optoPin = 2; 

2

3

4

5

6

7

8

void setup(){ 

  pinMode(optoPin, OUTPUT); 

}

void loop(){

  digitalWrite(optoPin, HIGH); 

  delay(15); 

  digitalWrite(optoPin, LOW); 

9

  delay(21000); 

10

}

Integrated  circuits  are  in  virtually  every  electronic  device.  The  large  28  pin  chip  on 

your Arduino is an IC that houses the brains of the board. There are other ICs that 

support this one with communication and power. The optocoupler and main chip on 
the Arduino are Dual In-line Package (DIP) chips. These DIP chips are the kind that 
most hobbyists use because they easily fit in a breadboard and don’t have to be per-

manently soldered to be used.

The project example only played sound back at a regular interval. How could you 

incorporate  the  inputs  from  earlier  projects  to  trigger  these  sounds?  What  other 

battery powered things do you have around the house that need an Arduino to con-

trol them? This technique of controlling an electronic device with an optocoupler by 

connecting to the two sides of a switch can be used in many other devices. What 

other devices do you want to control?

Optocouplers  can  control  devices  that  are  on  a  different 
circuit. The two circuits are electrically separated from each 
other inside the component. 

A/Z

Accelerometer - 

Actuator - 

Direct current - 

Drain (transistor) -

Period - 

Photocell - 

Alternating current -

Dual In-line Package (DIP) -

Photoresistor - 

Amperage (amps or amperes) -

Duty cycle - 

Analog - 

Electricity -

Analog-to-Digital Converter 

Float -

Function -

Gate - 

Phototransistor - 

Polarized -

Power supply - 

Processing - 

Pseudocode - 

(ADC) - 

Anode - 

Argument - 

Array -

Back-voltage -

Baud -

Binary - 

Bit - 

Boolean - 

Byte - 

Calibration - 

Capacitance - 

Cathode - 

Circuit - 

Global variable - 

Pulse Width Modulation 

Ground - 

IDE - 

Index - 

Induction - 

Instance -

Insulator - 

Int - 

(PWM) - 

Resistance - 

Sensor -

Serial buffer - 

Serial communication - 

Serial monitor - 

Series - 

Integrated Circuit (IC)- 

Short circuit - 

Library - 

Load - 

Sketch -

Soldering -

Local variable -

Source (transistor) - 

Common cathode LED - 

Long - 

Conductor -

Constant - 

Current - 

Datasheet -

Datatype - 

Debugging - 

Microcontroller - 

Millisecond - 

Object - 

Ohm - 

Ohm’s Law - 

Optocoupler -

Decoupling capacitors -

Parallel -

Square wave -

Switch - 

Transducer - 

Transistor - 

Unsigned - 

USB - 

Variable -

Voltage - 

Digital - 

Parameter - 

Voltage divider -

GLOSSARY

163

GLOSSARY

THERE  ARE  A  NUMBER  OF  NEW  TERMS 

YOU’VE LEARNED IN THESE PROJECTS. 

WE’VE COLLECTED THEM ALL HERE FOR 

REFERENCE

A

Accelerometer  -  A  sensor  that  measures  ac-
celeration. Sometimes, they are used to detect 

Analog-to-Digital  Converter  (ADC)  -  A  circuit 
that  converts  an  analog  voltage  into  a  digital 

orientation, or tilt.

Actuator - A type of component that changes 
electrical energy into motion. Motors are a type 

of actuator.

Alternating  current  -  A  type  of  current  where 
electricity  changes  its  direction  periodically. 

This is the sort of electricity that comes out of 

a wall socket. 

number  representing  that  voltage.  This  circuit 

is  built-in  to  the  microcontroller,  and  is  con-
nected  to  the  analog  input  pins  A0-A5.  Con-

verting an analog voltage into a digital number 

takes a tiny bit of time, so we always follow the 

analogRead() with a short delay().

Anode - The positive end of a capacitor or diode 
(remember that an LED is a type of diode).

Amperage (amps or amperes) - The amount of 
electrical  charge  flowing  past  a  specific  point 

Argument - A type of data supplied to a func-
tion as an input. For example, for digitalRead() 

to  know  what  pin  to  check,  it  takes  an  argu-

in your circuit. Describes the current as it flows 

ment in the form of a pin number.

through a conductor, like a wire.

Analog - Something that can continuously vary 
over time. 

Array - In programming, this is a group of vari-
ables that are identified by one name, and ac-

cessed by an index number.

164

Glossary

B

Back-voltage  -  Voltage  that  pushes  back 
against  the  current  that  created  it.  It  can  be 

created  by  motors  spinning  down.  This  can 

damage circuits, which is why diodes are often 

used in conjunction with motors.

Baud - Shorthand for “bits per second”, signify-
ing the speed at which computers are commu-

nicating with each other.

Binary  -  A  system  with  only  two  states,  like 
true/false or off/on. 

Bit - The smallest piece of information a com-
puter can send or receive. It has two states, 0 

and 1.

Cathode - The end of a capacitor or diode that 
typically connects to ground.

Circuit  -  A  circular  path  from  a  power  supply, 
through  a  load,  and  then  back  again  to  the 

other  end  of  the  power  supply.  Current  flows 

in a circuit only if it is closed, that is, if the out-
going and return path are both uninterrupted, 

or closed. If either path is interrupted, or open, 

then current will not flow through the circuit.

Common  cathode  LED  -  Types  of  LEDs  that 
have  multiple  colors  in  one  fixture,  with  one 

cathode and multiple anodes.

Conductor - Something that enables electricity 
to flow, like a wire.

Constant  -  A  named  identifier  that  cannot 
change its value in a program.

Boolean  -  A  datatype  that  indicates  if  some-
thing is true or false.

Current - The flow of electrical charge through a 
closed circuit. Measured in amps.

Byte - 8 bits of information. A byte can hold a 
number between 0 and 255.

D

C

Calibration - The process of making adjustments 
to  certain  numbers  or  components  to  get  the 

best results from a circuit or program. In Arduino 

projects, this is often used when sensors in the 

real world may give different values in different 

circumstances, for instance the amount of light 

on a photoresistor. Calibration can be automatic, 

as in Project  6, or manual, as in Project  3.

Capacitance  -  The  ability  of  something  to 
hold an electrical charge. This charge can be 

measured with the Capacitive Sensor library, 

as seen in Project  13.

Datasheet -  A  document  written  by  engineers 
for  other  engineers  that  describes  the  design 

and  functionality  of  electrical  components. 

Typical information in a datasheet includes the 

maximum  voltage  and  current  a  component 

requires, as well as an explanation of the func-

tionality of the pins.

Datatype  -  A  classification  system  that  deter-
mines what values a particular constant, varia-

ble, or array will hold. Int, float, long and boolean 

are all types that can be used in Arduino.

Debugging - The process of going through a cir-
cuit or code, and finding errors (also referred as 

“bugs”), until the expected behavior is achieved.

165

Decoupling  capacitors  -  Capacitors  that  are 
used to regulate spikes and dips in voltage, of-

ten placed close to a sensor or actuator.

G

Digital - A system of discrete values. As Arduino 
is a type of digital device, it only knows of two 

discrete states, off and on, nothing in between. 

Direct current - A type of current which always 
flows in the same direction. All the projects in 

this kit use direct current.

Drain (transistor) - The pin that connects to the 
higher current/voltage load to be controlled.

Dual In-line Package (DIP) - A type of packaging 
for integrated circuits that allows the compo-

nents to be easily inserted into a breadboard.

Gate - The pin on a transistor that is connected 
to  the  Arduino.  When  the  gate  is  turned  on, 

by applying 5V, it closes the junction between 

drain  and  source,  completing  the  circuit  it  is 
connected to.

Global variable - A named variable that can be 
accessed  anywhere  inside  your  program.  It  is 

declared before the setup() function.

Ground - The point of a circuit where there is 0 
potential electrical energy. Without a ground, 

electricity  will  not  have  a  place  to  flow  in  a 

circuit.

Duty  cycle  -  A  ratio  indicating  the  amount  of 
time  over  a  certain  period  that  a  component 

is  turned  on.  When  using  a  PWM  value  of  127 

I

(out  of  a  total  of  256),  you’re  creating  a  50% 

duty cycle.

E

IDE - Stands for “Integrated Development En-
vironment”. The Arduino IDE is the place where 

you write software to upload to the Arduino. It 

contains all the functions the Arduino can un-

derstand.  Other  programming  environments, 

like Processing, have their own IDE. 

Electricity  -  A  type  of  energy  generated  by 
electric  charges.  You  can  use  electronic  com-

Index  -  The  number  supplied  to  an  array  that 
indicates  which  element  you’re  referring  to. 

ponents to change electricity to other forms of 

Computers  are  zero-indexed,  which  means 

energy, like light and heat.

F

Float - A datatype that can be expressed as a 
fraction. This entails the use of decimal points 

for floating point numbers.

they start counting at 0 instead of 1. To access 

the third element in an array named tones, for 

example, you would write tones[2].

Induction - The process of using electrical en-
ergy to create a magnetic field. This is used in 

motors to spin them around.

Instance  -  A  copy  of  a  software  object.  You’re 
using instances of the Servo library in Projects 5 

Function - A block of code that executes a spe-
cific task repeatedly. 

and 12, in each case, you’re creating a named in-

stance of the Servo library to use in the project.

166

Glossary

Insulator - Something that prevents electricity 
from  flowing.  Conductive  materials  like  wires 

are often covered in insulators like rubber.

is a small computer that you will program to lis-

ten for, process, and display information.

Int - A datatype that holds a whole number be-
tween −32,768 and 32,767.

Integrated Circuit (IC) - A circuit that has been 
created on a tiny piece of silicon and embedded 

in  plastic  (or  epoxy).  Pins,  or  legs,  protruding 

from  the  body  allow  you  to  interact  with  the 

circuit inside. Very often we can make good use 

of an IC knowing only what to connect to the 

pins without having to understand how it func-

tions internally.

L

Library - A piece of code that expands the func-
tionality of a program. In the case of Arduino li-

Millisecond - 1/1,000th of a second. The Arduino 
goes  through  its  programs  so  fast,  when  call-

ing delay() and other time based functions, it’s 

done in milliseconds.

O

Object - An instance of a library. When using the 
Servo  library,  were  you  to  create  an  instance 

named myServo, myServo would be the object.

Ohm - Unit of measurement of resistance. Rep-
resented by the omega symbol (Ω).

Ohm’s  Law  -  A  mathematical  equation  that 
demonstrates the relationship between resist-

ance,  current  and  voltage.  Usually  stated  as  V 

braries, they either enable communication with 

(voltage) = I (current) x R (resistance).

a  particular  piece  of  hardware,  or  are  used  for 

manipulating data.

Load - A device that turns electrical energy into 
something else, such as light, heat, or sound.

Local variable - A type of variable that is used 
for  a  short  amount  of  time,  then  forgotten.  A 

Optocoupler - Also known as an opto-isolator, 
photo-coupler,  photo-isolator,  photo-switch, 

and  opto-switch.  An  LED  is  combined  in  a 

sealed case with a phototransistor. The LED is 

positioned to illuminate the phototransistor, so 
that when the LED is turned on, the phototran-

sistor will conduct. Used to provide a high de-

variable  declared  inside  the  setup()  of  a  pro-

gree  of  isolation  as  there  is  no  electrical  con-

gram would be local: after the setup() finished 

nection common to the input and the output.

running, the Arduino would forget that the vari-

able ever existed.

Long  -  A  datatype  that  can  hold  a  very  large 
number, from −2,147,483,648 to 2,147,483,647.

P

M

Parallel  -  Components  connected  across  the 
same two points in a circuit are in parallel. Par-

allel components always have the same voltage 

drop across them.

Microcontroller - The brains of the Arduino, this 

Parameter  -  When  declaring  a  function,  a 

167

named parameter serves as the bridge between 

the local variables in the function, and the argu-

Pseudocode  -  A  bridge  between  writing  in  a 
computer  programming  language  and  using 

ments it receives when the function is called.

natural speech. When creating pseudocode, it’s 

Period - A specific span of time in which some-
thing  happens.  When  the  period  changes, 

you’re adjusting the frequency at which some-
thing will occur.

Photocell - A device for converting light energy 
to electrical energy.

helpful to write in short declarative statements.

Pulse Width Modulation (PWM) - A way to sim-
ulate an analog output when using a digital de-
vice, PWM involves turning a pin on and off at a 

very rapid rate.The ratio of ON time to OFF time 

determines the simulated analog result.

Photoresistor - A resistive device whose resist-
ance  varies  according  to  how  much  light  falls 

on it.

R

Phototransistor  -  A  transistor  which  is  con-
trolled by light rather than by current.

Resistance  -  A  measure  of  how  efficiently  a 
material  will  conduct  electricity.  In  particular, 

resistance can be calculated by Ohm’s Law as: 

Polarized - The leads of polarized components 
(e.g.  LEDs  or  capacitors)  have  different  func-

tions,  and  thus  must  be  connected  the  right 

way.  Polarized  components  connected  the 

wrong way might not work, might be damaged, 

or might damage other parts of your circuit.

Non-polarized  components  (e.g.  resistors)  can 

be connected either way.

R = V/I.

S

Sensor - A component that measures one form 
of energy (like light or heat or mechanical en-

ergy) and converts it to electrical energy, which 

the Arduino can understand.

Power supply - A source of energy, usually a bat-
tery, transformer, or even the USB port of your 

computer.  Comes  in  many  varieties  such  as 

Serial  buffer  -  A  place  in  your  computer’s  and 
microcontroller’s  memory  where  information 

regulated or unregulated, AC or DC. Usually the 

received in serial communication is stored until 

voltage  is  specified,  along  with  the  maximum 

it is read by a program.

current the supply can deliver before failing.

Processing  -  A  programming  environment 
based on the Java language. Used as a tool to 

Serial  communication  -  The  means  by  which 
the  Arduino  communicates  with  computers 

and other devices. It involves sending one bit of 

introduce people to the concepts of program-

information at a time in a sequential order. The 

ming, and in production environments. 

Arduino has a USB-to-serial converter onboard, 

The Arduino IDE is written in Processing, and so 

which enables it to talk with devices that don’t 

will  look  very  familiar.  In  addition,  Processing 

have a dedicated serial port. 

and Arduino share a similar philosophy and mo-

tive, of creating free open source tools allowing 

non-technical  people  to  work  with  hardware 

and software.

Serial monitor - A tool built in to the Arduino 
IDE allowing sending and receiving serial data 

to  and  from  a  connected  Arduino.  See  the 

168

Glossary

Serial() set of functions.

Series - Components are in series when current 
flows  from  the  first  into  the  next.  The  current 

device  which  can  act  as  either  an  amplifier  or 

a switch. A control voltage or current between 

two leads controls a (usually) higher voltage or 

current between a different pair of leads. Com-

flowing through both is the same, and the volt-

mon  types  of  transistors  include  the  Bipolar 

age drops across each component.

Junction  Transistor  (BJT)  and  the  Metal  Oxide 

Short  circuit  -  A  short  circuit  between  power 
and  ground  will  make  your  circuit  stop  work-

Semiconductor  Field  Effect  Transistor  (MOS-
FET). Often used to allow a small current from 

an Arduino (limited to 40 mA) to control sub-

ing and thus should be avoided. In some cases 

stantially larger currents, such as those needed 

this might damage your power supply or parts 

by  motors,  relays,  or  incandescent  lamps.  De-

of your circuit, and rare cases might start a fire.

pending on how they are constructed, transis-

Sketch - The term given to programs written in 
the Arduino IDE.

tors  are  either  N-channel  or  P-channel,  which 

determines how they should be connected.

Soldering  -  The  process  of  making  an  electri-
cal connection by melting solder over electrical 

components or wires that are to be connected. 

U

This provides a solid connection between com-

ponents.

Unsigned - A term used to describe some data-
types, indicating that they cannot be a negative 

number. It’s helpful to have an unsigned num-

Source (transistor) - The pin on a transistor that 
connects  to  ground.  When  the  gate  receives 

ber if you only need to count in one direction. 

For instance, when keeping track of time with 

power,  the  source  and  drain  are  connected, 

millis(), it’s advisable to use the unsigned long 

completing the circuit that is being controlled.

datatype.

Square wave - A type of waveform that is iden-
tified  by  having  only  two  states,  on  and  off. 
When used to generate tones, they can sound 

USB - Stands for Universal Serial Bus. It’s a ge-
neric port that is standard on most computers 
today. With a USB cable, it’s possible to program 

“buzzy”.

and power an Arduino over a USB connection.

Switch - A component that can open or close an 
electrical circuit. There are many different kinds of 

switches; the ones in the kit are momentary mean-

ing, they only close the circuit while being pressed.

V

T

Transducer - Something that changes one form 
of energy into another.

Variable -  A place in your computer’s or mi-
crocontroller’s  memory  for  storing  informa-

tion  needed  in  a  program.  Variables  store 

values which are likely to change as your pro-

gram  runs.  A  variable’s  type  depends  on  the 

type  of  information  you  want  to  store,  and 

the  maximum  size  of  the  information;  for 

Transistor  -  A  3  terminal  (usually)  electronic 

example,  a  byte  can  store  up  to  256  differ-

169

ent  values,  but  an  int  can  store  up  t  65,536 

different  values.  Variables  can  be  local  to  a 

particular block of code, or global to an entire 

program. (see Global variable, Local variable).

Voltage  -  A  measure  of  potential  energy,  that 
a  charge  might  be  pushed  with  if  provided  a 
closed circuit. 

Voltage divider - A type of circuit that provides 
an output that is a fraction of its input voltage. 

You  are  building  a  voltage  divider  when  you 

combine  a  photoresistor  with  a  fixed  resistor 

to provide an analog input. A potentiometer is 

another example of a voltage divider.

170

Further Reading

FURTHER
READING

Getting Started with Arduino by Massimo Banzi 
[O’Reilly  Media  /  Make,  2011].  The  definitive 

introduction to Arduino. 

Getting Started with Processing by Casey Reas 
and Ben Fry [O’Reilly Media / Make, 2010]. This 
short  guide  to  the  Processing  programming 

environment tells you more about how to pro-

gram graphics, sounds, and multimedia on your 

computer.

Making  Things  Talk,  2nd  Edition  by  Tom  Igoe 
[O’Reilly Media / Make, 2011]. Written for more 

experienced Arduino users, this book gives you 

many techniques for communicating between 

Arduino microcontrollers and other devices on 

the internet, and beyond. 

Learning Processing: A Beginner’s Guide to Pro-
gramming Images, Animation, and Interaction 
by  Daniel  Shiffman  [Morgan  Kaufman,  2009]. 
An  in-depth  introduction  to  programming  us-

ing Processing, for beginners of all ages.

Getting Started with RFID by Tom Igoe [O’Reilly 
Media / Make, 2012]. A short introduction to us-

ing Radio Frequency Identification with Arduino 

and Processing.

171

The Arduino Cookbook, 2nd Edition by Michael 
Margolis  [O’Reilly  Media  /  Make,  2011].  This 
book has a lot of great recipes for how to use 

Arduino in more advanced ways.

Making  Things  Move:  DIY  Mechanisms  for 
Inventors,  Hobbyists,  and  Artists  by  Dustyn 
Roberts  [McGraw-Hill,  2010].  A  great  resource 
on  building  movable  mechanisms  to  interface 

with your projects.

Make:  Electronics,  by  Charles  Platt  [O’Reilly 
Media / Make, 2009]. Cleverly written introduc-

tion to electronics suitable for just about any-

one.  No  Arduinos  were  used  in  the  making  of 

this book, but it’s a valuable text to understand 

electronics better.

iOS Sensor Apps with Arduino, by Alasdair Allan 
[O’Reilly Media / Make, 2011]. With this concise 

guide,  you’ll  learn  how  to  connect  an  external 

sensor to an iOS device and have them talk to 

each other through Arduino. You’ll also build an 

iOS  application  that  will  parse  the  sensor  val-

ues it receives and plot the resulting measure-

ments, all in real-time.