{"id":640,"date":"2015-02-19T05:51:28","date_gmt":"2015-02-19T05:51:28","guid":{"rendered":"https:\/\/www.courses.tegabrain.com\/SS15\/?page_id=640"},"modified":"2015-03-05T17:07:06","modified_gmt":"2015-03-05T17:07:06","slug":"arduino-1","status":"publish","type":"page","link":"https:\/\/www.courses.tegabrain.com\/SS15\/?page_id=640","title":{"rendered":"ARDUINO 1: Intro"},"content":{"rendered":"<h3>DOWNLOAD INSTALL AND SETUP<\/h3>\n<ul>\n<li>Follow the download and installation instructions for getting the\u00a0<a href=\"http:\/\/arduino.cc\/en\/Guide\/HomePage\">Arduino software here.<\/a><\/li>\n<li>If you are having difficulty getting your computer to recognize the Arduino,\u00a0you may\u00a0need to manually install a driver on your computer &#8211; <a href=\"http:\/\/www.ftdichip.com\/Drivers\/VCP.htm\">download here.<\/a>\u00a0If you have a mac and are confused as to whether your computer is 32bit or 64bit architecture. See this <a href=\"http:\/\/support.apple.com\/en-us\/HT3696\">guide here.<\/a><\/li>\n<li>Download this circuit design software Fritzing here:\u00a0<a href=\"http:\/\/fritzing.org\/download\/\">http:\/\/fritzing.org\/download\/<\/a><\/li>\n<\/ul>\n<h3>WHAT IS IT?<\/h3>\n<ul>\n<li>Arduino is a single chip computer on a single micro-controller board.<\/li>\n<li>Atmel Microcontroller (Uno= AVR atmega 328) with bootloader.<\/li>\n<li>Separate ATmega controller deals with serial communication. (Except on Leonardo and a few other boards which operate on only one microcontroller).<\/li>\n<li>We are using the <a href=\"http:\/\/arduino.cc\/en\/Main\/ArduinoBoardUno\">uno board<\/a>.<\/li>\n<\/ul>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone\" src=\"http:\/\/arduino.cc\/en\/uploads\/Main\/ArduinoUno_R3_Front.jpg\" alt=\"\" width=\"1600\" height=\"1052\" \/><\/p>\n<h3>COMPONENTS AND PINS:<\/h3>\n<p><a href=\"https:\/\/www.courses.tegabrain.com\/SS15\/wp-content\/uploads\/2015\/02\/Screen-Shot-2015-02-19-at-6.39.05-PM.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-690 size-medium\" src=\"https:\/\/www.courses.tegabrain.com\/SS15\/wp-content\/uploads\/2015\/02\/Screen-Shot-2015-02-19-at-6.39.05-PM-300x260.png\" alt=\"Screen Shot 2015-02-19 at 6.39.05 PM\" width=\"300\" height=\"260\" srcset=\"https:\/\/www.courses.tegabrain.com\/SS15\/wp-content\/uploads\/2015\/02\/Screen-Shot-2015-02-19-at-6.39.05-PM-300x260.png 300w, https:\/\/www.courses.tegabrain.com\/SS15\/wp-content\/uploads\/2015\/02\/Screen-Shot-2015-02-19-at-6.39.05-PM-535x463.png 535w, https:\/\/www.courses.tegabrain.com\/SS15\/wp-content\/uploads\/2015\/02\/Screen-Shot-2015-02-19-at-6.39.05-PM.png 748w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p><a href=\"https:\/\/www.courses.tegabrain.com\/SS15\/wp-content\/uploads\/2015\/02\/Screen-Shot-2015-02-19-at-6.38.56-PM.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-691 size-medium\" src=\"https:\/\/www.courses.tegabrain.com\/SS15\/wp-content\/uploads\/2015\/02\/Screen-Shot-2015-02-19-at-6.38.56-PM-300x262.png\" alt=\"Screen Shot 2015-02-19 at 6.38.56 PM\" width=\"300\" height=\"262\" srcset=\"https:\/\/www.courses.tegabrain.com\/SS15\/wp-content\/uploads\/2015\/02\/Screen-Shot-2015-02-19-at-6.38.56-PM-300x262.png 300w, https:\/\/www.courses.tegabrain.com\/SS15\/wp-content\/uploads\/2015\/02\/Screen-Shot-2015-02-19-at-6.38.56-PM-535x467.png 535w, https:\/\/www.courses.tegabrain.com\/SS15\/wp-content\/uploads\/2015\/02\/Screen-Shot-2015-02-19-at-6.38.56-PM.png 788w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p><a href=\"https:\/\/www.courses.tegabrain.com\/SS15\/wp-content\/uploads\/2015\/02\/Screen-Shot-2015-02-19-at-6.38.49-PM1.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-693 size-medium\" src=\"https:\/\/www.courses.tegabrain.com\/SS15\/wp-content\/uploads\/2015\/02\/Screen-Shot-2015-02-19-at-6.38.49-PM1-300x269.png\" alt=\"Screen Shot 2015-02-19 at 6.38.49 PM\" width=\"300\" height=\"269\" srcset=\"https:\/\/www.courses.tegabrain.com\/SS15\/wp-content\/uploads\/2015\/02\/Screen-Shot-2015-02-19-at-6.38.49-PM1-300x269.png 300w, https:\/\/www.courses.tegabrain.com\/SS15\/wp-content\/uploads\/2015\/02\/Screen-Shot-2015-02-19-at-6.38.49-PM1-535x480.png 535w, https:\/\/www.courses.tegabrain.com\/SS15\/wp-content\/uploads\/2015\/02\/Screen-Shot-2015-02-19-at-6.38.49-PM1.png 738w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<h3>How is it different from other small computers?<\/h3>\n<p><a href=\"https:\/\/www.courses.tegabrain.com\/SS15\/wp-content\/uploads\/2015\/02\/Screen-Shot-2015-02-19-at-11.59.51-AM.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-646 size-large\" src=\"https:\/\/www.courses.tegabrain.com\/SS15\/wp-content\/uploads\/2015\/02\/Screen-Shot-2015-02-19-at-11.59.51-AM-1024x673.png\" alt=\"Screen Shot 2015-02-19 at 11.59.51 AM\" width=\"980\" height=\"644\" srcset=\"https:\/\/www.courses.tegabrain.com\/SS15\/wp-content\/uploads\/2015\/02\/Screen-Shot-2015-02-19-at-11.59.51-AM-1024x673.png 1024w, https:\/\/www.courses.tegabrain.com\/SS15\/wp-content\/uploads\/2015\/02\/Screen-Shot-2015-02-19-at-11.59.51-AM-300x197.png 300w, https:\/\/www.courses.tegabrain.com\/SS15\/wp-content\/uploads\/2015\/02\/Screen-Shot-2015-02-19-at-11.59.51-AM-535x352.png 535w, https:\/\/www.courses.tegabrain.com\/SS15\/wp-content\/uploads\/2015\/02\/Screen-Shot-2015-02-19-at-11.59.51-AM.png 1290w\" sizes=\"(max-width: 980px) 100vw, 980px\" \/><\/a><\/p>\n<p>Comparison article:<\/p>\n<p><a href=\"http:\/\/makezine.com\/2013\/04\/15\/arduino-uno-vs-beaglebone-vs-raspberry-pi\/\">http:\/\/makezine.com\/2013\/04\/15\/arduino-uno-vs-beaglebone-vs-raspberry-pi\/<\/a><\/p>\n<h3>POWER<\/h3>\n<ul>\n<li>Input Voltage on Jack: between 6 and 20v (7-12v recommended)<\/li>\n<li>The board is 5v regulated- digital standard.<\/li>\n<li>There is also a 3.3v power pin. &#8211; Lower energy consumption.\u00a0 Good for lower voltage \/ small battery projects<\/li>\n<li>Mixing 5v and 3.3v can be tricky.<\/li>\n<li>Arduino uses 5mA-25mA current on its own.\u00a0 4 AA pack (6v) will power approx. 60hr (assuming 1500mAH\/25mA AA)<\/li>\n<\/ul>\n<h3>LANGUAGE<\/h3>\n<ul>\n<li>More C than C++\u00a0 (C yields smaller code to fix 32k flash storage). Uses the same structure and approach as Processing. If you know processing the transition to Arduino is made easier.<\/li>\n<li>Language is here: <a href=\"http:\/\/arduino.cc\/en\/Reference\/HomePage\">http:\/\/arduino.cc\/en\/Reference\/HomePage<\/a><\/li>\n<li><span class=\"author-p-251586\">Great PDF by Natalie Freed: <\/span><span class=\"author-p-251586 url\"><a href=\"http:\/\/sites.lwhs.org\/techarts\/files\/2013\/10\/arduino-cheat-sheet-1-2.pdf\">http:\/\/sites.lwhs.org\/techarts\/files\/2013\/10\/arduino-cheat-sheet-1-2.pdf<\/a><\/span><\/li>\n<\/ul>\n<p>Don&#8217;t ignore the learning power of the example files!!!! And for help and instruction on what the corresponding circuits look like, see the fritzing software examples.<\/p>\n<p><a href=\"https:\/\/www.courses.tegabrain.com\/SS15\/wp-content\/uploads\/2015\/02\/Screen-Shot-2015-02-19-at-12.04.09-PM.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-647 size-medium\" src=\"https:\/\/www.courses.tegabrain.com\/SS15\/wp-content\/uploads\/2015\/02\/Screen-Shot-2015-02-19-at-12.04.09-PM-300x228.png\" alt=\"Screen Shot 2015-02-19 at 12.04.09 PM\" width=\"300\" height=\"228\" srcset=\"https:\/\/www.courses.tegabrain.com\/SS15\/wp-content\/uploads\/2015\/02\/Screen-Shot-2015-02-19-at-12.04.09-PM-300x228.png 300w, https:\/\/www.courses.tegabrain.com\/SS15\/wp-content\/uploads\/2015\/02\/Screen-Shot-2015-02-19-at-12.04.09-PM-1024x779.png 1024w, https:\/\/www.courses.tegabrain.com\/SS15\/wp-content\/uploads\/2015\/02\/Screen-Shot-2015-02-19-at-12.04.09-PM-535x407.png 535w, https:\/\/www.courses.tegabrain.com\/SS15\/wp-content\/uploads\/2015\/02\/Screen-Shot-2015-02-19-at-12.04.09-PM.png 1336w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<h3>BASIC SKETCH STRUCTURE:<\/h3>\n<p><a href=\"https:\/\/www.courses.tegabrain.com\/SS15\/wp-content\/uploads\/2015\/02\/Screen-Shot-2015-02-19-at-1.05.35-PM.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-660 size-medium\" src=\"https:\/\/www.courses.tegabrain.com\/SS15\/wp-content\/uploads\/2015\/02\/Screen-Shot-2015-02-19-at-1.05.35-PM-249x300.png\" alt=\"Screen Shot 2015-02-19 at 1.05.35 PM\" width=\"249\" height=\"300\" srcset=\"https:\/\/www.courses.tegabrain.com\/SS15\/wp-content\/uploads\/2015\/02\/Screen-Shot-2015-02-19-at-1.05.35-PM-249x300.png 249w, https:\/\/www.courses.tegabrain.com\/SS15\/wp-content\/uploads\/2015\/02\/Screen-Shot-2015-02-19-at-1.05.35-PM-849x1024.png 849w, https:\/\/www.courses.tegabrain.com\/SS15\/wp-content\/uploads\/2015\/02\/Screen-Shot-2015-02-19-at-1.05.35-PM-535x645.png 535w, https:\/\/www.courses.tegabrain.com\/SS15\/wp-content\/uploads\/2015\/02\/Screen-Shot-2015-02-19-at-1.05.35-PM.png 1020w\" sizes=\"(max-width: 249px) 100vw, 249px\" \/><\/a><\/p>\n<h3>TROUBLESHOOTING?<\/h3>\n<p>Trouble uploading to the board? Always check the following things:<\/p>\n<ul>\n<li>Is the board plugged in?<\/li>\n<li>Are the power indicator lights on the board on?<\/li>\n<li>In the Arduino IDE &#8211; go to the Tools &gt; Board. Check that the UNO board is selected.<\/li>\n<li>Then also in Tools&gt;Port check that dev\/cu.usbmodem641 (Arduino Uno) is selected from the list of ports. If it is not, you have a problem reading from the USB port of your computer. If this is the first time you are running Arduino you may need to install a driver. See the <a href=\"http:\/\/arduino.cc\/en\/Guide\/HomePage\">install guide here.\u00a0<\/a><\/li>\n<li>Check you code compiles. Click the tick button to make sure you do not have errors in your program.<\/li>\n<\/ul>\n<h3>EXERCISES<\/h3>\n<p>We will do some basic circuits here. There are also excellent examples in the guides that come with your kits. See the online version here:<\/p>\n<p><a href=\"http:\/\/ardx.org\/src\/guide\/2\/ARDX-EG-ADAF-WEB.pdf\u00a0\">http:\/\/ardx.org\/src\/guide\/2\/ARDX-EG-ADAF-WEB.pdf\u00a0<\/a><\/p>\n<h3>EXERCISE 1: BLINK EXAMPLE (10min)<\/h3>\n<p>Set up an LED like follows:<\/p>\n<p><a href=\"https:\/\/www.courses.tegabrain.com\/SS15\/wp-content\/uploads\/2015\/02\/Blinking-LED.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-729\" src=\"https:\/\/www.courses.tegabrain.com\/SS15\/wp-content\/uploads\/2015\/02\/Blinking-LED-294x300.png\" alt=\"Blinking-LED\" width=\"294\" height=\"300\" srcset=\"https:\/\/www.courses.tegabrain.com\/SS15\/wp-content\/uploads\/2015\/02\/Blinking-LED-294x300.png 294w, https:\/\/www.courses.tegabrain.com\/SS15\/wp-content\/uploads\/2015\/02\/Blinking-LED-535x545.png 535w, https:\/\/www.courses.tegabrain.com\/SS15\/wp-content\/uploads\/2015\/02\/Blinking-LED.png 795w\" sizes=\"(max-width: 294px) 100vw, 294px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>Grab the code from the Arduino example files.<\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/www.courses.tegabrain.com\/SS15\/wp-content\/uploads\/2015\/02\/Screen-Shot-2015-02-19-at-12.14.49-PM.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-650 size-large\" src=\"https:\/\/www.courses.tegabrain.com\/SS15\/wp-content\/uploads\/2015\/02\/Screen-Shot-2015-02-19-at-12.14.49-PM-1024x297.png\" alt=\"Screen Shot 2015-02-19 at 12.14.49 PM\" width=\"980\" height=\"284\" srcset=\"https:\/\/www.courses.tegabrain.com\/SS15\/wp-content\/uploads\/2015\/02\/Screen-Shot-2015-02-19-at-12.14.49-PM-1024x297.png 1024w, https:\/\/www.courses.tegabrain.com\/SS15\/wp-content\/uploads\/2015\/02\/Screen-Shot-2015-02-19-at-12.14.49-PM-300x87.png 300w, https:\/\/www.courses.tegabrain.com\/SS15\/wp-content\/uploads\/2015\/02\/Screen-Shot-2015-02-19-at-12.14.49-PM-535x155.png 535w, https:\/\/www.courses.tegabrain.com\/SS15\/wp-content\/uploads\/2015\/02\/Screen-Shot-2015-02-19-at-12.14.49-PM.png 1440w\" sizes=\"(max-width: 980px) 100vw, 980px\" \/><\/a><\/p>\n<p><strong><span class=\"author-p-251586 i\"><i>&gt;&gt;&gt;&gt;&gt;Important: <\/i>PinMode declares<\/span><span class=\"author-p-251586\">\u00a0PINS as input or output in setup.\u00a0<\/span><\/strong><\/p>\n<pre lang=\"java\"> \r\nvoid setup() {                \r\n  \/\/ initialize the digital pin as an output.\r\n  pinMode(13, OUTPUT);     \r\n}\r\n<\/pre>\n<p>digitalWrite sets pin HIGH or LOW (this means they have a charge or they don&#8217;t ie. they are on or off.)<\/p>\n<pre lang=\"java\">  digitalWrite(13, HIGH);   \/\/ turn the LED on (HIGH is the voltage level)\r\n<\/pre>\n<h3>CHALLENGES<\/h3>\n<ul>\n<li>1.\u00a0 We can use two other alternatives to HIGH and LOW.\u00a0 What are they?<\/li>\n<li><span class=\"author-p-251586\">2. Port the external LED to another pin and change the rate of flash.<\/span><\/li>\n<li><span class=\"author-p-251586\">3. What&#8217;s the fastest you can flash an external LED and still see the flashing?\u00a0 (try changing delay to a float variable to get super precise).<\/span><\/li>\n<li>4. What if we want the light to flash two times when the microcontroller starts up when we turn it on and then never again until restart?\u00a0 What&#8217;s the easiest solution ?<\/li>\n<\/ul>\n<h3>Advice:<\/h3>\n<p>Blink is always the first program to run on a new Arduino or an Arduino that you are unsure of its health.\u00a0 Built in LEDs can vary.\u00a0 You can always blink the TX LED (usually PIN 1) if you are not sending data back to the host computer.<\/p>\n<p>&nbsp;<\/p>\n<h3>EXERCISE 2: Serial output for debugging. \u00a0(10min)<\/h3>\n<pre lang=\"java\">void setup() {\r\n\/\/ initialize serial communication at 9600 bits per second:\r\n Serial.begin(9600);\r\n}\r\n\r\nvoid loop() {\r\nSerial.print(\"I've been running for \");\r\nSerial.print(millis());\u00a0\r\nSerial.println(\" mS\");\r\n}\r\n<\/pre>\n<p><i>Important: <\/i><\/p>\n<ul>\n<li>Declaring the<span class=\"author-p-251586\">\u00a0baud rate. This is the rate at which your arduino sends data to the computer. The baud rate declared in your code must match the baud rate you select in your serial monitor.<\/span><\/li>\n<li>More information is here:\u00a0<a href=\"http:\/\/arduino.cc\/en\/Serial\/begin\">http:\/\/arduino.cc\/en\/Serial\/begin<\/a><\/li>\n<li>To output data to the serial port we use the functions print(); or println().\u00a0<a href=\"http:\/\/arduino.cc\/en\/Serial\/Print\">http:\/\/arduino.cc\/en\/Serial\/Print<\/a><\/li>\n<li>print prints data in one line, println includes carriage return!<\/li>\n<\/ul>\n<div id=\"magicdomid115\" class=\"ace-line gutter-author-p-251586 emptyGutter\" data-author-initials=\"AK\" data-author-name=\"Andrew K\" data-author-link=\"\/ep\/profile\/Fff9BhWVGtc\"><span class=\"author-p-251586\">Challenges:<\/span><\/div>\n<div id=\"magicdomid116\" class=\"ace-line gutter-author-p-251586 line-list-type-indent emptyGutter\" data-author-initials=\"AK\" data-author-name=\"Andrew K\" data-author-link=\"\/ep\/profile\/Fff9BhWVGtc\">\n<ul class=\"listtype-indent listindent1 list-indent1\">\n<li><span class=\"author-p-251586\">1.\u00a0<\/span> <span class=\"author-p-251586\">Print the state of an LED<\/span><\/li>\n<\/ul>\n<\/div>\n<div id=\"magicdomid117\" class=\"ace-line gutter-author-p-251586 line-list-type-indent emptyGutter\" data-author-initials=\"AK\" data-author-name=\"Andrew K\" data-author-link=\"\/ep\/profile\/Fff9BhWVGtc\">\n<ul class=\"listtype-indent listindent1 list-indent1\">\n<li><span class=\"author-p-251586\">2. Print runtime in millis, seconds, minutes, hours<\/span><\/li>\n<\/ul>\n<h3>EXERCISE\u00a03: control external LED with PWM (pulse-duration modulation)<\/h3>\n<p>If we want to have an LED fade, we need to be able to send it the equivalent of an analog signal, so this means we want to vary its voltage gradually, not in the on\/off mode of a digital signal.<\/p>\n<div class=\"ace-line gutter-author-p-251586 emptyGutter toc-entry\" data-author-initials=\"AK\" data-author-name=\"Andrew K\" data-author-link=\"\/ep\/profile\/Fff9BhWVGtc\"><\/div>\n<div id=\"magicdomid120\" class=\"ace-line gutter-author-p-251586 emptyGutter\" data-author-initials=\"AK\" data-author-name=\"Andrew K\" data-author-link=\"\/ep\/profile\/Fff9BhWVGtc\"><span class=\"author-p-251586 u\"><span style=\"text-decoration: underline;\">Analog vs Digital\u00a0<\/span><\/span><\/div>\n<div class=\"ace-line gutter-author-p-251586 emptyGutter\" data-author-initials=\"AK\" data-author-name=\"Andrew K\" data-author-link=\"\/ep\/profile\/Fff9BhWVGtc\"><a href=\"https:\/\/www.courses.tegabrain.com\/SS15\/wp-content\/uploads\/2015\/02\/hackpad.com_Q2FrBtpZBVA_p.251586_1418051699703_analog_digital.jpg\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-652\" src=\"https:\/\/www.courses.tegabrain.com\/SS15\/wp-content\/uploads\/2015\/02\/hackpad.com_Q2FrBtpZBVA_p.251586_1418051699703_analog_digital.jpg\" alt=\"hackpad.com_Q2FrBtpZBVA_p.251586_1418051699703_analog_digital\" width=\"385\" height=\"379\" srcset=\"https:\/\/www.courses.tegabrain.com\/SS15\/wp-content\/uploads\/2015\/02\/hackpad.com_Q2FrBtpZBVA_p.251586_1418051699703_analog_digital.jpg 385w, https:\/\/www.courses.tegabrain.com\/SS15\/wp-content\/uploads\/2015\/02\/hackpad.com_Q2FrBtpZBVA_p.251586_1418051699703_analog_digital-300x295.jpg 300w\" sizes=\"(max-width: 385px) 100vw, 385px\" \/><\/a><\/div>\n<h3>What is PWM (pulse width modulation)?<\/h3>\n<p>Pulse width modulation is the way that arduino imitates an analog signal. So if we want an LED to light up at 1\/4 strength, we send it a digital signal that is flickering on and off more rapidly than we can see with our eyes. If the digital signal is on for 25% or the time and off for 75% of the time, then we perceive it as on at 25% strength. This simulation of an analogy signal is called Pulse Width Modulation. See in the graphs below and the tutorial for more info.<\/p>\n<div id=\"magicdomid124\" class=\"ace-line gutter-author-p-251586 emptyGutter\" data-author-initials=\"AK\" data-author-name=\"Andrew K\" data-author-link=\"\/ep\/profile\/Fff9BhWVGtc\"><span class=\"author-p-251586 url\"><a href=\"http:\/\/arduino.cc\/en\/Tutorial\/PWM\">http:\/\/arduino.cc\/en\/Tutorial\/PWM<\/a><\/span><\/div>\n<div class=\"ace-line gutter-author-p-251586 emptyGutter\" data-author-initials=\"AK\" data-author-name=\"Andrew K\" data-author-link=\"\/ep\/profile\/Fff9BhWVGtc\">\n<p><a href=\"https:\/\/www.courses.tegabrain.com\/SS15\/wp-content\/uploads\/2015\/02\/hackpad.com_Q2FrBtpZBVA_p.251586_1418051721541_pwm.gif\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-653\" src=\"https:\/\/www.courses.tegabrain.com\/SS15\/wp-content\/uploads\/2015\/02\/hackpad.com_Q2FrBtpZBVA_p.251586_1418051721541_pwm.gif\" alt=\"hackpad.com_Q2FrBtpZBVA_p.251586_1418051721541_pwm\" width=\"400\" height=\"438\" \/><\/a><\/p>\n<\/div>\n<h3>PWM &#8211; FADE EXERCISE<\/h3>\n<p>Build this circuit on the Breadboard .<\/p>\n<div class=\"ace-line gutter-author-p-251586 emptyGutter\" data-author-initials=\"AK\" data-author-name=\"Andrew K\" data-author-link=\"\/ep\/profile\/Fff9BhWVGtc\"><a href=\"https:\/\/www.courses.tegabrain.com\/SS15\/wp-content\/uploads\/2015\/02\/simplefade_pin9_schem.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-654\" src=\"https:\/\/www.courses.tegabrain.com\/SS15\/wp-content\/uploads\/2015\/02\/simplefade_pin9_schem.png\" alt=\"simplefade_pin9_schem\" width=\"434\" height=\"523\" srcset=\"https:\/\/www.courses.tegabrain.com\/SS15\/wp-content\/uploads\/2015\/02\/simplefade_pin9_schem.png 434w, https:\/\/www.courses.tegabrain.com\/SS15\/wp-content\/uploads\/2015\/02\/simplefade_pin9_schem-249x300.png 249w\" sizes=\"(max-width: 434px) 100vw, 434px\" \/><\/a><\/div>\n<div class=\"ace-line gutter-author-p-251586 emptyGutter\" data-author-initials=\"AK\" data-author-name=\"Andrew K\" data-author-link=\"\/ep\/profile\/Fff9BhWVGtc\"><\/div>\n<div class=\"ace-line gutter-author-p-251586 emptyGutter\" data-author-initials=\"AK\" data-author-name=\"Andrew K\" data-author-link=\"\/ep\/profile\/Fff9BhWVGtc\"><\/div>\n<p>Argrhhh! Wondering what that weird diagram is? Well electrical components have special symbols. Here&#8217;s a starting guide:<\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/www.courses.tegabrain.com\/SS15\/wp-content\/uploads\/2015\/02\/Screen-Shot-2015-02-19-at-12.40.21-PM.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-656\" src=\"https:\/\/www.courses.tegabrain.com\/SS15\/wp-content\/uploads\/2015\/02\/Screen-Shot-2015-02-19-at-12.40.21-PM.png\" alt=\"Screen Shot 2015-02-19 at 12.40.21 PM\" width=\"990\" height=\"786\" srcset=\"https:\/\/www.courses.tegabrain.com\/SS15\/wp-content\/uploads\/2015\/02\/Screen-Shot-2015-02-19-at-12.40.21-PM.png 990w, https:\/\/www.courses.tegabrain.com\/SS15\/wp-content\/uploads\/2015\/02\/Screen-Shot-2015-02-19-at-12.40.21-PM-300x238.png 300w, https:\/\/www.courses.tegabrain.com\/SS15\/wp-content\/uploads\/2015\/02\/Screen-Shot-2015-02-19-at-12.40.21-PM-535x425.png 535w\" sizes=\"(max-width: 990px) 100vw, 990px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<div class=\"ace-line gutter-author-p-251586 emptyGutter\" data-author-initials=\"AK\" data-author-name=\"Andrew K\" data-author-link=\"\/ep\/profile\/Fff9BhWVGtc\">\n<p>Still confused by that diagram? This is where Fritzing comes in handy. Most of the\u00a0Arduino example circuits can be looked up in the Fritzing software. This makes it much easier to construct the circuits and gain an understanding of how circuits are represented. The circuit above is shown in Fritzing like this:<\/p>\n<p>&nbsp;<\/p>\n<\/div>\n<div class=\"ace-line gutter-author-p-251586 emptyGutter\" data-author-initials=\"AK\" data-author-name=\"Andrew K\" data-author-link=\"\/ep\/profile\/Fff9BhWVGtc\"><a href=\"https:\/\/www.courses.tegabrain.com\/SS15\/wp-content\/uploads\/2015\/02\/Screen-Shot-2015-02-19-at-12.50.15-PM.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-657 size-large\" src=\"https:\/\/www.courses.tegabrain.com\/SS15\/wp-content\/uploads\/2015\/02\/Screen-Shot-2015-02-19-at-12.50.15-PM-1024x491.png\" alt=\"Screen Shot 2015-02-19 at 12.50.15 PM\" width=\"980\" height=\"470\" srcset=\"https:\/\/www.courses.tegabrain.com\/SS15\/wp-content\/uploads\/2015\/02\/Screen-Shot-2015-02-19-at-12.50.15-PM-1024x491.png 1024w, https:\/\/www.courses.tegabrain.com\/SS15\/wp-content\/uploads\/2015\/02\/Screen-Shot-2015-02-19-at-12.50.15-PM-300x144.png 300w, https:\/\/www.courses.tegabrain.com\/SS15\/wp-content\/uploads\/2015\/02\/Screen-Shot-2015-02-19-at-12.50.15-PM-535x256.png 535w, https:\/\/www.courses.tegabrain.com\/SS15\/wp-content\/uploads\/2015\/02\/Screen-Shot-2015-02-19-at-12.50.15-PM.png 1240w\" sizes=\"(max-width: 980px) 100vw, 980px\" \/><\/a><\/div>\n<div class=\"ace-line gutter-author-p-251586 emptyGutter\" data-author-initials=\"AK\" data-author-name=\"Andrew K\" data-author-link=\"\/ep\/profile\/Fff9BhWVGtc\"><\/div>\n<div class=\"ace-line gutter-author-p-251586 emptyGutter\" data-author-initials=\"AK\" data-author-name=\"Andrew K\" data-author-link=\"\/ep\/profile\/Fff9BhWVGtc\"><\/div>\n<div class=\"ace-line gutter-author-p-251586 emptyGutter\" data-author-initials=\"AK\" data-author-name=\"Andrew K\" data-author-link=\"\/ep\/profile\/Fff9BhWVGtc\"><strong>Notes on resistors and LEDS:<\/strong><\/div>\n<div class=\"ace-line gutter-author-p-251586 emptyGutter\" data-author-initials=\"AK\" data-author-name=\"Andrew K\" data-author-link=\"\/ep\/profile\/Fff9BhWVGtc\">This circuit is built with an resistor. Remember\u00a0we need to design our circuit so that we use up all the current (otherwise we will eventually burn out our LED). This means we need to couple our LED with a resistor as shown above. (You dont have to do this on Pin 13 as it has a special on board resistor.\u00a0But\u00a0here we can&#8217;t use 13 as we need to use an PWM pin &#8211; one with a ~ sign).<\/div>\n<div class=\"ace-line gutter-author-p-251586 emptyGutter\" data-author-initials=\"AK\" data-author-name=\"Andrew K\" data-author-link=\"\/ep\/profile\/Fff9BhWVGtc\"><\/div>\n<div class=\"ace-line gutter-author-p-251586 emptyGutter\" data-author-initials=\"AK\" data-author-name=\"Andrew K\" data-author-link=\"\/ep\/profile\/Fff9BhWVGtc\">You have 3 different resistors in your kits.\u00a0For your LEDs you need to use\u00a0either the the\u00a0560 Ohm Resistor (stripes of Green-Blue-Brown) or the 220 Ohm resistor (stripes of red, red, red, gold).<\/div>\n<div class=\"ace-line gutter-author-p-251586 emptyGutter\" data-author-initials=\"AK\" data-author-name=\"Andrew K\" data-author-link=\"\/ep\/profile\/Fff9BhWVGtc\"><\/div>\n<p><b>Notes on building circuits using the breadboard:<\/b><\/p>\n<div class=\"ace-line gutter-author-p-251586 emptyGutter\" data-author-initials=\"AK\" data-author-name=\"Andrew K\" data-author-link=\"\/ep\/profile\/Fff9BhWVGtc\">Notice that we are now using our bread board to construct the circuit.\u00a0As Arduino does\u2019t have any other space to assemble other electronic components\u00a0directly, the breadboard is a\u00a0great tool to do that. You can easily insert and take out components without soldering therefore it has holes in grid. The holes are connected by following a certain rule. See the\u00a0figures below. The left one show schematic view of the breadboard. the red and blue lines show the connectivity between holes. 5V always goes to 5V pin on Arduino. GND does to GND pin.<\/div>\n<div class=\"ace-line gutter-author-p-251586 emptyGutter\" data-author-initials=\"AK\" data-author-name=\"Andrew K\" data-author-link=\"\/ep\/profile\/Fff9BhWVGtc\"><\/div>\n<div class=\"ace-line gutter-author-p-251586 emptyGutter\" data-author-initials=\"AK\" data-author-name=\"Andrew K\" data-author-link=\"\/ep\/profile\/Fff9BhWVGtc\">\u00a0<a href=\"https:\/\/www.courses.tegabrain.com\/SS15\/wp-content\/uploads\/2015\/02\/breadboard.jpg\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-large wp-image-731\" src=\"https:\/\/www.courses.tegabrain.com\/SS15\/wp-content\/uploads\/2015\/02\/breadboard-1024x755.jpg\" alt=\"breadboard\" width=\"980\" height=\"723\" srcset=\"https:\/\/www.courses.tegabrain.com\/SS15\/wp-content\/uploads\/2015\/02\/breadboard-1024x755.jpg 1024w, https:\/\/www.courses.tegabrain.com\/SS15\/wp-content\/uploads\/2015\/02\/breadboard-300x221.jpg 300w, https:\/\/www.courses.tegabrain.com\/SS15\/wp-content\/uploads\/2015\/02\/breadboard-535x395.jpg 535w, https:\/\/www.courses.tegabrain.com\/SS15\/wp-content\/uploads\/2015\/02\/breadboard.jpg 1261w\" sizes=\"(max-width: 980px) 100vw, 980px\" \/><\/a><\/div>\n<div class=\"ace-line gutter-author-p-251586 emptyGutter\" data-author-initials=\"AK\" data-author-name=\"Andrew K\" data-author-link=\"\/ep\/profile\/Fff9BhWVGtc\"><\/div>\n<div class=\"ace-line gutter-author-p-251586 emptyGutter\" data-author-initials=\"AK\" data-author-name=\"Andrew K\" data-author-link=\"\/ep\/profile\/Fff9BhWVGtc\">THE CODE FOR AN LED FADE IS HERE:<\/div>\n<div class=\"ace-line gutter-author-p-251586 emptyGutter\" data-author-initials=\"AK\" data-author-name=\"Andrew K\" data-author-link=\"\/ep\/profile\/Fff9BhWVGtc\"><\/div>\n<div class=\"ace-line gutter-author-p-251586 emptyGutter\" data-author-initials=\"AK\" data-author-name=\"Andrew K\" data-author-link=\"\/ep\/profile\/Fff9BhWVGtc\"><a href=\"https:\/\/www.courses.tegabrain.com\/SS15\/wp-content\/uploads\/2015\/02\/Screen-Shot-2015-02-19-at-12.51.38-PM.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-658 size-large\" src=\"https:\/\/www.courses.tegabrain.com\/SS15\/wp-content\/uploads\/2015\/02\/Screen-Shot-2015-02-19-at-12.51.38-PM-1024x366.png\" alt=\"Screen Shot 2015-02-19 at 12.51.38 PM\" width=\"980\" height=\"350\" srcset=\"https:\/\/www.courses.tegabrain.com\/SS15\/wp-content\/uploads\/2015\/02\/Screen-Shot-2015-02-19-at-12.51.38-PM-1024x366.png 1024w, https:\/\/www.courses.tegabrain.com\/SS15\/wp-content\/uploads\/2015\/02\/Screen-Shot-2015-02-19-at-12.51.38-PM-300x107.png 300w, https:\/\/www.courses.tegabrain.com\/SS15\/wp-content\/uploads\/2015\/02\/Screen-Shot-2015-02-19-at-12.51.38-PM-535x191.png 535w, https:\/\/www.courses.tegabrain.com\/SS15\/wp-content\/uploads\/2015\/02\/Screen-Shot-2015-02-19-at-12.51.38-PM.png 1432w\" sizes=\"(max-width: 980px) 100vw, 980px\" \/><\/a><\/div>\n<div class=\"ace-line gutter-author-p-251586 emptyGutter\" data-author-initials=\"AK\" data-author-name=\"Andrew K\" data-author-link=\"\/ep\/profile\/Fff9BhWVGtc\"><\/div>\n<\/div>\n<div class=\"ace-line gutter-author-p-251586 emptyGutter\" data-author-initials=\"AK\" data-author-name=\"Andrew K\" data-author-link=\"\/ep\/profile\/Fff9BhWVGtc\">\n<div id=\"magicdomid134\" class=\"ace-line gutter-author-p-251586 emptyGutter\" data-author-initials=\"AK\" data-author-name=\"Andrew K\" data-author-link=\"\/ep\/profile\/Fff9BhWVGtc\"><span class=\"author-p-251586 u\"><span style=\"text-decoration: underline;\">Can all pins be PWM pins?\u00a0 No!!! &#8211;\u00a0<\/span><\/span><span class=\"author-p-251586\">You need to see the\u00a0 <\/span><span class=\"author-p-251586 b\"><b>~<\/b><\/span><span class=\"author-p-251586\">\u00a0 next to a pin.<\/span><\/div>\n<h3>Challenges:<\/h3>\n<ul>\n<li><span class=\"author-p-251586\">1. Change fade speed<\/span><\/li>\n<li><span class=\"author-p-251586\">2. Fade one LED on as another fades off<\/span><\/li>\n<li>3. Build the RGB LED circuit and fade between colors on RGBled. The circuit will look something like this:<\/li>\n<\/ul>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-694\" src=\"https:\/\/www.courses.tegabrain.com\/SS15\/wp-content\/uploads\/2015\/02\/Screen-Shot-2015-02-19-at-6.37.32-PM.png\" alt=\"Screen Shot 2015-02-19 at 6.37.32 PM\" width=\"1368\" height=\"924\" srcset=\"https:\/\/www.courses.tegabrain.com\/SS15\/wp-content\/uploads\/2015\/02\/Screen-Shot-2015-02-19-at-6.37.32-PM.png 1368w, https:\/\/www.courses.tegabrain.com\/SS15\/wp-content\/uploads\/2015\/02\/Screen-Shot-2015-02-19-at-6.37.32-PM-300x203.png 300w, https:\/\/www.courses.tegabrain.com\/SS15\/wp-content\/uploads\/2015\/02\/Screen-Shot-2015-02-19-at-6.37.32-PM-1024x692.png 1024w, https:\/\/www.courses.tegabrain.com\/SS15\/wp-content\/uploads\/2015\/02\/Screen-Shot-2015-02-19-at-6.37.32-PM-535x361.png 535w\" sizes=\"(max-width: 1368px) 100vw, 1368px\" \/><\/p>\n<p>&#8212;-CODE &#8212;&#8212; (fixed up since class)<\/p>\n<pre lang=\"java\">\/*\r\n\/*\r\n Fade for a 3 color LED\r\n\r\n This example shows how to fade an LED on pin 9\r\n using the analogWrite() function.\r\n\r\n This example code is in the public domain.\r\n *\/\r\n\r\nint r = 9;           \/\/ the pin that the R pin of the LED is attached to\r\nint g = 10;    \/\/ the pin that the G pin of the LED is attached to\r\nint b = 11;    \/\/ the pin that the B pin of the LED is attached to\r\nint brightnessR = 0;    \/\/ how bright the R LED is\r\nint brightnessG = 0;    \/\/ how bright the G LED is\r\nint brightnessB = 0;    \/\/ how bright the B LED is\r\nint fadeAmountR = 5;    \/\/ how many points to fade the LED by\r\nint fadeAmountG = 7;    \/\/ how many points to fade the LED by\r\nint fadeAmountB = 9;    \/\/ how many points to fade the LED by\r\n\r\n\/\/ the setup routine runs once when you press reset:\r\nvoid setup() {\r\n  \/\/ declare pin 9, 10, 11 to be an output:\r\n  pinMode(r, OUTPUT);\r\n  pinMode(g, OUTPUT);\r\n  pinMode(b, OUTPUT);\r\n}\r\n\r\n\/\/ the loop routine runs over and over again forever:\r\nvoid loop() {\r\n  \/\/ set the brightness of pin 9, 10, 11:\r\n  analogWrite(r, brightnessR);\r\n  analogWrite(g, brightnessG);\r\n  analogWrite(b, brightnessB);\r\n\r\n  \/\/ change the brightness for next time through the loop:\r\n  brightnessR = brightnessR + fadeAmountR;\r\n  brightnessG = brightnessG + fadeAmountG;\r\n  brightnessB = brightnessB + fadeAmountB;\r\n\r\n  \/\/ reverse the direction of the fading at the ends of the fade:\r\n  if (brightnessR == 0 || brightnessR == 255) {\r\n    fadeAmountR = -fadeAmountR ;\r\n  }\r\n    \/\/ reverse the direction of the fading at the ends of the fade:\r\n  if (brightnessG == 0 || brightnessG == 255) {\r\n    fadeAmountG = -fadeAmountG ;\r\n  }\r\n    \/\/ reverse the direction of the fading at the ends of the fade:\r\n  if (brightnessB == 0 || brightnessB == 255) {\r\n    fadeAmountB = -fadeAmountB ;\r\n  }\r\n  \/\/ wait for 30 milliseconds to see the dimming effect\r\n  delay(30);\r\n}\r\n\r\n}\r\n<\/pre>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>DOWNLOAD INSTALL AND SETUP Follow the download and installation instructions for getting the\u00a0Arduino software here. If you are having difficulty getting your computer to recognize the Arduino,\u00a0you may\u00a0need to manually install a driver on your computer &#8211; download here.\u00a0If you have a mac and are confused as to whether your computer is 32bit or 64bit [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"open","ping_status":"open","template":"","meta":[],"_links":{"self":[{"href":"https:\/\/www.courses.tegabrain.com\/SS15\/index.php?rest_route=\/wp\/v2\/pages\/640"}],"collection":[{"href":"https:\/\/www.courses.tegabrain.com\/SS15\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.courses.tegabrain.com\/SS15\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.courses.tegabrain.com\/SS15\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.courses.tegabrain.com\/SS15\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=640"}],"version-history":[{"count":10,"href":"https:\/\/www.courses.tegabrain.com\/SS15\/index.php?rest_route=\/wp\/v2\/pages\/640\/revisions"}],"predecessor-version":[{"id":809,"href":"https:\/\/www.courses.tegabrain.com\/SS15\/index.php?rest_route=\/wp\/v2\/pages\/640\/revisions\/809"}],"wp:attachment":[{"href":"https:\/\/www.courses.tegabrain.com\/SS15\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=640"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}