{"id":40,"date":"2019-04-05T16:59:32","date_gmt":"2019-04-05T16:59:32","guid":{"rendered":"https:\/\/openlab.bmcc.cuny.edu\/mmp460\/?page_id=40"},"modified":"2020-10-11T20:31:19","modified_gmt":"2020-10-11T20:31:19","slug":"physical-computing","status":"publish","type":"page","link":"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/physical-computing\/","title":{"rendered":"Physical Computing"},"content":{"rendered":"<h2><strong>What is physical computing?<\/strong><\/h2>\n<p>Physical computing refers to the process of building physical interfaces that respond to the analog world. This is done by building circuits with micro controllers, wires, sensors, LEDs, motors etc. and controlling them with a piece of custom-made software (i.e: \u201cTurn the LED on when the number sent by the photocell sensor is less than 100\u201d). Physical computing is a great way of introducing or reinforcing programming concepts, and exploring how they can be applied to non-screenbased applications. But it has also been used beyond the educational realm \u2013 <a href=\"http:\/\/www.nytimes.com\/2011\/03\/17\/arts\/design\/arduinos-provide-interactive-exhibits-for-about-30.html\">by artists<\/a>, <a href=\"http:\/\/www.eyewriter.org\/\">to support ALS patients<\/a>, <a href=\"http:\/\/design-io.com\/projects\/ConnectedWorlds\/\">for immersive installations<\/a>, <a href=\"https:\/\/www.wired.com\/2009\/04\/drawdio-a-pencil-that-lets-you-draw-music\/\">experimental music<\/a>, <a href=\"https:\/\/www.fastcodesign.com\/3048737\/programmable-clothes-are-going-commercial\">fashion<\/a>, and\u00a0<a href=\"http:\/\/www.watercanary.com\/\">to test water quality.<\/a><\/p>\n<p>While there are a lot of similarities between robotics and physical computing, the latter is focused on creating interfaces that explore the human body\u2019s relationship to the digital world (rather than building robots that can function without human or environmental input).<\/p>\n<figure id=\"attachment_76\" aria-describedby=\"caption-attachment-76\" style=\"width: 828px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-76 size-large\" src=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/61\/2019\/04\/3822162747_9c30f6be11_o-e1521736759653-828x1024.jpg\" alt=\"\" width=\"828\" height=\"1024\" srcset=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/3822162747_9c30f6be11_o-e1521736759653-828x1024.jpg 828w, https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/3822162747_9c30f6be11_o-e1521736759653-242x300.jpg 242w, https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/3822162747_9c30f6be11_o-e1521736759653-768x950.jpg 768w, https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/3822162747_9c30f6be11_o-e1521736759653.jpg 1196w\" sizes=\"auto, (max-width: 828px) 85vw, 828px\" \/><figcaption id=\"caption-attachment-76\" class=\"wp-caption-text\">\u201cArduino with CdS &amp; LED\u201d by yoggy0. License: CC BY 2.0<\/figcaption><\/figure>\n<header class=\"entry-header\">\n<h1 class=\"entry-title\">Using a Microcontroller<\/h1>\n<\/header>\n<div class=\"entry-content\">\n<h2>What\u2019s a Microcontroller?<\/h2>\n<p>A microcontroller is a small computer that can take in information from inputs such as sensors and switches and control outputs such as lights, motors and other computers. Microcontrollers are widely used in many different ways; DIY and robotics, art installations, industrial applications, and the internet of things.<\/p>\n<p>When you are using a microcontroller, or in our case a microcontroller platform, there are two components: hardware and software. The hardware includes the microcontoller and its input and output pins, and any input or output devices you want to attach to it. The software is programs you write that control the microcontroller and the devices you have attached to it.<\/p>\n<p>In this class we will be using the Arduino microcontroller platform. It was developed by a team of teachers to help their design students who were not engineers create physical interfaces.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-77\" src=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/61\/2019\/04\/intro-arduino_logo-300x204.png\" alt=\"\" width=\"300\" height=\"204\" srcset=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/intro-arduino_logo-300x204.png 300w, https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/intro-arduino_logo.png 600w\" sizes=\"auto, (max-width: 300px) 85vw, 300px\" \/><\/p>\n<p>The Arduino has an IDE, (integrated development environment), that is free and downloadable from the Arduino site (download it <a href=\"https:\/\/www.arduino.cc\/en\/Main\/Software\">here<\/a>). This is a set of software that allows you to write code, then upload it directly to the Arduino.<\/p>\n<h3>Arduino Uno<\/h3>\n<p>There are many different versions of the Arduino but we will be using just one, the Arduino Uno.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-78 size-full\" src=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/61\/2019\/04\/intro-uno-01-1.png\" alt=\"\" width=\"692\" height=\"520\" srcset=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/intro-uno-01-1.png 692w, https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/intro-uno-01-1-300x225.png 300w\" sizes=\"auto, (max-width: 692px) 85vw, 692px\" \/><\/p>\n<p>In order to program the Arduino, download the Arduino IDE and install it (detailed instructions on downloading and installing are <a href=\"http:\/\/arduinotogo.com\/2016\/09\/09\/chapter-3-downloading-and-installing-the-software\/\">here<\/a>). The laptops we have in our Maker Space already have the software installed. Connect the Arduino to the computer with a USB A-B cable. If you have a newer Macintosh laptop, you will have to use an USB-C to USB adapter.<\/p>\n<\/div>\n<h3><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-79 size-full\" src=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/61\/2019\/04\/ch1-uno-usb-laptop-01.png\" alt=\"\" width=\"310\" height=\"166\" srcset=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/ch1-uno-usb-laptop-01.png 310w, https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/ch1-uno-usb-laptop-01-300x161.png 300w\" sizes=\"auto, (max-width: 310px) 85vw, 310px\" \/><\/h3>\n<h3>Parts of an Arduino Uno<\/h3>\n<p>Let\u2019s look a bit more closely to the parts of the Arduino. We\u2019ll look at the left side first.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-80 size-full\" src=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/61\/2019\/04\/ch1-uno-left-side-labelled-01.png\" alt=\"\" width=\"359\" height=\"570\" srcset=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/ch1-uno-left-side-labelled-01.png 359w, https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/ch1-uno-left-side-labelled-01-189x300.png 189w\" sizes=\"auto, (max-width: 359px) 85vw, 359px\" \/><\/p>\n<p><b>Reset Button:<\/b> This button will restart the code currently uploaded on your Arduino. The reset button may be in a different location on your board than in this diagram, but it is the only button.<\/p>\n<p><b>USB Port:<\/b> The USB port takes a standard A-to-B USB cable, often seen on printers or other computer peripherals. The USB port serves two purposes: First, it is the cable connection to a computer which allows you to program the board. The USB cord will also provide power for the Arduino if you\u2019re not using the power port (described below).<\/p>\n<p><b>Voltage Regulator:<\/b> The voltage regulator converts power plugged into the power port (described below) into the 5 volts and 1 amp standard used by the Arduino. BE CAREFUL! This component gets very hot.<\/p>\n<p><b>Power Port:<\/b> The power port includes a barrel-style connector which allows for either power straight from a wall source or from a battery. This power is used instead of the USB cable. The Arduino can take a wide range of voltages (5V \u2013 20V) but will be damaged if power higher than that is connected.<\/p>\n<p>Now let\u2019s look at the rest of the board.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-81 size-full\" src=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/61\/2019\/04\/ch1-uno-right-side-labelled-01.png\" alt=\"\" width=\"465\" height=\"601\" srcset=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/ch1-uno-right-side-labelled-01.png 465w, https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/ch1-uno-right-side-labelled-01-232x300.png 232w\" sizes=\"auto, (max-width: 465px) 85vw, 465px\" \/><\/p>\n<p><b>Built-in LEDs:<\/b> The LEDS indicate that there is power, and if your Arduino is sending or receiving data.<\/p>\n<p><b>Digital I\/O pins:<\/b> The holes on this side of the board are called the digital input\/output pins They are used to either sense the outside world (input) or control lights, sounds, or motors (output).<\/p>\n<p><b>TX\/RX pins:<\/b> Pin 0 and Pin 1 are special pins labeled TX and RX. They control how information is transmitted to and from a computer. It is best not to use them empty.<\/p>\n<p><b>ATmega328P, black chip:<\/b> The black chip in the middle of the board is an ATmega328P. This is the \u201cbrains\u201d of the Arduino: it interprets both the inputs \/ outputs and the programming code uploaded onto your Arduino.<\/p>\n<p><b>Power and ground pins:<\/b> All of the pins related to power are located here. You can use these pins to run power from your Arduino to your breadboard circuit.<\/p>\n<p><b>Analog pins:<\/b> These pins take sensor readings in a range of values (analog), rather than just sending whether something is just on or off (digital).<\/p>\n<h3>Settings in the software<\/h3>\n<p>We have seen a bit about the parts of the Arduino and we have seen that we program it through the Arduino software. Before we start programming the Arduino, we have to set a couple of settings in the software to ensure that the Arduino can communicate with your computer.<\/p>\n<p>Load the Arduino software. Once it is loaded, go to the To do this, go to the <b>Tools<\/b> menu, select <b>Board<\/b>. From the fly out menu, select <b>Arduino Uno\/Genuino<\/b>.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-82 size-full\" src=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/61\/2019\/04\/ch3-ide-select-board-screenshot-01.png\" alt=\"\" width=\"779\" height=\"471\" srcset=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/ch3-ide-select-board-screenshot-01.png 779w, https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/ch3-ide-select-board-screenshot-01-300x181.png 300w, https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/ch3-ide-select-board-screenshot-01-768x464.png 768w\" sizes=\"auto, (max-width: 779px) 85vw, 779px\" \/><\/p>\n<p>It is also necessary to specify a Serial Port for your Arduino to communicate with the computer. A Port is a channel of communication which connects your Arduino and the computer. On a Windows machine, go to the Tools Menu, select Port then select the COM port that is specified. It should look something like the screenshot below.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-83\" src=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/61\/2019\/04\/serial_com-1024x608.png\" alt=\"\" width=\"840\" height=\"499\" srcset=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/serial_com-1024x608.png 1024w, https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/serial_com-300x178.png 300w, https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/serial_com-768x456.png 768w, https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/serial_com.png 1200w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/p>\n<p>Once you have connected the Arduino to the computer and set the version and the port, you are ready to start programming the Arduino.<\/p>\n<header class=\"entry-header\">\n<h1 class=\"entry-title\">Programming the Arduino<\/h1>\n<\/header>\n<div class=\"entry-content\">\n<p>As we have seen, the <a href=\"https:\/\/www.arduino.cc\/en\/Main\/Software\">Arduino IDE<\/a> is free and can be downloaded from their site. Detailed instructions for installing and configuring the IDE can be found <a href=\"http:\/\/arduinotogo.com\/2016\/09\/09\/chapter-3-downloading-and-installing-the-software\/\">here<\/a>.<\/p>\n<h3>What\u2019s an IDE?<\/h3>\n<p>An IDE, or integrated development environment, is a software application that allows you to write code and test that code out in the programming language the IDE supports.<\/p>\n<p>If you have experience programming, you may have used another IDE to write, test, debug, and turn your code into something the computer understands. If you haven\u2019t, the Arduino IDE is a good place to start, as it is relatively simple and easy to understand.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-85\" src=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/61\/2019\/04\/ch3-codeflowchart-01.png\" alt=\"\" width=\"767\" height=\"234\" srcset=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/ch3-codeflowchart-01.png 767w, https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/ch3-codeflowchart-01-300x92.png 300w\" sizes=\"auto, (max-width: 767px) 85vw, 767px\" \/><\/p>\n<p>The Arduino team has designed an IDE for use with their devices that has the features you need. It has a built-in code editor, which is a program used to write the code files that you create when programming. You can test your code in the IDE and solve problems with the help of a message area that shows errors in your code and a console that provides more detail about the nature of these errors. It has buttons so you can check your code, save it, create a new code window, upload it to your Arduino and more.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-86\" src=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/61\/2019\/04\/ch3-blank-sketch-labelled-01-1.png\" alt=\"\" width=\"594\" height=\"584\" srcset=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/ch3-blank-sketch-labelled-01-1.png 594w, https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/ch3-blank-sketch-labelled-01-1-300x295.png 300w\" sizes=\"auto, (max-width: 594px) 85vw, 594px\" \/><\/p>\n<h3>The sketch<\/h3>\n<p>In the Arduino IDE, your program is called a <b>sketch<\/b>. The sketch is the basic unit of Arduino programming. The Arduino IDE supplies example sketches, that cover many of the things you can do with an Arduino. Let\u2019s open, save, then upload a simple sketch called Blink.<\/p>\n<p>First, connect your computer to the Arduino with a USB A-B cable. Open up the Arduino IDE. When it is open, go to the File Menu &gt; Examples &gt; 01.Basics &gt; Blink. This will open up the <b>Blink Sketch<\/b>.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-87\" src=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/61\/2019\/04\/ch3-menus-blink-sketch-01.png\" alt=\"\" width=\"391\" height=\"196\" srcset=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/ch3-menus-blink-sketch-01.png 391w, https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/ch3-menus-blink-sketch-01-300x150.png 300w\" sizes=\"auto, (max-width: 391px) 85vw, 391px\" \/><\/p>\n<p>Let\u2019s take a look at the buttons in the IDE, at the top of the sketch. The verify button checks your code for errors, the Upload button sends your code to the Arduino, New creates a new code window, Open opens a previously saved sketch and Save saves your sketch.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-88\" src=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/61\/2019\/04\/ch3-buttons-labelled.png\" alt=\"\" width=\"525\" height=\"220\" srcset=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/ch3-buttons-labelled.png 525w, https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/ch3-buttons-labelled-300x126.png 300w\" sizes=\"auto, (max-width: 525px) 85vw, 525px\" \/><\/p>\n<p>Here\u2019s a screenshot of the Blink sketch, with the three main sections annotated.<\/p>\n<p><b>Comments<\/b> are used to write notes to anyone who might read your code. This might be you, when you return to a sketch you created earlier, or others who you are sharing your code with. Comments have no effect whatsoever on how the computer interprets the text and are only there to remind you or clue someone else in on what you intended to do, or how the program functions as a whole.<\/p>\n<p>The <b>setup()<\/b> function is where you set initial conditions for your code. setup() happens only one time, when you run the code or turn on your Arduino.<\/p>\n<p>The <b>loop()<\/b> function is where you put code that you want to run over and over again.This is generally where all of your code that creates functionality lives. We will see, for example in the Blink sketch, the code that turns the LED on and off is here.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-90\" src=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/61\/2019\/04\/blink-sketch-01.png\" alt=\"\" width=\"646\" height=\"689\" srcset=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/blink-sketch-01.png 646w, https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/blink-sketch-01-281x300.png 281w\" sizes=\"auto, (max-width: 646px) 85vw, 646px\" \/><\/p>\n<h3>Save and rename the sketch!<\/h3>\n<p>After you\u2019ve taken a look at the Blink Sketch, save it and give it a new name. File Menu &gt; Save As &gt; MyBlink for example. You don\u2019t want to write over the example files and also you want to make adjustments to the example file to understand how the code is working. Saving early and often is always a good practice.<\/p>\n<h3>Verify and Upload<\/h3>\n<p>Let\u2019s verify the sketch, then upload to the Arduino. Click the Verify button to check your code. Even though this is an example sketch, it is good to get in the habit of checking your code. There will be a message in the bottom of the window that tells you a bit of information about your sketch. If there was a problem, it would also note it here. After verifying, you can upload your code, Make sure your Arduino is attached to the computer and that you have configured it properly. Then press the upload button. The LED on the Arduino near pin 13 should start blinking on and off.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-91\" src=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/61\/2019\/04\/ch3-verify-upload-sketch-01-1.png\" alt=\"\" width=\"733\" height=\"415\" srcset=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/ch3-verify-upload-sketch-01-1.png 733w, https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/ch3-verify-upload-sketch-01-1-300x170.png 300w\" sizes=\"auto, (max-width: 733px) 85vw, 733px\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-92\" src=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/61\/2019\/04\/ch3-uno-usb.png\" alt=\"\" width=\"394\" height=\"254\" srcset=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/ch3-uno-usb.png 394w, https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/ch3-uno-usb-300x193.png 300w\" sizes=\"auto, (max-width: 394px) 85vw, 394px\" \/><\/p>\n<h3>setup() and loop(): the guts of the code<\/h3>\n<p>Now let\u2019s look a bit closer at setup() and loop(). We have seen that setup happens once and loop happens over and over again.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-93\" src=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/61\/2019\/04\/ch3-program_flowchart-large-01.png\" alt=\"\" width=\"471\" height=\"447\" srcset=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/ch3-program_flowchart-large-01.png 471w, https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/ch3-program_flowchart-large-01-300x285.png 300w\" sizes=\"auto, (max-width: 471px) 85vw, 471px\" \/><\/p>\n<p>Inside of the <code>setup()<\/code> function, there is a line of instructions to the Arduino. It tells the Arduino to set the pin on the Arduino that is attached to the built-in LED on the board to be an output. In other words, <code>pinMode()<\/code> tells the Arduino to set <code>LED_BUILTIN<\/code> (pin 13 on the Arduino Uno) to be an <code>OUTPUT<\/code>.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-94\" src=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/61\/2019\/04\/setup-function-01.png\" alt=\"\" width=\"504\" height=\"197\" srcset=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/setup-function-01.png 504w, https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/setup-function-01-300x117.png 300w\" sizes=\"auto, (max-width: 504px) 85vw, 504px\" \/><\/p>\n<p>If we look at <code>loop()<\/code>, we see several more lines of instructions inside the function, These lines of code are what is turning the LED at pin 13 on and off. <code>digitalWrite()<\/code> sets <code>LED_BUILTIN<\/code> to <code>HIGH<\/code>, turning on the LED. <code>delay()<\/code> pauses the Arduino for <code>1000<\/code> milliseconds, or one second. The next line, <code>digitalWrite()<\/code>, sets the <code>LED_BUILTIN<\/code> <code>LOW<\/code>, or turns off the LED. This is followed by another <code>delay()<\/code>, which pauses the Arduino for <code>1000<\/code> or one second.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-95\" src=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/61\/2019\/04\/loop-code-blink-01.png\" alt=\"\" width=\"801\" height=\"184\" srcset=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/loop-code-blink-01.png 801w, https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/loop-code-blink-01-300x69.png 300w, https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/loop-code-blink-01-768x176.png 768w\" sizes=\"auto, (max-width: 801px) 85vw, 801px\" \/><\/p>\n<p>Try adjusting the amount of time that the LED is on and off. How do do that? Create a new pattern, perhaps a short time on, a long time off, a long time on. How would you do an SOS signal?<\/p>\n<header class=\"entry-header\">\n<h1 class=\"entry-title\">Building a circuit<\/h1>\n<\/header>\n<div class=\"entry-content\">\n<p>The circuit is the basic building block for any electronics project. A circuit includes all of the electronic components required for a task as well as wires or another material which will let the electricity flow between the connected components. Electronic circuits describe a complete and closed loop.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-97\" src=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/61\/2019\/04\/circuit_ill1-connected-components-arrows-01.png\" alt=\"\" width=\"401\" height=\"255\" srcset=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/circuit_ill1-connected-components-arrows-01.png 401w, https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/circuit_ill1-connected-components-arrows-01-300x191.png 300w\" sizes=\"auto, (max-width: 401px) 85vw, 401px\" \/><\/p>\n<p>There are two main parts that make up a circuit: conductive lines and components.What are\u00a0 components? LEDs, transistors, resistors, diodes, and all of the parts that control the flow of electricity or have another function in our circuit. Conductive lines are often metal threads or wires, as metal is a good conductor of electricity.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-98\" src=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/61\/2019\/04\/ch2-battery-led-resistor-connected-01.png\" alt=\"\" width=\"401\" height=\"130\" srcset=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/ch2-battery-led-resistor-connected-01.png 401w, https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/ch2-battery-led-resistor-connected-01-300x97.png 300w\" sizes=\"auto, (max-width: 401px) 85vw, 401px\" \/><\/p>\n<h3>The Breadboard<\/h3>\n<p>Components are often attached to each other on a <strong>solderless breadboard<\/strong>. What\u2019s that?\u00a0 A solderless breadboard has rows and columns of metal strips encased in plastic with a grid of holes called tie-points on the top. It allows us to quickly build circuits without having to permanently connect the components (by soldering, for example). Here\u2019s an \u201cx-ray view\u201d of a breadboard.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-99\" src=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/61\/2019\/04\/ch2-breadboard-x-ray-labelled-01.png\" alt=\"\" width=\"601\" height=\"337\" srcset=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/ch2-breadboard-x-ray-labelled-01.png 601w, https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/ch2-breadboard-x-ray-labelled-01-300x168.png 300w\" sizes=\"auto, (max-width: 601px) 85vw, 601px\" \/><\/p>\n<p>There is a pattern to how the metal strips are arranged on a breadboard. There are long strips along the left and right of many breadboards that are used to attach power and ground in a circuit. These long columns are called busses. The power bus is marked with a red plus sign, the ground bus with a green, blue or black minus sign.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-100\" src=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/61\/2019\/04\/ch-2-breadboard-top-labelled-01.png\" alt=\"\" width=\"456\" height=\"470\" srcset=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/ch-2-breadboard-top-labelled-01.png 456w, https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/ch-2-breadboard-top-labelled-01-291x300.png 291w\" sizes=\"auto, (max-width: 456px) 85vw, 456px\" \/><\/p>\n<p>This drawing shows how components are attached on a breadboard; the leads of the components are in the same row of tie-points.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-101\" src=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/61\/2019\/04\/ch2-components-in-boards-01.png\" alt=\"\" width=\"614\" height=\"252\" srcset=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/ch2-components-in-boards-01.png 614w, https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/ch2-components-in-boards-01-300x123.png 300w\" sizes=\"auto, (max-width: 614px) 85vw, 614px\" \/><\/p>\n<h3>Connecting the breadboard to an Arduino<\/h3>\n<p>How do you connect a breadboard to an Arduino to build a circuit? Let\u2019s build a circuit that connects a breadboard with an LED and a resistor to an Arduino.<\/p>\n<p>You will need these parts:<\/p>\n<ul>\n<li>Arduino Uno<\/li>\n<li>solderless breadboard<\/li>\n<li>USB A-B cable<\/li>\n<li>LED<\/li>\n<li>220 Ohm resistor<\/li>\n<li>jumpers<\/li>\n<\/ul>\n<h3>A note about LEDs<\/h3>\n<p>An LED (light emitting diode) has an orientation, or a positive and negative lead. An LED must be placed into a circuit properly, with the positive and negative lead oriented properly. How do you know what is the positive and negative side? The positive side has a longer lead. It is called the anode. The negative lead is shorter and called the anode. Also, the negative side of an LED often has a flatter side at the bulb.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-102\" src=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/61\/2019\/04\/led-01.png\" alt=\"\" width=\"192\" height=\"180\" \/><\/p>\n<h3>Start building!<\/h3>\n<p>Before you start building, make sure your Arduino <strong>is not attached to your computer<\/strong>. Never make changes to a circuit when power is attached.<\/p>\n<p>Attach jumpers from the 5V power pin on the Arduino. Your teacher should have some jumpers, they are pieces of wire used to make connections between components. You can make your own jumpers as well, by using 22 gauge hook-up wire and stripping the coating off the ends.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-103\" src=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/61\/2019\/04\/ch3-attach-jumpers-uno-board-01.png\" alt=\"\" width=\"769\" height=\"651\" srcset=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/ch3-attach-jumpers-uno-board-01.png 769w, https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/ch3-attach-jumpers-uno-board-01-300x254.png 300w, https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/ch3-attach-jumpers-uno-board-01-768x650.png 768w\" sizes=\"auto, (max-width: 769px) 85vw, 769px\" \/><\/p>\n<p>Next attach a jumper from pin 13 on the Arduino to a row of tie-points on the breadboard.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-104\" src=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/61\/2019\/04\/ch3-circuit-jumper-step-2-01.png\" alt=\"\" width=\"556\" height=\"372\" srcset=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/ch3-circuit-jumper-step-2-01.png 556w, https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/ch3-circuit-jumper-step-2-01-300x201.png 300w\" sizes=\"auto, (max-width: 556px) 85vw, 556px\" \/><\/p>\n<p>Place one end of a 220 Ohm resistor in the same row of tie-points as the jumper from pin 13, and the other end in a different row of tie-points.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-105\" src=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/61\/2019\/04\/ch3-circuit-resistor-step-3-01.png\" alt=\"\" width=\"556\" height=\"320\" srcset=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/ch3-circuit-resistor-step-3-01.png 556w, https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/ch3-circuit-resistor-step-3-01-300x173.png 300w\" sizes=\"auto, (max-width: 556px) 85vw, 556px\" \/><\/p>\n<p>Now let\u2019s place the LED in the breadboard. Put the anode (long leg) of the LED in the same row of tie-points as the resistor. Put the cathode (short leg) of the LED in another row of tie-points.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-106\" src=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/61\/2019\/04\/ch3-circuit-led-step-4-011.png\" alt=\"\" width=\"730\" height=\"320\" srcset=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/ch3-circuit-led-step-4-011.png 730w, https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/ch3-circuit-led-step-4-011-300x132.png 300w\" sizes=\"auto, (max-width: 730px) 85vw, 730px\" \/><\/p>\n<p>Now you have built the circuit! Hook up the Arduino to your computer. If you have already downloaded the Blink sketch, your code is loaded on the Arduino, and the LED should start blinking right away. If you haven\u2019t downloaded the Blink sketch, open up the Arduino software. The Blink sketch is at the File Menu &gt; Examples &gt; 01. Basics &gt; Blink.<\/p>\n<header class=\"entry-header\">\n<h1 class=\"entry-title\">Digital Input and\u00a0Output<\/h1>\n<\/header>\n<div class=\"entry-content\">\n<p>We use computers every day that have inputs and outputs. On a computer, the inputs might include keyboard and a mouse. The outputs are a screen and speakers. On the Arduino, a digital input might be a switch or button, the output an LED. Inputs send messages to the microcontroller\/Arduino. Outputs receive messages from the microcontroller\/Arduino.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-108\" src=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/61\/2019\/04\/ch5-inputs-01.png\" alt=\"\" width=\"355\" height=\"169\" srcset=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/ch5-inputs-01.png 355w, https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/ch5-inputs-01-300x143.png 300w\" sizes=\"auto, (max-width: 355px) 85vw, 355px\" \/><\/p>\n<p>Why do we want to add an input? Interactivity! So far, we have been able to control the LED by code, but it is not interactive, the Arduino turns the LED on and off with no user input. We will learn how to turn the LED with a button.<\/p>\n<p>It\u2019s important to understand that a digital input or output can only have 2 possible values, on and off. In digital inputs and outputs, <code>HIGH<\/code> = On = 1. <code>LOW<\/code> = Off = 0.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-109\" src=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/61\/2019\/04\/ch5-high-low-01.png\" alt=\"\" width=\"369\" height=\"319\" srcset=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/ch5-high-low-01.png 369w, https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/ch5-high-low-01-300x259.png 300w\" sizes=\"auto, (max-width: 369px) 85vw, 369px\" \/><\/p>\n<h3>Adding a button to a circuit<\/h3>\n<p>Let\u2019s start with the circuit we built to run the Blink sketch. Make sure that power and ground are connected to the busses on the breadboard. Pin 13 should be attached to a row of tie-points that has one lead of a 220 ohm resistor. The other end of the resistor should be attached to the anode (positive end) of the LED. The cathode (negative end) of the LED should be attached to a jumper going to ground.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-110\" src=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/61\/2019\/04\/ch5-basic-circuit-review-01.png\" alt=\"\" width=\"775\" height=\"477\" srcset=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/ch5-basic-circuit-review-01.png 775w, https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/ch5-basic-circuit-review-01-300x185.png 300w, https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/ch5-basic-circuit-review-01-768x473.png 768w\" sizes=\"auto, (max-width: 775px) 85vw, 775px\" \/><\/p>\n<p>Once you have made sure that your circuit is built properly, we will move on the adding a button.<\/p>\n<h3>Buttons and switches<\/h3>\n<p>There are a million different ways to trigger electronic devices or turn something on. Switches and similar on\/off devices activate everything from televisions, to music equipment, lights, even your kitchen appliances. How does a switch work?<\/p>\n<p>All switches work on the same basic principle: it either \u201ccloses the circuit\u201d and turns something on, or \u201copens the circuit\u201d and turns something off. When the switch is closed, electricity can flow through; it cannot flow through when the switch is open. The schematic symbols for a switch illustrate how this works. (A schematic is a simplified drawing that uses symbols to represent the electrical relationships in a circuit.)<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-111\" src=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/61\/2019\/04\/ch5-button-schematics-labelled-01.png\" alt=\"\" width=\"646\" height=\"157\" srcset=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/ch5-button-schematics-labelled-01.png 646w, https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/ch5-button-schematics-labelled-01-300x73.png 300w\" sizes=\"auto, (max-width: 646px) 85vw, 646px\" \/><\/p>\n<p>We are using a momentary pushbutton switch in our circuit. When you hold down the button, it completes the circuit. When you let go, the switch opens up and the circuit is no longer complete.<\/p>\n<p>Here is a drawing and a schematic of the pushbutton:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-112\" src=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/61\/2019\/04\/ch5-button-pins-schematic-01.png\" alt=\"\" width=\"323\" height=\"481\" srcset=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/ch5-button-pins-schematic-01.png 323w, https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/ch5-button-pins-schematic-01-201x300.png 201w\" sizes=\"auto, (max-width: 323px) 85vw, 323px\" \/><\/p>\n<h3>Step by step: add button<\/h3>\n<p>Now let\u2019s place the button on the board. It will go over the trench in the breadboard.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-113\" src=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/61\/2019\/04\/ch5-add-button-detail-01.png\" alt=\"\" width=\"786\" height=\"445\" srcset=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/ch5-add-button-detail-01.png 786w, https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/ch5-add-button-detail-01-300x170.png 300w, https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/ch5-add-button-detail-01-768x435.png 768w\" sizes=\"auto, (max-width: 786px) 85vw, 786px\" \/><\/p>\n<p>Next we will add a jumper from the power bus to one of the leads of the pushbutton.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-114\" src=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/61\/2019\/04\/ch5-button-jumper-power-detail-01.png\" alt=\"\" width=\"684\" height=\"301\" srcset=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/ch5-button-jumper-power-detail-01.png 684w, https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/ch5-button-jumper-power-detail-01-300x132.png 300w\" sizes=\"auto, (max-width: 684px) 85vw, 684px\" \/><\/p>\n<p>Add a 10k resistor from the ground bus to the other side of the pushbutton.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-115\" src=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/61\/2019\/04\/ch5-button-add-resistor-01.png\" alt=\"\" width=\"658\" height=\"297\" srcset=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/ch5-button-add-resistor-01.png 658w, https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/ch5-button-add-resistor-01-300x135.png 300w\" sizes=\"auto, (max-width: 658px) 85vw, 658px\" \/><\/p>\n<p>The final step is to connect the pushbutton to the Arduino, Attach a jumper from pin 2 to the same row of tie-points that as the resistor and one of the leads of the pushbutton.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-117\" src=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/61\/2019\/04\/ch5-jumper-pin-button-01.png\" alt=\"\" width=\"710\" height=\"248\" srcset=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/ch5-jumper-pin-button-01.png 710w, https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/ch5-jumper-pin-button-01-300x105.png 300w\" sizes=\"auto, (max-width: 710px) 85vw, 710px\" \/><\/p>\n<p>Once you have added the jumper connecting the Arduino to the breadboard, you are ready to connect the Arduino to a computer and upload a script. Connect with a USB A-B cable.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-118\" src=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/61\/2019\/04\/ch5-open-verify-upload-sequence-01.png\" alt=\"\" width=\"780\" height=\"174\" srcset=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/ch5-open-verify-upload-sequence-01.png 780w, https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/ch5-open-verify-upload-sequence-01-300x67.png 300w, https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/ch5-open-verify-upload-sequence-01-768x171.png 768w\" sizes=\"auto, (max-width: 780px) 85vw, 780px\" \/><\/p>\n<p>Open up the Arduino IDE. Open this script: from the <strong>File Menu &gt; Examples &gt; 02.Digital &gt; Button<\/strong>. Save as, with a name like MyButton.<\/p>\n<p>Click the Verify Button to make sure there aren\u2019t any problems with your code or the connection or settings in the software. If all is well, then click the Upload button. Now try pressing the button. Your LED should turn on and off.<\/p>\n<p>While there may be adjustments depending on what type of device you are turning on or off, this procedure should work generally for any kind of digital input or output.<\/p>\n<header class=\"entry-header\">\n<h1 class=\"entry-title\">Analog Input and\u00a0Output<\/h1>\n<\/header>\n<div class=\"entry-content\">\n<p>We have seen that digital information only has two possibilities, on and off. Analog information, on the other hand can hold a range of possible values. We perceive the world as a stream of analog information via our eyes and ears and other senses. By using analog information with our Arduino, we can respond to the users\u2019 input in a more complex fashion. We can control the brightness of an LED, setting it to shine brightly, glow dimly, or show any range of values in between.<\/p>\n<p>Analog information is continuous and can hold a range of possible values. It is quite simple to attach sensors and variable resistors to the Arduino so we can capture information with a range of values, not just on and off. Some examples of sensors would be photoresistors, which capture information about light levels, or thermistors, which capture information about temperature. There are many, many types of sensors available that can give us information about the world around us that can be attached to the Arduino.<\/p>\n<p>We will learn how to add a potentiometer to a circuit to control the brightness of our LED, from the dimmest glow to the brightest.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-120\" src=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/61\/2019\/04\/ch6-circuit-pot-final-2-01.png\" alt=\"\" width=\"500\" height=\"449\" srcset=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/ch6-circuit-pot-final-2-01.png 500w, https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/ch6-circuit-pot-final-2-01-300x269.png 300w\" sizes=\"auto, (max-width: 500px) 85vw, 500px\" \/><\/p>\n<h3>What\u2019s a potentiometer?<\/h3>\n<p>A potentiometer, sometimes called a pot, is a knob or dial that can be turned to increase or decrease the amount of resistance depending on how far, and in which direction, it is turned. Potentiometers come in many sizes and shapes. We will be using a 10k ohm potentiometer in our circuit.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-121\" src=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/61\/2019\/04\/ch6-pot-schematic-symbol-01.png\" alt=\"\" width=\"577\" height=\"385\" srcset=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/ch6-pot-schematic-symbol-01.png 577w, https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/ch6-pot-schematic-symbol-01-300x200.png 300w\" sizes=\"auto, (max-width: 577px) 85vw, 577px\" \/><\/p>\n<p>In order to build our circuit, first we will make a basic circuit using an LED, a 220 Ohm resistor, some jumpers and an Arduino Uno. This is quite similar to the basic circuit we have used in our other examples, with one important difference. <b>The Arduino pin attached to the LED is pin 9, not pin 13.<\/b><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-122\" src=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/61\/2019\/04\/ch6-circuit-pot-step-1-01.png\" alt=\"\" width=\"758\" height=\"318\" srcset=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/ch6-circuit-pot-step-1-01.png 758w, https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/ch6-circuit-pot-step-1-01-300x126.png 300w\" sizes=\"auto, (max-width: 758px) 85vw, 758px\" \/><\/p>\n<p>Now we will attach the potentiometer. A potentiometer has 3 pins. In our circuit, we will attach the middle pin to a pin on the Arduino, one of the outer pins to the power bus, and the other outer pin to the ground bus. It doesn\u2019t matter which outer pin goes to power and which one to ground.<\/p>\n<p>We will place the potentiometer parallel to the trench as depicted in the drawing. Each pin of the potentiometer is in a separate row of tie points, with an empty tie point between each of the pins. Orient the potentiometer facing away from the Arduino, with the dial over the trench, as shown below. This will make it easier for you to reach the potentiometer to turn it and to integrate it into the rest of the circuit.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-123\" src=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/61\/2019\/04\/ch6-circuit-pot-step-2-01.png\" alt=\"\" width=\"583\" height=\"490\" srcset=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/ch6-circuit-pot-step-2-01.png 583w, https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/ch6-circuit-pot-step-2-01-300x252.png 300w\" sizes=\"auto, (max-width: 583px) 85vw, 583px\" \/><\/p>\n<p>Now we\u2019ll attach the potentiometer to the power and ground busses on the Arduino.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-124\" src=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/61\/2019\/04\/ch6-circuit-pot-step-3-01.png\" alt=\"\" width=\"693\" height=\"363\" srcset=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/ch6-circuit-pot-step-3-01.png 693w, https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/ch6-circuit-pot-step-3-01-300x157.png 300w\" sizes=\"auto, (max-width: 693px) 85vw, 693px\" \/><\/p>\n<p>Finally, we will attach the middle pin of the potentiometer to pin 9 on the Arduino.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-125\" src=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/61\/2019\/04\/ch6-circuit-pot-step-4-01-1.png\" alt=\"\" width=\"752\" height=\"355\" srcset=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/ch6-circuit-pot-step-4-01-1.png 752w, https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/ch6-circuit-pot-step-4-01-1-300x142.png 300w\" sizes=\"auto, (max-width: 752px) 85vw, 752px\" \/><\/p>\n<h3>Upload the sketch<\/h3>\n<p>Now that you\u2019ve built the circuit, attach your Arduino to a computer. From the <strong>File Menu &gt; Examples &gt; 03.Analog &gt; AnalogInOutSerial<\/strong>. Save the sketch, renaming it as something like <strong>MyAnalogInOutSerial<\/strong>. Click the Verify button, then click the Upload button. Turn the potentiometer. Your LED should go from dim to bright, depending on how far it is turned.<\/p>\n<h2>Using a photoresistor<\/h2>\n<p>Let\u2019s look at how to use a sensor to test something about conditions in a room. We\u2019ll look at a photocell, also known as a photoresistor. A photoresistor can test for light levels in a room. Before you start making adjustments to the circuit, make sure that it is not connected to a computer or other power source.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-126\" src=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/61\/2019\/04\/photocell-01.png\" alt=\"\" width=\"600\" height=\"278\" srcset=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/photocell-01.png 600w, https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/photocell-01-300x139.png 300w\" sizes=\"auto, (max-width: 600px) 85vw, 600px\" \/><\/p>\n<p>Setting up the circuit for a photoresistor is slightly more complicated than using a potentiometer. To set up this circuit, first take out the potentiometer from your breadboard. Then place the photocell, or photoresistor into the breadboard, with one end attached to pin A0. There is no polarity or direction in a photocell, you can place either one of the leads in that row of tie points. Place the other lead in another row of tie points.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-127\" src=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/61\/2019\/04\/circuit-add-photocell-01.png\" alt=\"\" width=\"685\" height=\"377\" srcset=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/circuit-add-photocell-01.png 685w, https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/circuit-add-photocell-01-300x165.png 300w\" sizes=\"auto, (max-width: 685px) 85vw, 685px\" \/><\/p>\n<p>Next we will attach the other lead to power with a jumper as shown in the drawing.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-128\" src=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/61\/2019\/04\/circuit-photocell-jumper-02.png\" alt=\"\" width=\"621\" height=\"363\" srcset=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/circuit-photocell-jumper-02.png 621w, https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/circuit-photocell-jumper-02-300x175.png 300w\" sizes=\"auto, (max-width: 621px) 85vw, 621px\" \/><\/p>\n<p>Add a 10K resistor to the circuit. One lead is in the same row of tie points as the jumper to pin A0 and one lead of the resistor. The other end of the resistor is in another row of tie points, and jumped to the ground bus.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-129\" src=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/61\/2019\/04\/photocell-circuit-resistor-03.png\" alt=\"\" width=\"671\" height=\"382\" srcset=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/photocell-circuit-resistor-03.png 671w, https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/photocell-circuit-resistor-03-300x171.png 300w\" sizes=\"auto, (max-width: 671px) 85vw, 671px\" \/><\/p>\n<p>You can attach the computer back to the Arduino now. If you have not made any changes to the code, you should be able to run the same sketch on the Uno as you downloaded and saved when you built the potentiometer circuit. If your hand is covering the photocell, the LED will be shine more dimly, the more light that shines on it, the brighter the LED will light up.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-130\" src=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/61\/2019\/04\/photocell-circuit-final-small-01.png\" alt=\"\" width=\"795\" height=\"743\" srcset=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/photocell-circuit-final-small-01.png 795w, https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/photocell-circuit-final-small-01-300x280.png 300w, https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-content\/uploads\/sites\/619\/2019\/04\/photocell-circuit-final-small-01-768x718.png 768w\" sizes=\"auto, (max-width: 795px) 85vw, 795px\" \/><\/p>\n<hr \/>\n<p><em>Most of the illustrations and text in this chapter are taken from Jody Culkin and Eric Hagan\u2019s book <a href=\"https:\/\/www.amazon.com\/Learn-Electronics-Arduino-Illustrated-Beginners\/dp\/1680453742\">\u201c<\/a><span id=\"productTitle\" class=\"a-size-extra-large\"><a href=\"https:\/\/www.amazon.com\/Learn-Electronics-Arduino-Illustrated-Beginners\/dp\/1680453742\">Learn Electronics with Arduino: An Illustrated Beginner\u2019s Guide to Physical Computing\u201d<\/a>. Some of these resources are also available for free at\u00a0<a href=\"http:\/\/arduinotogo.com\/\">arduinotogo.com<\/a>.<\/span><\/em><\/p>\n<\/div>\n<\/div>\n<hr \/>\n<h3><strong style=\"font-size: 23px\"><em>Further reading\/resources:\u00a0<\/em><\/strong><\/h3>\n<p>&nbsp;<\/p>\n<\/div>\n<\/div>\n<ul>\n<li>What is physical computing?\n<ul>\n<li><em><a href=\"https:\/\/www.theatlantic.com\/magazine\/archive\/2012\/07\/the-measured-man\/309018\/\">\u201cThe Measured Man\u201d <\/a>\u2013 article from the Atlantic<\/em><\/li>\n<li><em><a href=\"https:\/\/www.ted.com\/talks\/massimo_banzi_how_arduino_is_open_sourcing_imagination\">\u201cMassimo Banzi: How Arduino is open-Sourcing imagination\u201d<\/a> \u2013 TED talk<\/em><\/li>\n<li><em><a href=\"https:\/\/itp.nyu.edu\/physcomp\/\">Physical Computing page at ITP NYU<\/a><\/em><\/li>\n<\/ul>\n<\/li>\n<li>Using a Microcontroller\n<ul>\n<li><a href=\"http:\/\/arduinotogo.com\/category\/intro-chapter\/\"><em>Introduction to Arduino on Arduino to go<\/em><\/a><\/li>\n<li><a href=\"http:\/\/arduinotogo.com\/category\/chapter-1\/\"><em>Parts of the Arduino, plug it in, components and tools<\/em><\/a><\/li>\n<li><a href=\"https:\/\/www.arduino.cc\/\"><em>Arduino site<\/em><\/a><\/li>\n<li><a href=\"https:\/\/www.arduino.cc\/en\/Main\/Software\"><em>Download the IDE here<\/em><\/a><\/li>\n<\/ul>\n<\/li>\n<li>Building a circuit\n<ul>\n<li><a href=\"http:\/\/arduinotogo.com\/category\/chapter-2\/\">C<em>hapter 2 Arduino to go: The circuit<\/em><\/a><\/li>\n<li><a href=\"https:\/\/www.arduino.cc\/en\/Guide\/ArduinoUno\"><em>Getting started with the Arduino Uno<\/em><\/a><\/li>\n<\/ul>\n<\/li>\n<li>Digital Input and Output\n<ul>\n<li><a href=\"http:\/\/arduinotogo.com\/category\/chapter-5\/\"><em>Digital Input and Output on Arduino to go<\/em><\/a><\/li>\n<li><a href=\"https:\/\/itp.nyu.edu\/physcomp\/lessons\/microcontrollers\/digital-input-output\/\"><em>Digital Input and Output on the ITP NYU site<\/em><\/a><\/li>\n<\/ul>\n<\/li>\n<li>Analog Input and Output\n<ul>\n<li><a href=\"http:\/\/arduinotogo.com\/category\/chapter-6\/\"><em>Analog input and output on Arduino to go <\/em><\/a><\/li>\n<li><em><a href=\"https:\/\/itp.nyu.edu\/physcomp\/videos\/videos-sensors\/\">Videos about sensors on ITP NYU site<\/a><\/em><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>What is physical computing? Physical computing refers to the process of building physical interfaces that respond to the analog world. This is done by building circuits with micro controllers, wires, sensors, LEDs, motors etc. and controlling them with a piece of custom-made software (i.e: \u201cTurn the LED on when the number sent by the photocell &hellip; <a href=\"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/physical-computing\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Physical Computing&#8221;<\/span><\/a><\/p>\n","protected":false},"author":21,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"portfolio_post_id":0,"portfolio_citation":"","portfolio_annotation":"","openlab_post_visibility":"","footnotes":""},"class_list":["post-40","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-json\/wp\/v2\/pages\/40","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-json\/wp\/v2\/users\/21"}],"replies":[{"embeddable":true,"href":"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-json\/wp\/v2\/comments?post=40"}],"version-history":[{"count":14,"href":"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-json\/wp\/v2\/pages\/40\/revisions"}],"predecessor-version":[{"id":882,"href":"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-json\/wp\/v2\/pages\/40\/revisions\/882"}],"wp:attachment":[{"href":"https:\/\/openlab.bmcc.cuny.edu\/mmp460-1100\/wp-json\/wp\/v2\/media?parent=40"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}