tag:blogger.com,1999:blog-54609295826707096852024-03-20T02:59:16.792-07:00The Maker's Apprenticedent424http://www.blogger.com/profile/16900861616437185462noreply@blogger.comBlogger11125tag:blogger.com,1999:blog-5460929582670709685.post-45072310395789246252013-01-21T02:27:00.003-08:002013-01-21T02:27:34.845-08:00Day 9: Servos and Sensors<div class="separator" style="clear: both; text-align: center;">
</div>
<div style="margin-left: 1em; margin-right: 1em; text-align: left;">
Wow! Servos! Not only do they sound incredibly cool, but they also open up a whole range of possibilities. You see, unlike a regular motor which just spins, servos allow you to precisely control how many degrees you want to turn them. So, for example, you can connect them to a sensor and have that sensor determine how much something turns. As a proof of concept, I tried connecting a servo up to a potentiometer. Basically, by turning a dial, I controlled how far the servo turned. Nothing too exciting. </div>
<br />
<div>
<br /></div>
<div>
The next exercise actually had me attach a flex sensor to the servo so that by bending a little strip, I could control how far the servo turns. This, unlike my previous little exercise, really triggers my imagination. Imagine, you could stick a set of these sensors inside a glove and have them control the motion of a robotic hand. By adjusting the strength of the servo, you could translate your motion into a robotic grip of death.</div>
<div>
<br /></div>
<div style="text-align: center;">
Flex Sensor and Touch Sensor</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://dlnmh9ip6v2uc.cloudfront.net/images/products/1/1/2/2/7/Sensors.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://dlnmh9ip6v2uc.cloudfront.net/images/products/1/1/2/2/7/Sensors.jpg" width="320" /></a></div>
<div>
<br /></div>
<div>
The last exercise that I did too a touch sensor and attached it to an LED. Nothing too novel there, but it's still neat to see a new kind of sensor at work. Basically the touch sensor offers a different amount of resistance depending on what point you touch, and so by touching different parts, I was able to alter the color of a three color LED.</div>
<div>
<br /></div>
<div>
Below is an awesome video I compiled of these three projects... with the most awesome music ever. </div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<iframe allowfullscreen='allowfullscreen' webkitallowfullscreen='webkitallowfullscreen' mozallowfullscreen='mozallowfullscreen' width='320' height='266' src='https://www.youtube.com/embed/nIW3u36GU4E?feature=player_embedded' frameborder='0'></iframe></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
I'm fast approaching the end of my Arduino workbook, but there are still a few neat components to go! </div>
<div>
<br /></div>
<div>
<br /></div>
dent424http://www.blogger.com/profile/16900861616437185462noreply@blogger.com0tag:blogger.com,1999:blog-5460929582670709685.post-34373764043154161112013-01-16T02:32:00.002-08:002013-01-16T02:32:35.272-08:00Day 8: Getting Data, Creating a Thermostat<div class="separator" style="clear: both; text-align: left;">
The key component of circuit 7 was using the serial connection between the Arduino and the computer. This allows the board to send output from a sensor to your computer so that you can output it onto your screen. In this case, I was given a temperature sensor and it was pretty neat to see the temperature scrolling up my screen second by second. I could blow on the sensor and see the temperature go up for a second and then float back down. </div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
The Sparkfun Inventor's Kit guide recommended that I make a thermostat with my temperature sensor, a potentiometer, and an LED, and so I did. The thermostat reads in a temperature that I set using a knob, compares that temperature with the temperature that it senses through a temperature sensor, and then sends a signal to turn on an LED if the temperature is below a certain level.</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjv2MXP74zI-0bzUrbLnt3GWuJINetP97M92gOLvGEM5a8ym7f3LB5aZ0sOPHZtf1TbZ3ZAcg4bSdfZYstXBKmcbJjIvSdoVeSv8fi_uOVLBANWwN0lt5M4RmFbZVHKFfBPOG5xhBVsvQ/s1600/photo.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjv2MXP74zI-0bzUrbLnt3GWuJINetP97M92gOLvGEM5a8ym7f3LB5aZ0sOPHZtf1TbZ3ZAcg4bSdfZYstXBKmcbJjIvSdoVeSv8fi_uOVLBANWwN0lt5M4RmFbZVHKFfBPOG5xhBVsvQ/s320/photo.JPG" width="320" /></a></div>
<br />
<div>
Ok, so it isn't exactly a thermostat. It doesn't actually control an air conditioner or a heater. Still, it's pretty close, and I wouldn't have had any idea how to do this two weeks ago. I have to say that, one of the remarkable things about playing with the Arduino is that you get a sense of how the electronics in your daily life work, and then you can just create your own mini-version that does whatever crazy thing you want it to do! Amazing!</div>
<div>
<br /></div>
<div>
</div>
dent424http://www.blogger.com/profile/16900861616437185462noreply@blogger.com0tag:blogger.com,1999:blog-5460929582670709685.post-27914153228292553212013-01-12T19:56:00.003-08:002013-01-12T19:56:58.876-08:00Day 7: Photoresistors and Mapping FunctionsThere's nothing new in terms of setting up this circuit. You simply create one circuit with an LED and another circuit with a photoresistor that you use as a light sensor. The photoresistor is set up in a voltage divider in the same way as the <a href="http://makersapprentice.blogspot.com/2012/12/day-2-getting-to-know-potentiometer.html">potentiometer in Day 2</a>. It's neat to see that you can use a single setup like a voltage divider for a range of different sensors.<br />
<div>
<div style="text-align: center;">
Voltage Divider</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEimN1GFZ7uXb1mzrZR8aW_cmVNn04cIBK4Ri6mWL5xaHu_poakZtffF2BXrB2Ix1DyAHhLvNDXZi6KU8NrVwFP3uuq3qr72s6dS87hc-5OMboCcXQj5WTl1l0mUoRQ2L6ZkNu2613RcQQ/s1600/Impedance_Voltage_divider.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEimN1GFZ7uXb1mzrZR8aW_cmVNn04cIBK4Ri6mWL5xaHu_poakZtffF2BXrB2Ix1DyAHhLvNDXZi6KU8NrVwFP3uuq3qr72s6dS87hc-5OMboCcXQj5WTl1l0mUoRQ2L6ZkNu2613RcQQ/s1600/Impedance_Voltage_divider.png" /></a></div>
<div>
</div>
</div>
<div>
Even though this is fundamentally identical to the potentiometer circuit, it feels a lot cooler. You can get the LED to increase and decrease in brightness just by waving your hand in front of it. Here's a terrible video by me of the circuit in action.</div>
<div class="separator" style="clear: both; text-align: center;">
<iframe allowfullscreen='allowfullscreen' webkitallowfullscreen='webkitallowfullscreen' mozallowfullscreen='mozallowfullscreen' width='320' height='266' src='https://www.youtube.com/embed/68MsFRdvG2g?feature=player_embedded' frameborder='0'></iframe></div>
<div>
<br /></div>
<div>
The other awesomely useful thing that I learned building this circuit was the map function. In short, this easily solves the problem that I faced in my <a href="http://makersapprentice.blogspot.com/2013/01/day-3-multicolored-leds-and-cool-side.html">potentiometer controlled multicolored LED side project in Day 3</a>. In that one, the potentiometer read in an analog signal between 1-1023 and the LED pins read between 0 and 255 and so I had to invent an adjustment factor to move between the two. The map function does that for me. So in this case I could do the function<br />
<br />
lightLevel=map(lightLevel, 0, 1023, 0, 255);<br />
<br />
which is exactly the same map function as required in this circuit as well. Cool stuff that will definitely save me time in the future!<br />
<br /></div>
dent424http://www.blogger.com/profile/16900861616437185462noreply@blogger.com0tag:blogger.com,1999:blog-5460929582670709685.post-77199484466800808012013-01-11T18:59:00.003-08:002013-01-11T18:59:54.117-08:00Day 6: Push Buttons and Pullup ResistorsThe SIK kit uses circuit 5 to teach people about push buttons and logic. Two push buttons are hooked up in circuits and used as inputs. An LED is then hooked up to an output. Depending on how whether you are pushing one button or two buttons, the LED will either be on or off. There are various little functions included in the included code that provide some good examples.<br />
<br />
<div style="text-align: center;">
A Circuit with a Pullup Resistor</div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjsRqmsKzciSBjyQkuQ6OtJsOyo9rDlQUc3gl09H_NSki5sJp7UfJLU2F1Lody-b58WNReXvxA1r0UzWVn30q8rpBX6NDtOorKzylwhdEO5-_TlCQwXI1-ujmtkjU_kcM60paKa5XSTsg/s1600/Pullup_Resistor.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjsRqmsKzciSBjyQkuQ6OtJsOyo9rDlQUc3gl09H_NSki5sJp7UfJLU2F1Lody-b58WNReXvxA1r0UzWVn30q8rpBX6NDtOorKzylwhdEO5-_TlCQwXI1-ujmtkjU_kcM60paKa5XSTsg/s1600/Pullup_Resistor.png" /></a></div>
<br />
<br />
One of the things that really confused me, though, was the use of 10kohm resistor with the push button. The circuit looked like this:<br />
<br />
5V -- 10,000ohm resistor -- input pin -- push button --GND<br />
<br />
It turns out that this is pretty simple. When the push button is closed, you get the circuit:<br />
<br />
input pin -- push button -- GND<br />
<br />
Which sends no power to the input pin. This is a LOW signal.<br />
<br />
When the push button is open you get the circuit<br />
<br />
5V -- 10,000ohm resistor -- input pin<br />
<br />
And so you are sending power to the input pin. This is a HIGH signal.<br />
<br />
So now you can use these values of LOW and HIGH to program button behaviors. <a href="http://www.sparkfun.com/tutorials/218">Here is a much more thorough explanation on the Sparkfun website.</a> Awesome!dent424http://www.blogger.com/profile/16900861616437185462noreply@blogger.com0tag:blogger.com,1999:blog-5460929582670709685.post-46756117274510846132013-01-09T02:58:00.000-08:002013-01-11T18:39:32.532-08:00Day 5: Analog Write and Pulse Width Modulation (~)<div class="separator" style="clear: both; text-align: left;">
Circuit #4 in the Sparkfun Inventor's Kit isn't anything too exciting in terms of introducing you to new stuff. It basically teaches you how to create a circuit with eight LEDs which you can program to turn on and off in various patterns. </div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZHAOb4fBTEd6trVw-Z0HT3JJDmWRpMPAeA09BS_1VgOwTnp4SnhueDrM-SULnBy8WYlJuzByhf1oINDyhMDrRYqLLAzP9pHNKfxdKcSYd7rg0k4iSomUY7zurZoY_YvnvXz3zApnnPQ/s1600/photo.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZHAOb4fBTEd6trVw-Z0HT3JJDmWRpMPAeA09BS_1VgOwTnp4SnhueDrM-SULnBy8WYlJuzByhf1oINDyhMDrRYqLLAzP9pHNKfxdKcSYd7rg0k4iSomUY7zurZoY_YvnvXz3zApnnPQ/s320/photo.JPG" width="320" /></a></div>
<br />
<div>
Like I said, there is almost nothing new introduced in this project, and yet, it brings a lot of things together. In fact, this is probably the first circuit that really gave me a view into a small fraction of the things that the Arduino is capable of. You see, even with just eight LEDs, you can make them light up one after another, light up all at once, or light up completely randomly. The program provided with the circuit provides a nice array of functions that allow you to generate some fun patterns with the LEDs. It's a great exercise, and a great opportunity to play around with programming a simple circuit like this one to create some fun results.</div>
<div>
<br /></div>
<div>
I decided that for my own project related to circuit 4, I would replace the digitalWrite function that is used in all of the various patterns with the analogWrite function. This means that instead of having the lights simply turn on and off in succession, the lights would pulse on and off slowly. I thought it would be simple enough. Basically, I took the for loops that had the lights turn on and off in succession, and added another for loop within it to gradually raise the brightness of the LED. See code below.</div>
<div>
<br /></div>
<div>
<div>
<i>void glowOneAfterAnother()</i></div>
<div>
<i>{</i></div>
<div>
<i> int index;</i></div>
<div>
<i> int x;</i></div>
<div>
<i> int delayTime = 10; // milliseconds to pause between LEDs</i></div>
<div>
<i><br /></i></div>
<div>
<i> for(index = 0; index <= 5; index++) // this loop goes through each LED</i></div>
<div>
<i> {</i></div>
<div>
<i> for(x=0; x <=255; x++) //this loop gradually raises the level of analogWrite from 0 to 255</i></div>
<div>
<i> {</i></div>
<div>
<i> analogWrite(ledPins[index], x);</i></div>
<div>
<i> delay(delayTime);</i></div>
<div>
<i> } </i></div>
<div>
<i> }</i></div>
</div>
<div>
<i><br /></i></div>
<div>
You may notice that I mentioned 8 LEDs before, but only 6 are mentioned in this code. This is due to a small hitch I encountered along the way.</div>
<div>
<br /></div>
<div>
When I first ran my program with the original 8 LEDs, I encountered the strange situation where about half of my LEDs gradually turned on as expected, and the other half simply turned on as if I had used digitalWrite. After double checking my code and double checking all my circuit connections, I was left scratching my head. After staring at my board for a while, I realized that all of the pins that were working as expected were plugged into digital pins with a tilde(~) next to the pin number. Apparently, only these pins are capable of what is called <a href="http://en.wikipedia.org/wiki/Pulse-width_modulation">Pulse Width Modulation</a>. While I don't know the exact details, pulse width modulation is basically the rapid flickering on and off of the pin that allows for the simulation of analog output required to use analogWrite. Apparently this is also useful for doing things like controlling the speed of motors. </div>
<div>
<br /></div>
<div>
In the end, to get the circuit to work properly, I had to restrict the pins I used to the ones with a ~ beside them. Unfortunately there were only 6 so I had to remove two of my LEDs.</div>
<div>
<br /></div>
<div>
So that was my adventure with analogWrite. I'm glad it gave me the chance to understand the Arduino a little better. Now I can sit and bask in the glory of my 6 gently pulsing LED lights.</div>
dent424http://www.blogger.com/profile/16900861616437185462noreply@blogger.com0tag:blogger.com,1999:blog-5460929582670709685.post-24973825514227621122013-01-05T09:49:00.004-08:002013-01-09T02:35:35.327-08:00Day 4: A Guide to ResistorsWell, I'm not feeling that well today so I figure I'll work on more theoretical stuff so that I can stay in bed. One of the things that has mystified me since I started these Arduino projects is the role of the resistor. I remember using these things when I was setting up circuits in physics class in high school, but I realized that I have no idea when or how to use what resistor. I thought I would do a little research to refresh my understanding of resistors and get a better understanding of how to use them with the Arduino.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgC-Lzqi5fS4pT3YSBZaQyZ0swC2Bvqe4BDC1mGlMWeI1cOSb3TyAnKPIGOe6RhvcttuzLUmdsLWFmo7ngszIzXE1YRHoInI0XfbZgbcjqH9buKjfIlP8n7ChYvXakasyQeufdWKeJyrg/s1600/800px-Resistor.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="212" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgC-Lzqi5fS4pT3YSBZaQyZ0swC2Bvqe4BDC1mGlMWeI1cOSb3TyAnKPIGOe6RhvcttuzLUmdsLWFmo7ngszIzXE1YRHoInI0XfbZgbcjqH9buKjfIlP8n7ChYvXakasyQeufdWKeJyrg/s320/800px-Resistor.jpg" width="320" /></a></div>
<br />
<br />
The basic question I want to answer is the following: Why do I need a 330ohm resistor in my circuit when I attach an LED to an Arduino pin. I've been doing it since my very first circuit, but I have no idea why. Looking at various message boards proved useful. The first thing that I encountered as I looked for solutions to this question was the following equation:<br />
<br />
V=IR where V is voltage, I is current (in amps), and R is resistance (in ohms).<br />
<br />
This equation was sitting somewhere in the dim recesses of my memory, but I had no idea how to apply it to this situation. The next clue came when reading the specifications of an Arduino pin.<br />
<br />
A digital Arduino pin, when set to output "High" outputs 5V. The pin is also rated at 40mA. This means that if I try to draw more than 40mA of current from any given pin on the Arduino, I might damage it. Plugging these two values into the equation above I get:<br />
<br />
5V/0.04A=125ohm<br />
<br />
This gives me the resistance of the resistor I need in an circuit (which plugs the pin directly into ground) with 5V to draw a current of 40mA. Playing with this relationship a bit, we can see that<br />
<br />
5V/10ohm=0.5A of 5V/1000ohm=0.005A or 5mA<br />
<br />
So then having a circuit with anything less than a 125ohm resistor would damage the Arduino pin. (There is likely some variance here due to the resistance in the wires themselves, so we could probably attach a resistor somewhat less than 125ohm.)<br />
<br />
Now if we look at the <a href="https://www.sparkfun.com/products/9590?">LED that comes with the SIK</a>, it says that there is a 1.8-2.2 voltage drop across the LED. Taking the median value of 2V, we can see that we now end up with:<br />
<br />
(5V-2V)/0.04A=75ohm<br />
<br />
So we have the value of the resistor necessary to keep from damaging the Arduino pin (75ohm). But now looking at the specification for the LED, it also says "Suggested Using Current 16-18mA." This means that, with a 75ohm resistor, we might not damage the Arduino pin, but we would damage the LED. To get the right amount of current to the LED we must recalculate:<br />
<br />
(5V-2V)/0.017A=176.47ohm<br />
<br />
In the kit, I have been using a 330ohm resistor which means:<br />
<br />
(5V-2V)/330ohm=0.009 or 9mA<br />
<br />
Judging from this, my LED is probably a little dimmer than it could be.<br />
<br />
In writing this I found the first reply by <a href="http://arduino.cc/forum/index.php?PHPSESSID=8b5fdf0c6d1f30ab575e12d734551225&action=profile;u=7576">lefty</a> in <a href="http://arduino.cc/forum/index.php?PHPSESSID=36c2050c000ea4dbf90b767f918fa464&topic=135292.msg1017473#msg1017473">this Arduino Forum</a> to be extremely valuable. I also <a href="http://arduino.cc/forum/index.php?PHPSESSID=c68546b7627592c57c01330d8becaded&topic=140531.0">opened up a thread in the Arduino basic electronics forum</a> where several people were extremely helpful. More on resistors later.<br />
<br />
<br />dent424http://www.blogger.com/profile/16900861616437185462noreply@blogger.com0tag:blogger.com,1999:blog-5460929582670709685.post-12976175472934828582013-01-02T07:40:00.003-08:002013-01-05T09:26:31.863-08:00Day 3: Multicolored LEDs and a cool side projectThe circuit involved in circuit three of the Sparkfun Inventor's Kit (SIK) was extremely simple. It basically involved plugging three LEDs of different colors (all in one convenient package pictured below) into a circuit.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhInkZiLjhCzTFp-OPIDuFCpmz9oSjIhZPyMj9EF5xyQfiMVFVcfFzs3HjkJN0H0odfrLaBMK3PjPFurHHZOVDosf4UTQhZ9vwfZMe4wRlnmus9FRv34atqLZ_Fi0FBZOtXqYbXrFuU8Q/s1600/IMG_1403.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhInkZiLjhCzTFp-OPIDuFCpmz9oSjIhZPyMj9EF5xyQfiMVFVcfFzs3HjkJN0H0odfrLaBMK3PjPFurHHZOVDosf4UTQhZ9vwfZMe4wRlnmus9FRv34atqLZ_Fi0FBZOtXqYbXrFuU8Q/s320/IMG_1403.JPG" width="320" /></a></div>
<br />
<br />
The really cool bits were in the programming where I was introduced to two new concepts. First was the function analogWrite(PIN, Intensity) which basically simulates analog output. The SIK guide has a nice explanation of the function, but basically what it does is flickers a digital output on and off at various speeds to approximate analog output. The result in the case of the LED was changing intensities of the LEDs based on the values in the intensity level put into the analogWrite function.<br />
<br />
The other important concept was the use of a for loop in programming the Arduino. I've encountered loops many times in the past doing other types of programming but this is the first time I've encountered it in this setting. Unsurprisingly, they worked in exactly the same way. The function that was created basically cycled the three color LED through the color spectrum by varying the brightness of the three LEDs. Since the analogWrite function takes intensities between 0 and 255, it was simply a matter of creating a new function (called showSpectrum) that looped through values of 0 and 255 on each of the three colors. The code looked like this:<br />
<br />
<br />
<i>void showSpectrum()</i><br />
<i>{</i><br />
<i> int x; // define an integer variable called "x"</i><br />
<i> </i><br />
<i> // Now we'll use a for() loop to make x count from 0 to 767</i><br />
<i> // (Note that there's no semicolon after this line!</i><br />
<i> // That's because the for() loop will repeat the next</i><br />
<i> // "statement", which in this case is everything within</i><br />
<i> // the following brackets {} )</i><br />
<i><br /></i>
<i> for (x = 0; x < 768; x++)</i><br />
<i><br /></i>
<i> // Each time we loop (with a new value of x), do the following:</i><br />
<i><br /></i>
<i> {</i><br />
<i> showRGB(x); // Call RGBspectrum() with our new x</i><br />
<i> delay(10); // Delay for 10 ms (1/100th of a second)</i><br />
<i> }</i><br />
<i>}</i><br />
<i><br /></i>
<i><br /></i>
<i>// showRGB()</i><br />
<i><br /></i>
<i>// This function translates a number between 0 and 767 into a</i><br />
<i>// specific color on the RGB LED. If you have this number count</i><br />
<i>// through the whole range (0 to 767), the LED will smoothly</i><br />
<i>// change color through the entire spectrum.</i><br />
<i><br /></i>
<i>// The "base" numbers are:</i><br />
<i>// 0 = pure red</i><br />
<i>// 255 = pure green</i><br />
<i>// 511 = pure blue</i><br />
<i>// 767 = pure red (again)</i><br />
<i><br /></i>
<i>// Numbers between the above colors will create blends. For</i><br />
<i>// example, 640 is midway between 512 (pure blue) and 767</i><br />
<i>// (pure red). It will give you a 50/50 mix of blue and red,</i><br />
<i>// resulting in purple.</i><br />
<i><br /></i>
<i>// If you count up from 0 to 767 and pass that number to this</i><br />
<i>// function, the LED will smoothly fade between all the colors.</i><br />
<i>// (Because it starts and ends on pure red, you can start over</i><br />
<i>// at 0 without any break in the spectrum).</i><br />
<i><br /></i>
<i><br /></i>
<i>void showRGB(int color)</i><br />
<i>{</i><br />
<i> int redIntensity;</i><br />
<i> int greenIntensity;</i><br />
<i> int blueIntensity;</i><br />
<i><br /></i>
<i> // Here we'll use an "if / else" statement to determine which</i><br />
<i> // of the three (R,G,B) zones x falls into. Each of these zones</i><br />
<i> // spans 255 because analogWrite() wants a number from 0 to 255.</i><br />
<i><br /></i>
<i> // In each of these zones, we'll calculate the brightness</i><br />
<i> // for each of the red, green, and blue LEDs within the RGB LED.</i><br />
<i><br /></i>
<i> if (color <= 255) // zone 1</i><br />
<i> {</i><br />
<i> redIntensity = 255 - color; // red goes from on to off</i><br />
<i> greenIntensity = color; // green goes from off to on</i><br />
<i> blueIntensity = 0; // blue is always off</i><br />
<i> }</i><br />
<i> else if (color <= 511) // zone 2</i><br />
<i> {</i><br />
<i> redIntensity = 0; // red is always off</i><br />
<i> greenIntensity = 255 - (color - 256); // green on to off</i><br />
<i> blueIntensity = (color - 256); // blue off to on</i><br />
<i> }</i><br />
<i> else // color >= 512 // zone 3</i><br />
<i> {</i><br />
<i> redIntensity = (color - 512); // red off to on</i><br />
<i> greenIntensity = 0; // green is always off</i><br />
<i> blueIntensity = 255 - (color - 512); // blue on to off</i><br />
<i> }</i><br />
<i><br /></i>
<i> // Now that the brightness values have been set, command the LED</i><br />
<i> // to those values</i><br />
<i><br /></i>
<i> analogWrite(RED_PIN, redIntensity);</i><br />
<i> analogWrite(BLUE_PIN, blueIntensity);</i><br />
<i> analogWrite(GREEN_PIN, greenIntensity);</i><br />
<i>}</i><br />
<i><br /></i>
I've left the comments in so that everything is clear. Not too terribly complicated.<br />
<br />
And finally for the good stuff. After finishing exercise 3, I thought to myself, wouldn't it be fun if I could make the LEDs cycle through the spectrum based on twisting the potentiometer? Thus my very first independent arduino project was born. Here is my needlessly dramatic video of the results.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<iframe allowfullscreen='allowfullscreen' webkitallowfullscreen='webkitallowfullscreen' mozallowfullscreen='mozallowfullscreen' width='320' height='266' src='https://www.youtube.com/embed/BzoRXrdMw2A?feature=player_embedded' frameborder='0'></iframe></div>
<br />
In the end the project basically involved making a circuit that was a hybrid of the <a href="http://makersapprentice.blogspot.com/2012/12/day-2-getting-to-know-potentiometer.html">potentiometer circuit created in circuit 2</a> with the circuit I had just created. I created one circuit which plugged the potentiometer into the analog input of the arduino and left the three color LED just the way it was in circuit 3.<br />
<br />
The programming was slightly trickier and I've uploaded it to scribd <a href="http://www.scribd.com/doc/118588401">here</a>. Most of the code is pretty easy if you understand circuit three. The only tricky part is to realize that the output from the potentiometer ranges from 1-1023 while the function we've created to cycle through the color spectrum goes from 1-766. As a result, we need to map the values 1-1023 to 1-766 and this is done by multiplying the output from the potentiometer by a factor 766/1023.<br />
<br />
And there you have it! A cute little side project!<br />
<br />
<br />dent424http://www.blogger.com/profile/16900861616437185462noreply@blogger.com0tag:blogger.com,1999:blog-5460929582670709685.post-67054915459111146632012-12-28T16:15:00.001-08:002012-12-28T16:15:29.089-08:00Make just released<a href="http://blog.makezine.com/2012/12/28/best-of-arduino/view-all/"> a list of cool Arduino projects that it covered in 2012.</a> My personal favorite? Probably the <a href="http://blog.makezine.com/2012/04/23/arc-o-matic-an-arduino-controlled-art-bot/">ArcoMatic Art Bot</a>.dent424http://www.blogger.com/profile/16900861616437185462noreply@blogger.com0tag:blogger.com,1999:blog-5460929582670709685.post-77380180323175859852012-12-28T15:41:00.000-08:002012-12-28T15:41:21.003-08:00Day 2: Getting to know the PotentiometerI think the last time I actually built any kind of circuit was in my freshman year physics class in college (8 years ago). Unsurprisingly I've forgotten almost everything. Today as I started circuit number 2 in my <a href="https://www.sparkfun.com/products/11227">SparkFun Inventor's Kit</a> I was faced with a component called a potentiometer (or variable resistor).<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjx9CYADFelAT7LCBBzE0xK_mdLCEvcX3sWrubWBzgfNX-wAkWpaapxofBUcKUaWSJwIpywwWMVbv1gS4yje8aXsp0Utq2XxnEZxWKKPeQBwQ1LMD-bZka4K-WmQJiPe2Eb1eQ0klKcwA/s1600/IMG_1399.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjx9CYADFelAT7LCBBzE0xK_mdLCEvcX3sWrubWBzgfNX-wAkWpaapxofBUcKUaWSJwIpywwWMVbv1gS4yje8aXsp0Utq2XxnEZxWKKPeQBwQ1LMD-bZka4K-WmQJiPe2Eb1eQ0klKcwA/s320/IMG_1399.JPG" width="320" /></a></div>
<br />
This little fella here basically has three pins and a little knob on the top that you can rotate and is described in the SparkFun guide as a knob that can raise and lower resistance, like a dimmer switch or a volume knob. The two outer pins connect to the power and the ground, and the central pin which is the output. It seems that in general, the way that these things work is that a connection is made between some sort of resistive material (apparently graphite in cheap potentiometers) organized in an arc and the power. By turning the knob on the potentiometer, you adjust the amount of resistive material between the power and the output by moving the second contact to a position further on the arc. <a href="http://www.wisegeek.com/what-is-a-potentiometer.htm">This site</a> explains it far more clearly than me. It's a surprisingly simple and elegant design... and I always thought that the inner workings of any of these things would be impossible to understand!<br />
<br />
The second project in the kit involves setting up the potentiometer so that it can adjust the speed of the blinking of an LED, and getting this to work was surprisingly simple. Basically I made two circuits. One of the circuits is between the arduino and the LED, and the other is between the arduino and the potentiometer.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikzdYFUj6Cot7AjOskbSx6hDyxTXskWAZlPfGzckIqdCg5apqFBB7TJqTagsPTsj6xYB44n8UhAPwmj4fH425MvcD5AceqJtxzry8HlX7hgcSv4a6tpwbhKqTBcgg4RzHj57U6ISZYHQ/s1600/IMG_1400.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikzdYFUj6Cot7AjOskbSx6hDyxTXskWAZlPfGzckIqdCg5apqFBB7TJqTagsPTsj6xYB44n8UhAPwmj4fH425MvcD5AceqJtxzry8HlX7hgcSv4a6tpwbhKqTBcgg4RzHj57U6ISZYHQ/s320/IMG_1400.JPG" width="320" /></a></div>
<br />
It's at this point that the manual discusses some crucial aspects of the arduino board: analog and digital pins. Basically, the analog pins take a value between 0 and 5 volts and translates them into a number between 0 and 1023 (more on this later). The digital pin is for dealing with values of things that are either off (0 volts) or on (5 volts) like say a blinking LED.<br />
<br />
Now the code:<br />
<br />
int sensorPin = 0;<br />
int ledPin = 13;<br />
<br />
void setup()<br />
{<br />
pinMode(ledPin, OUTPUT);<br />
}<br />
<br />
void loop()<br />
{<br />
int sensorValue;<br />
sensorValue = analogRead(sensorPin);<br />
digitalWrite(ledPin, HIGH);<br />
delay(sensorValue);<br />
digitalWrite(ledPin, LOW);<br />
delay(sensorValue);<br />
}<br />
<br />
If you are unfamiliar with Arduino code, this might look complicated but it's actually pretty straightforward, especially if you know some programming. Here are the key lines:<br />
<br />
<br />
sensorValue = analogRead(sensorPin);<br />
<i>This reads the value from the potentiometer and sets it to a variable called sensorValue</i><br />
<br />
digitalWrite(ledPin, HIGH); <i>This turns on the LED</i><br />
delay(sensorValue); <i>This keeps the next line from running for sensorValue milliseconds </i><br />
digitalWrite(ledPin, LOW); <i>This turns off the LED</i><br />
delay(sensorValue);<br />
<div>
<br /></div>
<div>
That's it. Just read in the value of the potentiometer and turn the light on and off delaying by the returned value from the potentiometer. It's really surprising to me that such a simple set of code could get this done. I was expecting it to be much more complicated, but perhaps that is why arduino is so popular.</div>
dent424http://www.blogger.com/profile/16900861616437185462noreply@blogger.com0tag:blogger.com,1999:blog-5460929582670709685.post-68516924750109028232012-12-27T14:00:00.001-08:002012-12-27T14:02:37.459-08:00Day 1: Opening the Sparkfun Inventor's KitMy wife, Victoria, was kind enough to purchase the <a href="https://www.sparkfun.com/products/11227">Sparkfun Inventor's Kit</a> for me for Christmas. This kit costs about $95 and includes an <a href="http://www.arduino.cc/">Arduino</a> board for running programs, a <a href="http://en.wikipedia.org/wiki/Breadboard">breadboard</a> for creating circuits, and a variety of things like motors, sensors, and LEDs to hook up in a circuit. It also comes with a very nice manual with some basic projects. The code for the projects which can be uploaded to the Arduino are available online.<br />
<br />
It's a nice kit that comes with a nice plastic box to keep everything in. Fancy eh?<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhDzNzIvP1pg2bGcEEfsnCeKBqVcVb9GZ3CbeJuXxGN-huPA_VgEmcEaKC-VhwKxToh3Fb2pMioBdq2zPBIn6rcqqb9p2mEcaVe7Ty1GMnB_2XetmeZRwzfY5YjkR7dqP8UNwFJT7YBgw/s1600/IMG_1396.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhDzNzIvP1pg2bGcEEfsnCeKBqVcVb9GZ3CbeJuXxGN-huPA_VgEmcEaKC-VhwKxToh3Fb2pMioBdq2zPBIn6rcqqb9p2mEcaVe7Ty1GMnB_2XetmeZRwzfY5YjkR7dqP8UNwFJT7YBgw/s320/IMG_1396.JPG" width="320" /></a></div>
<br />
Everything in the box comes in nice little labelled pouches. All you have to do is attach the Arduino and the breadboard to the little plastic dish they give you. Below are the contents of the package.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjCqEFe3hQNetDZAtZ6DgMGDgEfGqgL0uUC75SJV20z8Vy7JiXqSaRfQa2XGYwQVfIQqCXt_a1i6FW9ufCKILgyT2XwG6UEdIqSAPz22qcEYbjczDdEizte2fUwGBZKy_LwiIoZWxfJfQ/s1600/IMG_1387.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjCqEFe3hQNetDZAtZ6DgMGDgEfGqgL0uUC75SJV20z8Vy7JiXqSaRfQa2XGYwQVfIQqCXt_a1i6FW9ufCKILgyT2XwG6UEdIqSAPz22qcEYbjczDdEizte2fUwGBZKy_LwiIoZWxfJfQ/s320/IMG_1387.JPG" width="320" /></a></div>
<br />
Setting up the Arduino with my computer could not have been easier. Just follow some <a href="http://arduino.cc/en/Guide/HomePage">simple instructions</a> on the Arduino website. I was up and running my first program in about 10 minutes. Since the Arduino was powered by the USB port connected to my PC, there was no need to hook up batteries or anything. Once all the drivers were installed, I followed some of the simple instructions for the first circuit presented in the Sparkfun manual. It's a simple circuit that creates a blinking LED light.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiuFMtbR2LX35B90tNVP7PcIoe2-RCy1DkVApdqSLXGd98PuMihGFjvOxI71H44mYpDu8Zbs46c_aPbeEQxeO9Rf-v0VFeLzOlkdZo-L7bgtqaXTLKqINIiisu_yZoW8t2H7rnQ-ntbsQ/s1600/IMG_1388.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiuFMtbR2LX35B90tNVP7PcIoe2-RCy1DkVApdqSLXGd98PuMihGFjvOxI71H44mYpDu8Zbs46c_aPbeEQxeO9Rf-v0VFeLzOlkdZo-L7bgtqaXTLKqINIiisu_yZoW8t2H7rnQ-ntbsQ/s320/IMG_1388.JPG" width="320" /></a></div>
As you can see, the instructions are accompanied by very clear and helpful illustrations and explanations. After setting up the circuit, I opened up the provided code which was also very clearly annotated. I hit upload and boom! Blinking LED!<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgA-je2nkCwzeum-muzctiqI91Sesr-2RGVtduvM_LCn85KwMX3AOQsnOfMUyyUxDDCq4Bu-dK1yHQmjLkap1ILHtAvqLrYhFz-YDRA_67PUwMt2qEIuEUbA7MHupCX1InwZ1pjh7v1Ig/s1600/IMG_1394.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgA-je2nkCwzeum-muzctiqI91Sesr-2RGVtduvM_LCn85KwMX3AOQsnOfMUyyUxDDCq4Bu-dK1yHQmjLkap1ILHtAvqLrYhFz-YDRA_67PUwMt2qEIuEUbA7MHupCX1InwZ1pjh7v1Ig/s320/IMG_1394.JPG" width="320" /></a></div>
By adjusting the program a little bit, I was able to adjust the speed of the blinking. Simple but fun. Who knew a simple little blinking light could bring so much joy! And thus ended my first day of playing with my new Arduino.dent424http://www.blogger.com/profile/16900861616437185462noreply@blogger.com0tag:blogger.com,1999:blog-5460929582670709685.post-83145263905810722222012-12-27T13:33:00.002-08:002012-12-27T13:42:40.562-08:00What this blog is aboutAfter graduating from college in 2007, I had a miserable time. I was left with a stellar education in economics without a passion to apply it to. I worked for two years at a consulting company. The salary was good, but the work was paradoxically mind numbingly boring and stroke inducingly stressful. I sat around wondering if my life was simply going to be sitting in an office working on spreadsheets at all hours of the day while occasionally solving a business problem that captured an extra 1% of a billion dollar market for a client. I couldn't have cared less, but I was also stuck.<br />
<br />
After two years, I thought maybe I would give graduate school a try. I worked at a cognitive psychology lab for two years surrounded by kind, generous, and interesting people. I ran experiments and read academic papers. I sat in on seminars and lab meetings. I became quite fascinated and proficient in the science of decision making and negotiation. I was even lucky enough to be a teaching assistant for a couple of classes. Still, I knew that the academic lifestyle wasn't for me. The work that academics do is often highly important, but for me, it lacked a certain practicality. The results that our lab created were not something that I could hold in my hand.<br />
<br />
After two more years, I took an opportunity that had been staring me in the face for a while. A little over 50 years ago, my grandfather started a small machine tool shop in Iwata, Japan. My mother had been running it for about 20 years but she wanted to retire. I had nothing to lose and thought, why not? I'd always been interested in entrepreneurship and working at this factory would be a gentle introduction where I wouldn't have to worry about start-up capital or finding new business immediately.<br />
<br />
For the first year, I worked exclusively inside the factory. I learned to operate a manual lathe, a drill press, a manual milling machine, a cylindrical grinder, and a surface grinder. I'm by no means an expert but I understand what goes into it. After a year, I moved into management where my family has given me basically free reign to implement ideas.<br />
<br />
It's been a year and a half since I started at the factory, and now I'm completely hooked. I love the process of production. I love making stuff. I love the technology of manufacturing. I love reading blue prints. What a difference time makes. Where once I was depressed and without passion, now I'm brimming with enthusiasm. Where I once dragged myself out of bed every morning, I now wake up excited for the day ahead.<br />
<br />
I love making stuff so much that I've recently decided to take it up as a personal hobby as well, with the hope that someday my personal hobby and my professional job will merge into one. I'm creating this blog to document this process. As I have mentioned I have a year of experience working with metals, but I have no experience with electronics, and have only recently dipped my toes into the world of CAD. I hope that over the years, this blog will serve as a record of my progress as well as help to anyone who might be interested in taking their ideas and turning them into objects.<br />
<br />
I know that this is a first post and that no one will read it, but I also know that it's important to define a mission and stick to it. This is what I have for now:<br />
<br />
<span style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 13px;">A74S4TP7DWAW</span>dent424http://www.blogger.com/profile/16900861616437185462noreply@blogger.com1