{"id":71,"date":"2020-01-23T15:51:04","date_gmt":"2020-01-23T15:51:04","guid":{"rendered":"https:\/\/openlab.bmcc.cuny.edu\/mea211\/?page_id=71"},"modified":"2023-07-19T19:08:34","modified_gmt":"2023-07-19T19:08:34","slug":"digital-input-and-output","status":"publish","type":"page","link":"https:\/\/openlab.bmcc.cuny.edu\/mea-211\/digital-input-and-output\/","title":{"rendered":"Digital Input and Output"},"content":{"rendered":"<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-417 aligncenter\" src=\"https:\/\/mea211blog.files.wordpress.com\/2018\/04\/ch5-inputs-01.png\" alt=\"ch5-inputs-01\" width=\"355\" height=\"169\"><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-416 aligncenter\" src=\"https:\/\/mea211blog.files.wordpress.com\/2018\/04\/ch5-outputs-01.png\" alt=\"ch5-outputs-01\" width=\"318\" height=\"227\"><\/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&#8217;s 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.<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-421 aligncenter\" src=\"https:\/\/mea211blog.files.wordpress.com\/2018\/04\/ch5-high-low-01.png\" alt=\"ch5-high-low-01\" width=\"369\" height=\"319\"><\/p>\n<h3>Adding a button to a circuit<\/h3>\n<p>Let&#8217;s 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-427\" src=\"https:\/\/mea211blog.files.wordpress.com\/2018\/04\/ch5-basic-circuit-review-01.png\" alt=\"ch5-basic-circuit-review-01\" width=\"775\" height=\"477\"><\/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-444\" src=\"https:\/\/mea211blog.files.wordpress.com\/2018\/04\/ch5-button-schematics-labelled-01.png\" alt=\"ch5-button-schematics-labelled-01\" width=\"646\" height=\"157\"><\/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:<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-446\" src=\"https:\/\/mea211blog.files.wordpress.com\/2018\/04\/ch5-button-pins-schematic-01.png\" alt=\"ch5-button-pins-schematic-01\" width=\"323\" height=\"481\"><\/p>\n<h3>Step by step: add button<\/h3>\n<p>Now let&#8217;s 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-447\" src=\"https:\/\/mea211blog.files.wordpress.com\/2018\/04\/ch5-add-button-detail-01.png\" alt=\"ch5-add-button-detail-01\" width=\"786\" height=\"445\"><\/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-449\" src=\"https:\/\/mea211blog.files.wordpress.com\/2018\/04\/ch5-button-jumper-power-detail-01.png\" alt=\"ch5-button-jumper-power-detail-01\" width=\"684\" height=\"301\"><\/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-450\" src=\"https:\/\/mea211blog.files.wordpress.com\/2018\/04\/ch5-button-add-resistor-01.png\" alt=\"ch5-button-add-resistor-01\" width=\"658\" height=\"297\"><\/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-451\" src=\"https:\/\/mea211blog.files.wordpress.com\/2018\/04\/ch5-jumper-pin-button-01.png\" alt=\"ch5-jumper-pin-button-01\" width=\"710\" height=\"248\"><\/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-453\" src=\"https:\/\/mea211blog.files.wordpress.com\/2018\/04\/ch5-open-verify-upload-sequence-01.png\" alt=\"ch5-open-verify-upload-sequence-01\" width=\"780\" height=\"174\"><\/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&#8217;t 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<h3><em><strong>Further reading\/resources<\/strong><\/em><\/h3>\n<ul>\n<li><a href=\"http:\/\/arduinotogo.com\/category\/chapter-5\/\"><strong><em>Digital Input and Output on Arduino to go<\/em><\/strong><\/a><\/li>\n<li><a href=\"https:\/\/itp.nyu.edu\/physcomp\/lessons\/microcontrollers\/digital-input-output\/\"><em><strong>Digital Input and Output on the ITP NYU site<\/strong><\/em><\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<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 &hellip; <a href=\"https:\/\/openlab.bmcc.cuny.edu\/mea-211\/digital-input-and-output\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Digital Input and Output&#8221;<\/span><\/a><\/p>\n","protected":false},"author":184,"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-71","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/openlab.bmcc.cuny.edu\/mea-211\/wp-json\/wp\/v2\/pages\/71","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/openlab.bmcc.cuny.edu\/mea-211\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/openlab.bmcc.cuny.edu\/mea-211\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/openlab.bmcc.cuny.edu\/mea-211\/wp-json\/wp\/v2\/users\/184"}],"replies":[{"embeddable":true,"href":"https:\/\/openlab.bmcc.cuny.edu\/mea-211\/wp-json\/wp\/v2\/comments?post=71"}],"version-history":[{"count":2,"href":"https:\/\/openlab.bmcc.cuny.edu\/mea-211\/wp-json\/wp\/v2\/pages\/71\/revisions"}],"predecessor-version":[{"id":388,"href":"https:\/\/openlab.bmcc.cuny.edu\/mea-211\/wp-json\/wp\/v2\/pages\/71\/revisions\/388"}],"wp:attachment":[{"href":"https:\/\/openlab.bmcc.cuny.edu\/mea-211\/wp-json\/wp\/v2\/media?parent=71"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}