<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>bildr</title>
	<atom:link href="http://bildr.org/feed/" rel="self" type="application/rss+xml" />
	<link>http://bildr.org</link>
	<description>bildr - communal know-how</description>
	<lastBuildDate>Tue, 14 Feb 2012 13:16:29 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2</generator>
		<item>
		<title>Tilt Sensing with the RPI-1031 + Arduino</title>
		<link>http://bildr.org/2012/02/rpi-1031_arduino/</link>
		<comments>http://bildr.org/2012/02/rpi-1031_arduino/#comments</comments>
		<pubDate>Tue, 14 Feb 2012 13:16:29 +0000</pubDate>
		<dc:creator>ameyer</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Tilt Sensor]]></category>

		<guid isPermaLink="false">http://bildr.org/?p=1909</guid>
		<description><![CDATA[
Once in a while something comes out that I think is going to be really awesome, but when you get it, it is just so so. Im sure you all know what I mean&#8230; But yeah&#8230; This is one of those. The RPI-1031 available from sparkfun is a pretty simple (heck, it is dead simple) [...]
]]></description>
			<content:encoded><![CDATA[<p><img class="noFrame" src="http://bildr.org/blog/wp-content/uploads/2012/01/tilt.jpg"/></p>
<div class="columnBody">
<div class="leftColumn">
<p>Once in a while something comes out that I think is going to be really awesome, but when you get it, it is just so so. Im sure you all know what I mean&#8230; But yeah&#8230; This is one of those.</p>
<p>The RPI-1031 <a href="http://www.sparkfun.com/products/10621">available</a> from <a href="http://www.sparkfun.com/">sparkfun</a> is a pretty simple (heck, it is dead simple) sensor for sensing when it is tilted. And it does this really well. But it seriously only does that. If it is not tilted, it freaks out and reports tilt anyways.</p>
<p>It actually just uses a metal ball that rolls around inside (you can hear it moving around when you tip it). Because of how it is made, the ball is always up against one side even when it is flat. Unfortunately this means you can never know the difference between a reading, and it being flat, only changes in reading.</p>
<h3>Hooking it up</h3>
<p>This is as simple as it gets I guess. Just power and ground, then connect the 2 digital pins and you are done. These 2 digital pins will output LOW/LOW, LOW/HIGH, HIGH/LOW and HIGH/HIGH depending on the wall it is touching. Again, even if it is flat, it is still touching a wall.</p>
<h3>Code</h3>
<p>The code for this guy is really simple, it just checks 2 pins, to see what side is being touched &#8211; The simple function just takes the 2 digital outputs and returns 0,1,2 or 3 depending on the side. </p>
</div>
<div class="rightColumn">
<a href="http://bildr.org/blog/wp-content/uploads/2012/01/RPI-1031_arduino_hookup.png"><img src="http://bildr.org/blog/wp-content/uploads/2012/01/RPI-1031_arduino_hookup-400x597.png" alt="" title="RPI-1031_arduino_hookup" width="400" height="597" class="alignleft size-medium wp-image-1910" /></a>
</div>
</div>
<div class="codesnip-container" >
<div class="codeHead">
				<a class="copy" href="#">Copy Code</a>
			</div>
<pre class="arduino codesnip" style="font-family:monospace;"><span class="co1">//For the RPI-1031 - http://www.sparkfun.com/products/10621 </span>

<span class="kw4">int</span> tilt_s1 <span class="sy0">=</span> <span class="nu0">2</span><span class="sy0">;</span>
<span class="kw4">int</span> tilt_s2 <span class="sy0">=</span> <span class="nu0">3</span><span class="sy0">;</span>

<span class="kw4">void</span> setup<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span>
 <span class="kw3">pinMode</span><span class="br0">&#40;</span>tilt_s1<span class="sy0">,</span> <span class="kw2">INPUT</span><span class="br0">&#41;</span><span class="sy0">;</span>
 <span class="kw3">pinMode</span><span class="br0">&#40;</span>tilt_s2<span class="sy0">,</span> <span class="kw2">INPUT</span><span class="br0">&#41;</span><span class="sy0">;</span>
 <span class="kw3">Serial</span>.<span class="me1">begin</span><span class="br0">&#40;</span>9600<span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span>

<span class="kw4">void</span> loop<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span>
  <span class="kw4">int</span> position <span class="sy0">=</span> getTiltPos<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
  <span class="kw3">Serial</span>.<span class="me1">println</span><span class="br0">&#40;</span>position<span class="br0">&#41;</span><span class="sy0">;</span>
  <span class="kw3">delay</span><span class="br0">&#40;</span>200<span class="br0">&#41;</span><span class="sy0">;</span> <span class="co1">//only here to slow down the serial output</span>
<span class="br0">&#125;</span>

<span class="kw4">int</span> getTiltPosition<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span>
   <span class="kw4">int</span> s1 <span class="sy0">=</span> <span class="kw3">digitalRead</span><span class="br0">&#40;</span>tilt_s1<span class="br0">&#41;</span><span class="sy0">;</span>
   <span class="kw4">int</span> s2 <span class="sy0">=</span> <span class="kw3">digitalRead</span><span class="br0">&#40;</span>tilt_s2<span class="br0">&#41;</span><span class="sy0">;</span>
   <span class="kw1">return</span> <span class="br0">&#40;</span>s1 <span class="sy0">&lt;&lt;</span> 1<span class="br0">&#41;</span> <span class="sy0">|</span> s2<span class="sy0">;</span> <span class="co1">//bitwise math to combine the values</span>
<span class="br0">&#125;</span></pre>
<div class="codeFoot">
				Unless otherwise stated, this code is released under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT License</a> &#8211; Please use, change and share it.
			</div>
</p></div>
]]></content:encoded>
			<wfw:commentRss>http://bildr.org/2012/02/rpi-1031_arduino/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sensing color with the ADJD-S311 + Arduino</title>
		<link>http://bildr.org/2012/01/adjd-s311_arduino/</link>
		<comments>http://bildr.org/2012/01/adjd-s311_arduino/#comments</comments>
		<pubDate>Tue, 31 Jan 2012 13:41:05 +0000</pubDate>
		<dc:creator>ameyer</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[adjd-S311]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[color]]></category>

		<guid isPermaLink="false">http://bildr.org/?p=1928</guid>
		<description><![CDATA[
A year ago we had an article called Sensing color with the ADJD-S371. Well the ADJD-S371 is long gone, and its replacement is the ADJD-S311 (breakout board available from sparkfun). It is basically the same all around, so without shame, I will be copying a lot of that article, because&#8230; Why reinvent the wheel? A [...]
]]></description>
			<content:encoded><![CDATA[<p><img class="noFrame" src="http://bildr.org/blog/wp-content/uploads/2012/01/adjd-S311.jpg"/></p>
<div class="columnBody">
<div class="leftColumn">
A year ago we had an article called <a href="http://bildr.org/2011/01/adjd-s371-tutorial/">Sensing color with the ADJD-S371</a>. Well the ADJD-S371 is long gone, and its replacement is the <a href="http://www.sparkfun.com/products/10701">ADJD-S311</a> (breakout board available from sparkfun). It is basically the same all around, so without shame, I will be copying a lot of that article, because&#8230; Why reinvent the wheel? </p>
<p>A few things you should know about the ADJD-S311 before we dive in too deep: I have never been able to get perfect color sampling from this guy without limiting the colors it would detect to just 6, and accurately reproducing color on an <a href="http://wiki.bildr.org/index.php/LED">LED</a> is not as simple as one would hope. The color reading from the sensor could be spot on, but the reproduced color on the LED may be way off. (you can blame your eyes and the LEDs)</p>
<h3>Hooking it up</h3>
<p>The ADJD-S311 is an <a href="http://wiki.bildr.org/index.php/I2C">I2C</a> device (I2C is a 2-wire serial connection), so we just need to connect the SDA (Data) and SCL (Clock) lines to your Arduino for communication. On your Arduino (everything but the <a href="http://wiki.bildr.org/index.php/Arduino_Mega ">mega</a>) SDA is on analog pin 4, and SCL is on analog pin 5. On an arduino mega, SDA is digital 20, and SCL is digital 21. (The Arduino Leonardo will also be different). Other than these 2 lines, we just need to connect power(3.3v), ground, and the onboard LED to digital 2 (you can change that in code if you want).</p>
<p>The ADJD-S311 has 4 sensors built into it to detect Red, Green, Blue, and Clear. It reports back an individual reading from each sensor. The white, or clear, sensor is mainly for sensing brightness.</p>
</div>
<div class="rightColumn">
<a href="http://bildr.org/blog/wp-content/uploads/2012/01/ADJA-S311_arduino_hookup.png"><img src="http://bildr.org/blog/wp-content/uploads/2012/01/ADJA-S311_arduino_hookup-400x591.png" alt="" title="ADJA-S311_arduino_hookup" width="400" height="591" class="alignleft size-medium wp-image-1929" /></a>
</div>
</div>
<div class="columnBody">
<div class="leftColumn">
The ADJD-S311 is designed to sense reflected light using the onboard LED, but I have found that by turning the onboard LED off, it works even better for sensing projected light (like from your monitor or projector). If you are interested in using the sensor for sensing reflected colors, you want the sensor to be about 1-2mm from the subject so the onboard LED can bounce off the material and back to the sensor. </p>
</div>
<div class="rightColumn">
<a href="http://bildr.org/blog/wp-content/uploads/2011/01/led-bounce.png"><br />
<img class="noFrame" src="http://bildr.org/blog/wp-content/uploads/2011/01/led-bounce.png"/></a>
</div>
</div>
<div class="wideBody">
<h3>Code</h3>
<p>The code for this guy is long and obnoxious, so we made a library out of it. This code is based on the sparkfun code, that was based on the old bildr code, that was based on the code by Marcus over at <a href="http://interactive-matter.eu/">Interactive Matter</a>. I love open source!</p>
<p>This library is really simple, you can call calibrate to calibrate to white (make sure you have a white objet or light source in front of it when you do this), you can turn the LED on and off, and you can read. Reading gives you back a RGBC (red,green,blue,clear) variable that has the readings from the sensor. See the code for how to use it.
</p></div>
<div class="columnBody">
<div class="leftColumn">
<p>To make this code work, <strong>before you load the code, or even open the Arduino program</strong>, we need to place the &#8220;ADJDS311&#8243; folder into your Arduino Library. If you don’t know where that is by default, Look to the right.</p>
<p>If you click the download button to the right of “Arduino” you can download the whole thing as a zip, so you dont need to copy all the files.</p>
</div>
<div class="rightColumn">
<h3>Default Library Folder Location</h3>
<p><span style="font-size: 10px; line-height:12px;"><strong>On your Mac:</strong>: In (home directory)/Documents/Arduino/libraries<br />
<strong>On your PC:</strong>: My Documents -> Arduino -> libraries<br />
<strong>On your Linux box:</strong>: (home directory)/sketchbook/libraries<br />
</span></p>
</div>
</div>

	<div class="clear">
	<script src="http://code.bildr.org/render/ADJD-S311/arduino.js"></script>
	</div>
	
]]></content:encoded>
			<wfw:commentRss>http://bildr.org/2012/01/adjd-s311_arduino/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Quickly: KS0108B Graphic LCD 128&#215;64 + Arduino</title>
		<link>http://bildr.org/2011/10/ks0108b-arduino/</link>
		<comments>http://bildr.org/2011/10/ks0108b-arduino/#comments</comments>
		<pubDate>Thu, 13 Oct 2011 03:32:58 +0000</pubDate>
		<dc:creator>ameyer</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[KS0108B]]></category>
		<category><![CDATA[LCD]]></category>

		<guid isPermaLink="false">http://bildr.org/?p=1829</guid>
		<description><![CDATA[
This is an incredibly quick post, and it is actually here simply because this thing was a pain to figure out how to hook it up. But, I wasn&#8217;t able to do anything with it more than the Arduino library was able to do out of the box. So, if you have this screen sold [...]
]]></description>
			<content:encoded><![CDATA[<p><img class="noFrame" src="http://bildr.org/blog/wp-content/uploads/2011/10/KS0108B.jpg"/></p>
<div class="columnBody">
<div class="leftColumn">
This is an incredibly quick post, and it is actually here simply because <a href="http://www.sparkfun.com/products/710">this thing</a> was a pain to figure out how to hook it up. But, I wasn&#8217;t able to do anything with it more than the Arduino library was able to do out of the box.</p>
<p>So, if you have <a href="http://www.sparkfun.com/products/710">this screen</a> sold from SparkFun, and you wanted to hook it up to your Arduino, here is how you do that.</p>
<h2>Hooking it up</h2>
<p>LCD screens of this type are more difficult to work with than ones specifically designed for text. With these you have individual pixel control, so you can draw completely custom graphics with it. But it also means you have to keep track of a lot of pixels, hence all the extra wires. Making matters worse, many of these screens actually require a negative voltage on the dimmer pot to get an image from it. But luckily this particular one includes all the circuitry needed.</p>
<p><strong>Note: this is hookup for the non-mega Arduino. The Arduino Megas actually connect differently to this screen. </strong> Just make sure to connect all the wires to the Arduino as seen on the right. You can click on the image to get a closer look.</p>
<p>To drive this graphic display you need a library, and for that, Arduino has you covered: <a href="http://www.arduino.cc/playground/Code/GLCDks0108">http://www.arduino.cc/playground/Code/GLCDks0108</a></p>
<p>I know this is a lame excuse for an article. But like I said, it is just here incase you need to know how to hook it up.</p>
</div>
<div class="rightColumn">
<p><a href="http://bildr.org/blog/wp-content/uploads/2011/10/KS0108B-hookup.png"><img src="http://bildr.org/blog/wp-content/uploads/2011/10/KS0108B-hookup-400x511.png" alt="" title="KS0108B-hookup" width="400" height="511" class="alignleft size-medium wp-image-1833" /></a></p>
</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://bildr.org/2011/10/ks0108b-arduino/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>High Sensitivity Light Sensor TSL230R + Arduino</title>
		<link>http://bildr.org/2011/09/tsl230r-arduino/</link>
		<comments>http://bildr.org/2011/09/tsl230r-arduino/#comments</comments>
		<pubDate>Fri, 09 Sep 2011 12:03:37 +0000</pubDate>
		<dc:creator>ameyer</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Light]]></category>
		<category><![CDATA[TSL230R]]></category>

		<guid isPermaLink="false">http://bildr.org/?p=1642</guid>
		<description><![CDATA[
A while back we covered the TEMT6000, a great little analog sensor for getting ambient light readings when you need something a bit more sensitive than a simple Photoresistor. Well in the spirit of documenting everything we can get our hands on, this week we will be taking the sensitivity to the next level with [...]
]]></description>
			<content:encoded><![CDATA[<p><img class="noFrame" src="http://bildr.org/blog/wp-content/uploads/2011/08/TSL230R.jpg"/></p>
<div class="columnBody">
<div class="leftColumn">
<p>A while back we <a href="http://bildr.org/2011/06/temt6000_arduino/">covered</a> the <a href="http://wiki.bildr.org/index.php/TEMT6000">TEMT6000</a>, a great little <a href="http://wiki.bildr.org/index.php/analog">analog</a> sensor for getting ambient light readings when you need something a bit more sensitive than a simple <a href="http://wiki.bildr.org/index.php/Photoresistor">Photoresistor</a>. Well in the spirit of documenting everything we can get our hands on, this week we will be taking the sensitivity to the next level with the <a href="http://www.sparkfun.com/products/8940">TSL230R Light Intensity Sensor</a>. </p>
<p>I actually bought this a long time ago simply because it looked awesome. I mean really&#8230; How often do you see a clear chip? That was enough, I had to have it. Well, aside from looking downright awesome, it is also an incredibly sensitive digital light sensor. This awesome guy is sensitive enough to be used for photography light metering, or be able to tell when someone walks by a lamp on the other side of the room. Also, to top it all off, it actually has 3 sensitivity settings, so if you are in a low-light situation, it has you covered!</p>
</div>
<div class="rightColumn">
<p><a href="http://bildr.org/blog/wp-content/uploads/2011/08/TSL230R-hookup.png"><img src="http://bildr.org/blog/wp-content/uploads/2011/08/TSL230R-hookup-400x228.png" alt="" title="TSL230R-hookup" width="400" height="228" class="alignleft size-medium wp-image-1648" /></a></p>
</div>
</div>
<div class="wideBody">
<h3>Hooking it up</h3>
<p>So the TSL230R is actually pretty simple, it really only has power, and signal out. But it has a bunch of extra pins so you can change sensitivity and output type if you want. We don&#8217;t care about changing the output format, but I did want to keep the &#8220;sensitivity select&#8221; open for you incase you need it.</p>
<p>So just connect it up to your Arduino as shown in the image. Make sure to take note of either the larger pin in the bottom left (pin 4) or the circle on the top left (pin 1) to make sure you have it facing the right way.</p>
<h3>Code</h3>
<p><strong>Before we get to far!</strong> If you are looking for a photo-ready reading from this sensor, in ISO, ASA, Lux or other, you are in the wrong place. You want this article here: <a href="http://roamingdrone.wordpress.com/2008/11/13/arduino-and-the-taos-tsl230r-light-sensor-getting-started/">Arduino and the Taos TSL230R Light Sensor: Getting Started</a>. </p>
<p>If you want to be able to check for changes in light, and have some simpler code to tame this beast, keep reading. </p>
<p>So what the TSL230R does, is it sends out a digital <a href="http://wiki.bildr.org/index.php/Square Wave">Square Wave</a> (simple up and down) signal that gets longer with less light, and shorter with more light. So we need to look at how long the wave is so we can figure out the brightness. We will actually be taking a few samples and averaging them so the signal will be more accurate and smoother. If you are looking at using a threshold to trigger something, you may want to up the number of samples it takes so it is even smoother and you don&#8217;t get false positives. (but this will slow down how long it takes to read)</p>
<p>This code simply checks the output of the TSL230R, and prints to the Arduino&#8217;s software serial terminal. With higher readings meaning brighter. You can change the sensitivity of the TSL230R as well. In the sketch, under setupTSL230, you can set TSL230_s0, and TSL230_s1 HIGH or LOW to make the sensor more or less sensitive to light. Great for low-light, or ultra-bright situations.</p>
<div class="codesnip-container" >
<div class="codeHead">
				<a class="copy" href="#">Copy Code</a>
			</div>
<pre class="arduino codesnip" style="font-family:monospace;"><span class="co1">// Reports the frequency from the TSL230, higher number means brighter</span>
<span class="co1">// Part: http://www.sparkfun.com/products/8940</span>
<span class="co1">// Article:  http://bildr.org/2011/08/tsl230r-arduino/ </span>

<span class="kw4">int</span> TSL230_Pin <span class="sy0">=</span> <span class="nu0">4</span><span class="sy0">;</span> <span class="co1">//TSL230 output</span>
<span class="kw4">int</span> TSL230_s0 <span class="sy0">=</span> <span class="nu0">3</span><span class="sy0">;</span> <span class="co1">//TSL230 sensitivity setting 1</span>
<span class="kw4">int</span> TSL230_s1 <span class="sy0">=</span> <span class="nu0">2</span><span class="sy0">;</span> <span class="co1">//TSL230 sensitivity setting 2</span>

<span class="kw4">int</span> TSL230_samples <span class="sy0">=</span> <span class="nu0">6</span><span class="sy0">;</span> <span class="co1">//higher = slower but more stable and accurate</span>

<span class="kw4">void</span> setup<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span>
  <span class="kw3">Serial</span>.<span class="me1">begin</span><span class="br0">&#40;</span>9600<span class="br0">&#41;</span><span class="sy0">;</span>
  setupTSL230<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span>

<span class="kw4">void</span> loop<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span>

  <span class="kw4">float</span> lightLevel <span class="sy0">=</span> readTSL230<span class="br0">&#40;</span>TSL230_samples<span class="br0">&#41;</span><span class="sy0">;</span>
  <span class="kw3">Serial</span>.<span class="me1">println</span><span class="br0">&#40;</span>lightLevel<span class="br0">&#41;</span><span class="sy0">;</span>

<span class="br0">&#125;</span>

<span class="kw4">void</span> setupTSL230<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span>
  <span class="kw3">pinMode</span><span class="br0">&#40;</span>TSL230_s0<span class="sy0">,</span> <span class="kw2">OUTPUT</span><span class="br0">&#41;</span><span class="sy0">;</span>
  <span class="kw3">pinMode</span><span class="br0">&#40;</span>TSL230_s1<span class="sy0">,</span> <span class="kw2">OUTPUT</span><span class="br0">&#41;</span><span class="sy0">;</span> 

  <span class="co1">//configure sensitivity - Can set to</span>
  <span class="co1">//S1 LOW  | S0 HIGH: low</span>
  <span class="co1">//S1 HIGH | S0 LOW:  med</span>
  <span class="co1">//S1 HIGH | S0 HIGH: high</span>

  <span class="kw3">digitalWrite</span><span class="br0">&#40;</span>TSL230_s1<span class="sy0">,</span> <span class="kw2">LOW</span><span class="br0">&#41;</span><span class="sy0">;</span>
  <span class="kw3">digitalWrite</span><span class="br0">&#40;</span>TSL230_s0<span class="sy0">,</span> <span class="kw2">HIGH</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span>

<span class="kw4">float</span> readTSL230<span class="br0">&#40;</span><span class="kw4">int</span> samples<span class="br0">&#41;</span><span class="br0">&#123;</span>
<span class="co1">//sample light, return reading in frequency</span>
<span class="co1">//higher number means brighter</span>

  <span class="kw4">float</span> start <span class="sy0">=</span> <span class="kw3">micros</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
  <span class="kw4">int</span> readings <span class="sy0">=</span> <span class="nu0">0</span><span class="sy0">;</span>

  <span class="kw1">while</span><span class="br0">&#40;</span>readings <span class="sy0">&lt;</span> samples<span class="br0">&#41;</span><span class="br0">&#123;</span>
   <span class="kw3">pulseIn</span><span class="br0">&#40;</span>TSL230_Pin<span class="sy0">,</span> <span class="kw2">HIGH</span><span class="br0">&#41;</span><span class="sy0">;</span>
   readings <span class="sy0">++;</span>
  <span class="br0">&#125;</span>

  <span class="kw4">float</span> length <span class="sy0">=</span> <span class="kw3">micros</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="sy0">-</span> start<span class="sy0">;</span>
  <span class="kw4">float</span> freq <span class="sy0">=</span> <span class="br0">&#40;</span>1000000 <span class="sy0">/</span> <span class="br0">&#40;</span>length <span class="sy0">/</span> samples<span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="sy0">*</span> <span class="nu0">10</span><span class="sy0">;</span>

  <span class="kw1">return</span> freq<span class="sy0">;</span>
<span class="br0">&#125;</span></pre>
<div class="codeFoot">
				Unless otherwise stated, this code is released under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT License</a> &#8211; Please use, change and share it.
			</div>
</p></div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://bildr.org/2011/09/tsl230r-arduino/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Displaying on Paper &#8211; Thermal Printer + Arduino</title>
		<link>http://bildr.org/2011/08/thermal-printer-arduino/</link>
		<comments>http://bildr.org/2011/08/thermal-printer-arduino/#comments</comments>
		<pubDate>Tue, 30 Aug 2011 11:48:03 +0000</pubDate>
		<dc:creator>ameyer</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[thermal printer]]></category>

		<guid isPermaLink="false">http://bildr.org/?p=1656</guid>
		<description><![CDATA[
The following code and library are compatible with arduino software 1.0+ ONLY. You can download the newest version of the arduino software here. Outputting data can be extremely useful, and typically when we look at doing this, it is either to the Arduino&#8217;s serial terminal, or to some sort of display. But what about making [...]
]]></description>
			<content:encoded><![CDATA[<p><img class="noFrame" src="http://bildr.org/blog/wp-content/uploads/2011/08/thermalPrinter.jpg"/></p>
<div class="columnBody">
<div class="leftColumn">
<div class="intro">
<strong>The following code and library are compatible with arduino software 1.0+ ONLY. You can download the newest version of the <a href="http://www.arduino.cc/en/Main/Software">arduino software here.</a></strong>
</div>
<p>Outputting data can be extremely useful, and typically when we look at doing this, it is either to the Arduino&#8217;s serial terminal, or to some sort of display. But what about making physical copies of the data? So a few months back, <a href="http://sparkfun.com">SparkFun</a> started selling a <a href="http://www.sparkfun.com/products/10438">thermal printer that you could connect to a microcontroller</a> (<a href="http://www.adafruit.com/products/597">or via adafruit</a> ). That same day my brain filled with crazy thing you could do with it, like a giant fortune cookie that could print your fortune on the fly.</p>
<p>Anyways&#8230; If you dont know about thermal printers, they are most often the printers your store&#8217;s receipts are printed on. The reason for this is that they dont use ink, or use a cartridge of any sort. The paper it prints on turns black when heated. So this printer simply applies heat where another printer would apply ink. Eventually the printers head will wear out, but this after several miles of printing. Yes, miles &#8211; about 30 of them. So given that the rolls of paper are 34ft long, you can print about 4,600 rolls before the print head dies, meaning for most of us, you will never see that happen.</p>
<h3>Hooking it up</h3>
<p>So this printer can be powered off of 5V, but NOT the 5v pin on your arduino, and no via USB. It uses very little power when it is is just sitting by, but uses around a full amp when it is printing! And because the most USB can handle is half of that, we need an external power supply. Something between 5 and 9V, and a minimum of 1400ma output (larger is fine). I found that powering the printer with 9v, it printed much faster, and slightly darker than 5v, and if you have it available, I recommend using 9v.</p>
<p>There are two ways of connecting the power supply as shown in the illustrations. You can either power your arduino and the printer separately, or you can power the arduino, and power the printer off of the arduino. </p>
<p>To do the latter, the printer&#8217;s power wire (red) needs to connect to the VIN pin on the arduino, not the 5v pin. The reason is that the 5v pin goes through a regulator and is not meant to supply this kind of power, but the VIN pin is directly connected to the power input on the arduino. So it can supply much more.</p>
<p>Now just connect the rest of the wires as shown.</p>
<h3>Code</h3>
<p>The printer needs a serial connection to the arduino. And normally that would mean we would connect to digital pins 0,1 but, if we did this, anything you printed to the serial terminal for debugging or otherwise the printer would see and possibly print out. We don&#8217;t want that, so we will be using a libraty so that you can keep those pins free.</p>
<p>This printer has a huge amount of features. 2 different barcode, text output, size settings etc, and each one needs a new configuration to get it working. So we created a library for this so that you could keep your code clean, and simple.
</p></div>
<div class="rightColumn">
<p><a href="http://bildr.org/blog/wp-content/uploads/2011/08/Thermal-Printer-arduino-21.png"><img src="http://bildr.org/blog/wp-content/uploads/2011/08/Thermal-Printer-arduino-21-400x464.png" alt="" title="Thermal-Printer-arduino-2" width="400" height="464" class="alignleft size-medium wp-image-1663" /></a></p>
<p><a href="http://bildr.org/blog/wp-content/uploads/2011/08/Thermal-Printer-arduino-1.png"><img src="http://bildr.org/blog/wp-content/uploads/2011/08/Thermal-Printer-arduino-1-400x454.png" alt="" title="Thermal-Printer-arduino-1" width="400" height="454" class="alignleft size-medium wp-image-1659" /></a></p>
</div>
</div>
<div class="columnBody">
<div class="leftColumn">
<p>To make this code work, <strong>before you load the code, or even open the Arduino program</strong>, we need to place the &#8220;Thermal&#8221; folder into your Arduino Library. If you don’t know where that is by default, Look to the right.</p>
<p>If you click the download button to the right of “Arduino” you can download the whole thing as a zip, so you dont need to copy all the files.</p>
</div>
<div class="rightColumn">
<h3>Default Library Folder Location</h3>
<p><span style="font-size: 10px; line-height:12px;"><strong>On your Mac:</strong>: In (home directory)/Documents/Arduino/libraries<br />
<strong>On your PC:</strong>: My Documents -> Arduino -> libraries<br />
<strong>On your Linux box:</strong>: (home directory)/sketchbook/libraries<br />
</span></p>
</div>
</div>

	<div class="clear">
	<script src="http://code.bildr.org/render/Thermal Printer/arduino.js"></script>
	</div>
	
<div class="wideBody">
<h3>darkness And Speed Calibration</h3>
<p>If you want to get a little more speed, or darkness out of the printer, you can change some settings in the thermal.cpp file of the Thermal library.</p>
<div class="codesnip-container" >
<div class="codeHead">
				<a class="copy" href="#">Copy Code</a>
			</div>
<pre class="arduino codesnip" style="font-family:monospace;">heatTime <span class="sy0">=</span> <span class="nu0">120</span><span class="sy0">;</span> <span class="co1">//80 is default from page 23 of datasheet. Controls speed of printing and darkness</span>
heatInterval <span class="sy0">=</span> <span class="nu0">50</span><span class="sy0">;</span> <span class="co1">//2 is default from page 23 of datasheet. Controls speed of printing and darkness</span></pre>
<div class="codeFoot">
				Unless otherwise stated, this code is released under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT License</a> &#8211; Please use, change and share it.
			</div>
</p></div>
<p>Changing heatTime and heatInterval to lower values, will yield a faster, but lighter printing, and raising them will yield a slower, but  darker printing. If you are running off of 5V, and find the printing too light, try changing both values to 255.</p>
<p>You can make changes to the file with the arduino sketch open. Just save the Thermal.cpp file and re-upload the sketch to see the changes.</p>
<h4>Help expand the library</h4>
<p>We would love help expanding the library if you are interested. We would like to add to support for bitmap printing and other text setting. Also there may be a better way to set many of the settings than we are now. If you are interested in helping, let us know in the forum.</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://bildr.org/2011/08/thermal-printer-arduino/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Polar Heart Rate Monitor Interface + Arduino</title>
		<link>http://bildr.org/2011/08/heartrate-arduino/</link>
		<comments>http://bildr.org/2011/08/heartrate-arduino/#comments</comments>
		<pubDate>Wed, 24 Aug 2011 12:17:53 +0000</pubDate>
		<dc:creator>ameyer</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Heart rate]]></category>
		<category><![CDATA[Polar Heart Rate Monitor Interface]]></category>

		<guid isPermaLink="false">http://bildr.org/?p=1530</guid>
		<description><![CDATA[
The following code and library are compatible with arduino software 1.0+ ONLY. You can download the newest version of the arduino software here. When you start to talk about biometrics in electronics, heart-rate is usually the first thing to come up. And why not? I think it is often the thing we are most aware [...]
]]></description>
			<content:encoded><![CDATA[<p><img class="noFrame" src="http://bildr.org/blog/wp-content/uploads/2011/08/heartRate.jpg" alt="" /></p>
<div class="columnBody">
<div class="leftColumn">
<div class="intro">
<strong>The following code and library are compatible with arduino software 1.0+ ONLY. You can download the newest version of the <a href="http://www.arduino.cc/en/Main/Software">arduino software here.</a></strong>
</div>
<p>When you start to talk about biometrics in electronics, heart-rate is usually the first thing to come up. And why not? I think it is often the thing we are most aware of changing when we get excited, nervous, are being active, or very calm. There are several ways of sensing heart rate that dont require lots of heavy equipment and electrodes taped to you. A lot of work has been done on wrist worn <a href="http://wiki.bildr.org/index.php/IR">IR</a> based sensing, but it tends to be error prone, especially with movement. Currently, the best available method at a reasonable price seems to come from the company <a href="http://www.polarusa.com/us-en/">Polar</a>. And, what makes it better is that <a href="http://sparkfun.com">Sparkfun</a> in conjunction with <a href="http://danjuliodesigns.com/">danjuliodesigns</a>, created a <a href="http://wiki.bildr.org/index.php/microcontroller">microcontroller</a> compatible receiver for the polar monitors. So let&#8217;s take a look at using the <a href="http://www.sparkfun.com/products/8661">Polar Heart Rate Monitor Interface</a> and getting it running with your arduino.</p>
<p>The annoying thing about all of this is that you do need to wear a sensor on your body to get this going. I picked up <a href="http://www.amazon.com/Polar-T31-Non-Coded-Transmitter-Belt/dp/B0015RWZQ4">this guy</a> off amazon and had pretty good results most of the time. </p>
<p>This transmitter band is a reusable electrode that wirelessly transmits to a receiver. A note when you are testing, the band will only transmit when it is on person, or you have semi-wet thumbs pressed into the sensor plates. Also because it is an electrode, it wants a good connection with your skin&#8230; meaning sweat. They sell electrode gel you can use with it for a better connection when the skin is dry, but I never tried it. In the humid summer nights I was testing this in, I never really had an issue.</p>
<h3>Hooking It Up</h3>
<p>Ok&#8230; so this board is capable of a ton of stuff. But we are just looking today at using this with the Arduino, and the simplest way is to get this guy running in I2C mode because it will allow us to get the heart rate from it easily into our Arduino.</p>
<p><a href="http://wiki.bildr.org/index.php/I2C">I2C</a> is a 2-wire <a href="http://wiki.bildr.org/index.php/serial">serial</a> connection, so you just need to connect the SDA (Data) and SCL (Clock) lines to your Arduino for communication. On your Arduino (everything but the mega) SDA is on analog pin 4, and SCL is on analog pin 5. On an Arduino Mega, SDA is digital 20, and SCL is digital 21.</p>
<p>The board doesn&#8217;t come setup for I2C by default, so we need to make a few changes. There are two solder-<a href="http://wiki.bildr.org/index.php/jumpers">jumpers</a> on the board that need to be changed to make this happen. The first is SJ1 just to the right of the 5V pin. Remove the solder from there using <a href="http://www.sparkfun.com/products/8775">solder wick</a> or a solder sucker so that the two parts are not connected. (like in the illustration). Next look at the row of pads at the top of the board labeled OP0 &#8211; OP7. We need to solder OP0 so the two pads are connected (See the illustration).</p>
<p>Ok, so once you have the board modified and ready for I2C communication, we can actually just power it up with 5v to check if it is able to communicate with the band. With the board on, moisten your thumbs and press them firmly into the back of the band where the electrodes are and hold it less than a food from the monitor board. You should see a green LED on the board start to blink. If it does&#8230; Awesome, the band and the board are communicating! If not, try it a bit more, and see if you can get it going.</p>
</div>
<div class="rightColumn">
<p><a href="http://bildr.org/blog/wp-content/uploads/2011/08/heartRate-hookup2.png"><img src="http://bildr.org/blog/wp-content/uploads/2011/08/heartRate-hookup2-400x987.png" alt="" title="heartRate-hookup2" width="400" height="987" class="alignleft size-medium wp-image-1729" /></a></p>
</div>
</div>
<div class="wideBody">
So, now that we know they communicate with each other, connect the board to the arduino as shown, and load up the code below.</p>
<p>When it is actually running, you will need to wear the band on your chest to get a heart rate signal.</p>
<h3>code</h3>
<p>This code is pretty simple. It will take the info from the sensor band (average of 20 of the samples) and report that back in the Arduino&#8217;s serial terminal as BPM (beats per minute). If it dosnt have a connection, or the band does not have a good connection to the skin, it will report a BPM of 0.</p>
<p>You should know better than I, but your BPM reading should be between 55 and 140. If you are just sitting around, and you see it around 200, it probably means it has a bad connection. Make sure it has a good connection with your skin, and restart the receiver board/ Arduino. &#8211; A note&#8230; I did have an hour reading that was very off, but all the other time, it was very accurate.</p>
<div class="codesnip-container" >
<div class="codeHead">
				<a class="copy" href="#">Copy Code</a>
			</div>
<pre class="arduino codesnip" style="font-family:monospace;"><span class="co1">//Arduino 1.0+ Compatible only</span>
<span class="co1">//Arduino 1.0+ Compatible only</span>
<span class="co1">//Arduino 1.0+ Compatible only</span>

<span class="co1">// Code to retrieve heartrate information from the Polar Heart Rate Monitor Interface via I2C</span>
<span class="co1">// Part: http://www.sparkfun.com/products/8661</span>
<span class="co1">// Article:  http://bildr.org/2011/08/heartrate-arduino/</span>

<span class="co2">#include &quot;Wire.h&quot;</span>

<span class="co2">#define HRMI_I2C_ADDR      127</span>
<span class="co2">#define HRMI_HR_ALG        1   // 1= average sample, 0 = raw sample</span>

<span class="kw4">void</span> setup<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span>
  setupHeartMonitor<span class="br0">&#40;</span>HRMI_HR_ALG<span class="br0">&#41;</span><span class="sy0">;</span>
  <span class="kw3">Serial</span>.<span class="me1">begin</span><span class="br0">&#40;</span>9600<span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span>

<span class="kw4">void</span> loop<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span>

  <span class="kw4">int</span> heartRate <span class="sy0">=</span> getHeartRate<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
  <span class="kw3">Serial</span>.<span class="me1">println</span><span class="br0">&#40;</span>heartRate<span class="br0">&#41;</span><span class="sy0">;</span>

  <span class="kw3">delay</span><span class="br0">&#40;</span>1000<span class="br0">&#41;</span><span class="sy0">;</span> <span class="co1">//just here to slow down the checking to once a second</span>
<span class="br0">&#125;</span>

<span class="kw4">void</span> setupHeartMonitor<span class="br0">&#40;</span><span class="kw4">int</span> type<span class="br0">&#41;</span><span class="br0">&#123;</span>
  <span class="co1">//setup the heartrate monitor</span>
  Wire.<span class="me1">begin</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
  writeRegister<span class="br0">&#40;</span>HRMI_I2C_ADDR<span class="sy0">,</span> 0x53<span class="sy0">,</span> type<span class="br0">&#41;</span><span class="sy0">;</span> <span class="co1">// Configure the HRMI with the requested algorithm mode</span>
<span class="br0">&#125;</span>

<span class="kw4">int</span> getHeartRate<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span>
  <span class="co1">//get and return heart rate</span>
  <span class="co1">//returns 0 if we couldnt get the heart rate</span>
  <span class="kw4">byte</span> i2cRspArray<span class="br0">&#91;</span>3<span class="br0">&#93;</span><span class="sy0">;</span> <span class="co1">// I2C response array</span>
  i2cRspArray<span class="br0">&#91;</span>2<span class="br0">&#93;</span> <span class="sy0">=</span> <span class="nu0">0</span><span class="sy0">;</span>

  writeRegister<span class="br0">&#40;</span>HRMI_I2C_ADDR<span class="sy0">,</span>  0x47<span class="sy0">,</span> 0x1<span class="br0">&#41;</span><span class="sy0">;</span> <span class="co1">// Request a set of heart rate values </span>

  <span class="kw1">if</span> <span class="br0">&#40;</span>hrmiGetData<span class="br0">&#40;</span>127<span class="sy0">,</span> 3<span class="sy0">,</span> i2cRspArray<span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
    <span class="kw1">return</span> i2cRspArray<span class="br0">&#91;</span>2<span class="br0">&#93;</span><span class="sy0">;</span>
  <span class="br0">&#125;</span>
  <span class="kw1">else</span><span class="br0">&#123;</span>
    <span class="kw1">return</span> <span class="nu0">0</span><span class="sy0">;</span>
  <span class="br0">&#125;</span>
<span class="br0">&#125;</span>

<span class="kw4">void</span> writeRegister<span class="br0">&#40;</span><span class="kw4">int</span> deviceAddress<span class="sy0">,</span> <span class="kw4">byte</span> address<span class="sy0">,</span> <span class="kw4">byte</span> val<span class="br0">&#41;</span> <span class="br0">&#123;</span>
  <span class="co1">//I2C command to send data to a specific address on the device</span>
  Wire.<span class="me1">beginTransmission</span><span class="br0">&#40;</span>deviceAddress<span class="br0">&#41;</span><span class="sy0">;</span> <span class="co1">// start transmission to device </span>
  Wire.<span class="me1">write</span><span class="br0">&#40;</span>address<span class="br0">&#41;</span><span class="sy0">;</span>       <span class="co1">// send register address</span>
  Wire.<span class="me1">write</span><span class="br0">&#40;</span>val<span class="br0">&#41;</span><span class="sy0">;</span>         <span class="co1">// send value to write</span>
  Wire.<span class="me1">endTransmission</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>     <span class="co1">// end transmission</span>
<span class="br0">&#125;</span>

<span class="kw4">boolean</span> hrmiGetData<span class="br0">&#40;</span><span class="kw4">byte</span> addr<span class="sy0">,</span> <span class="kw4">byte</span> numBytes<span class="sy0">,</span> <span class="kw4">byte</span><span class="sy0">*</span> dataArray<span class="br0">&#41;</span><span class="br0">&#123;</span>
  <span class="co1">//Get data from heart rate monitor and fill dataArray byte with responce</span>
  <span class="co1">//Returns true if it was able to get it, false if not</span>
  Wire.<span class="me1">requestFrom</span><span class="br0">&#40;</span>addr<span class="sy0">,</span> numBytes<span class="br0">&#41;</span><span class="sy0">;</span>
  <span class="kw1">if</span> <span class="br0">&#40;</span>Wire.<span class="me1">available</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>

    <span class="kw1">for</span> <span class="br0">&#40;</span><span class="kw4">int</span> i<span class="sy0">=</span><span class="nu0">0</span><span class="sy0">;</span> i<span class="sy0">&lt;</span>numBytes<span class="sy0">;</span> i<span class="sy0">++</span><span class="br0">&#41;</span><span class="br0">&#123;</span>
      dataArray<span class="br0">&#91;</span>i<span class="br0">&#93;</span> <span class="sy0">=</span> Wire.<span class="me1">read</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="br0">&#125;</span>

    <span class="kw1">return</span> <span class="kw2">true</span><span class="sy0">;</span>
  <span class="br0">&#125;</span>
  <span class="kw1">else</span><span class="br0">&#123;</span>
    <span class="kw1">return</span> <span class="kw2">false</span><span class="sy0">;</span>
  <span class="br0">&#125;</span>
<span class="br0">&#125;</span></pre>
<div class="codeFoot">
				Unless otherwise stated, this code is released under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT License</a> &#8211; Please use, change and share it.
			</div>
</p></div>
<h3>But it&#8217;s not working!</h3>
<p>If it is not working, 99% of the time, it is simply a sensor-band placement issue. Make sure you have a blinking light on the board. If you don&#8217;t have that light, the band is not communicating with the board. It wont communicate unless it thinks it is on your body, so your skin could be too dry or the placement is off.</p>
<p>If you see the communication light, but nothing in the arduino, make sure you soldered/ unsoldered the solder-jumpers as described above.
</p></div>
]]></content:encoded>
			<wfw:commentRss>http://bildr.org/2011/08/heartrate-arduino/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Arduino: Individually Control Shift Register Pins</title>
		<link>http://bildr.org/2011/08/74hc595-breakout-arduino/</link>
		<comments>http://bildr.org/2011/08/74hc595-breakout-arduino/#comments</comments>
		<pubDate>Tue, 23 Aug 2011 12:28:48 +0000</pubDate>
		<dc:creator>ameyer</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[74HC595]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Shift Register]]></category>

		<guid isPermaLink="false">http://bildr.org/?p=1668</guid>
		<description><![CDATA[
If you want an article on general 74hc595 shift register usage with detailed explanition on how it works/what it&#8217;s doing, you want this article here: http://bildr.org/2011/02/74hc595/ The following code and library are compatible with arduino software 1.0+ ONLY. You can download the newest version of the arduino software here. Earlier this year we did an [...]
]]></description>
			<content:encoded><![CDATA[<p><img class="noFrame" src="http://bildr.org/blog/wp-content/uploads/2011/08/shiftRegisters.jpg"/></p>
<div class="intro">
<strong>If you want an article on general 74hc595 shift register usage with detailed explanition on how it works/what it&#8217;s doing, you want this article here: <a href="http://bildr.org/2011/02/74hc595/">http://bildr.org/2011/02/74hc595/</a></p>
<p>The following code and library are compatible with arduino software 1.0+ ONLY. You can download the newest version of the <a href="http://www.arduino.cc/en/Main/Software">arduino software here.</a></strong>
</div>
<div class="columnBody">
<div class="leftColumn">
Earlier this year we did <a href="http://bildr.org/2011/02/74hc595/">an article on using the 74hc595 shift register with your arduino</a>. It has been, by far, our most popular article. It seems that a lot of people want to control a lot more LEDs (or other) than the arduino can do without help. So we actually went to the guys over at sparkfun and said&#8230; &#8220;Hey! Let&#8217;s make this even easier&#8221;. And so we came up with the 74hc595 breakout board. </p>
<p>So now you find your self asking &#8220;Why?&#8221; Well&#8230; chainability! Using right-angle headers you can chain a ton of these together. AND! With the code we have for you, you get an additional 8 digital outputs per board you have connected. That means if you have 1000 of these chained together, you will be able to say &#8220;setPin 7,432 HIGH&#8221;, and BAM! Just like that pin 7,432 goes HIGH. It will literally be like you have more digital outputs on your arduino, no funny business.</p>
</div>
<div class="rightColumn">
<p><a href="http://bildr.org/blog/wp-content/uploads/2011/08/shift-Register-breakout-hookup1.png"><img src="http://bildr.org/blog/wp-content/uploads/2011/08/shift-Register-breakout-hookup1-400x284.png" alt="" title="shift-Register-breakout-hookup" width="400" height="284" class="alignleft size-medium wp-image-1674" /></a></p>
</div>
</div>
<div class="wideBody">
<h3>Hooking it up</h3>
<p>At first this board may look confusing to hookup&#8230; But just click on the illustration to get a better view of how it is hooked up. We won&#8217;t be using Reset, so just connect that to power, and connect /OE to ground (enables the board). For VCC you can connect this to 3.3 or 5V on your arduino, and the outputs will just reflect this. So if you power the board with 3.3v, the outputs on the board will output 3.3v as well. We just need 3 digital pins to control the board, and after that we are done.</p>
<p>You can chain as many of these as you would like. I used right-angle header pins to make it modular and clean. I picked up some <a href="http://search.digikey.com/scripts/DkSearch/dksus.dll?lang=en&#038;site=US&#038;KeyWords=S4381-ND&#038;x=0&#038;y=0">7 pin right-angle headers from digikey</a> to make it even easier. But you dont have to use header pins for this if you don&#8217;t want. You can easily just wire them together too. Either way, see the illustration below to see how you do this.</p>
<p><a href="http://bildr.org/blog/wp-content/uploads/2011/08/shift-register-chain.png"><img src="http://bildr.org/blog/wp-content/uploads/2011/08/shift-register-chain-950x185.png" alt="" title="shift-register-chain" width="950" height="185" class="noFrame alignleft size-large wp-image-1675" /></a></p>
<h3>Code</h3>
<p>Because it is so much easier to use a lot of these now, we wanted the code to be the same. So we made an Arduino library that is capable of controlling near 2000 of these chained together and still enable you to call each pin individually.  (this library can be used with the plain 74hc959 chip as well)</p>
<p>The library by default will only support a chain of 25 of these. But that can easily be changed by changing one number in the file &#8220;Shifter.h&#8221; . If you find your self with a larger chain, hit us up in the discussion area, and we can help you out.</p>
<p>To use the library, you just need to create an instance of the Shifter library, then you have a few functions to do everything.</p>
<p><strong>shifter.clear();</strong> &#8211; This sets all of the pins on the register chain to LOW<br />
<strong>shifter.setPin(20, HIGH)</strong>  &#8211; Turn pin 20 (or whatever) HIGH/LOW<br />
<strong>shifter.write()</strong>  &#8211; Displays the changes made.</p>
<p>Best practice is to only call shifter.write only when you need to display the changes. This is because shifter.write() can be slow if you have a ton of these chained together (about 1ms per 10 registers (80 pins))</p>
<p>Make sure to check out the discussion area. We came up with a few cool sequences to test out/ play around with &#8211; including the one in the video</p>
</div>
<div class="columnBody">
<div class="leftColumn">
<p>To make this code work, <strong>before you load the code, or even open the Arduino program</strong>, we need to place the &#8220;Shifter&#8221; folder into your Arduino Library. If you don’t know where that is by default, Look to the right.</p>
<p>If you click the download button to the right of “Arduino” you can download the whole thing as a zip, so you dont need to copy all the files.</p>
</div>
<div class="rightColumn">
<h3>Default Library Folder Location</h3>
<p><span style="font-size: 10px; line-height:12px;"><strong>On your Mac:</strong>: In (home directory)/Documents/Arduino/libraries<br />
<strong>On your PC:</strong>: My Documents -> Arduino -> libraries<br />
<strong>On your Linux box:</strong>: (home directory)/sketchbook/libraries<br />
</span></p>
</div>
</div>

	<div class="clear">
	<script src="http://code.bildr.org/render/shift_Register_8-Bit_-_74HC595/arduino.js"></script>
	</div>
	
<div class="wideBody">
<h3>Video</h3>
<p><iframe src="http://player.vimeo.com/video/27660337?byline=0&amp;portrait=0" width="949" height="534" frameborder="0"></iframe></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://bildr.org/2011/08/74hc595-breakout-arduino/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>User Project: High Voltage Temperature Control</title>
		<link>http://bildr.org/2011/08/user-project-high-voltage-temperature-control/</link>
		<comments>http://bildr.org/2011/08/user-project-high-voltage-temperature-control/#comments</comments>
		<pubDate>Tue, 09 Aug 2011 03:01:47 +0000</pubDate>
		<dc:creator>ameyer</dc:creator>
				<category><![CDATA[User Project]]></category>

		<guid isPermaLink="false">http://bildr.org/?p=1604</guid>
		<description><![CDATA[
So typically we don&#8217;t cover too many user projects here. But I had been following the progress of a project by user K-Mob, and thought it looked really cool, so I asked if he would share it. The fact that the end result looks like something from a 1960&#8242;s mad-scientist&#8217;s lab dosnt hurt either. So [...]
]]></description>
			<content:encoded><![CDATA[<p><img class="noFrame" src="http://bildr.org/blog/wp-content/uploads/2011/08/acPowerControl.jpg"/></p>
<div class="intro">
So typically we don&#8217;t cover too many user projects here. But I had been following the progress of a project by user K-Mob, and thought it looked really cool, so I asked if he would share it. The fact that the end result looks like something from a 1960&#8242;s mad-scientist&#8217;s lab dosnt hurt either. So without further ado&#8230; Here it is.
</div>
<div class="columnBody">
<div class="leftColumn">
<p>Suppose you want to keep something (e.g. a room, sous-vide steak, autoclave) at a certain temperature with, say, an <a href="http://www.amazon.com/gp/product/B000I8VE68/" target="_blank">immersion water heater</a>; you could use an off-the shelf temperature controller, OR save some money (but not time), and build your own from the ground up.  If, like me, you&#8217;re cash poor, time rich, and intellectually curious, you may consider building one yourself.  I&#8217;d say this isn&#8217;t a quick build, but I think it is pretty straight-forward.</p>
<p><strong>Bill of Materials:</strong></p>
<ul>
<li><a href="http://www.sparkfun.com/products/9764">numeric display</a> (x2)</li>
<li>potentiometer</li>
<li>thermistor or thermocouple</li>
<li>10 K resistor</li>
<li>Arduino</li>
<li><a href="http://www.sparkfun.com/products/9802" target="_blank">microSD shield</a> (if you want to log data)</li>
<li>AC power control, digital pot/relay, etc&#8230;</li>
</ul>
</div>
<div class="rightColumn">
<p><a href="http://bildr.org/blog/wp-content/uploads/2011/08/temp_cont_schem2-final-crop.png"><img src="http://bildr.org/blog/wp-content/uploads/2011/08/temp_cont_schem2-final-crop-400x250.png" alt="" title="temp_cont_schem2-final-crop" width="400" height="250" class="alignleft size-medium wp-image-1613" style="background:transparent;" /></a></p>
</div>
</div>
<div class="wideBody">
Let me try to break this down into three parts.  You need something to measure temperature with, something to control temperature with, and some UI to view/control the temperature.<br />
To read the temperature, I went with a <a href="http://wiki.bildr.org/index.php/thermistor">thermistor</a>, but a <a href="http://wiki.bildr.org/index.php/Thermocouple_Amplifier_Digital_MAX6675">thermocouple</a> would do just as well (sort of depends on the temperature range of your application); it&#8217;s just not as easy to get up and running.</p>
<p>For the display, I have found <a href="http://www.sparkfun.com/products/9764">these Sparkfun displays</a> are the best balance of relatively low cost and saving me a lot of pins, wiring, coding, etc. headaches.
</div>
<div class="columnBody">
<div class="leftColumn">
<h3>Obligatory Disclaimer: AC POWER CAN KILL YOU</h3>
<p>For Pete&#8217;s sake, be careful, and never handle any circuitry without unplugging everything first.  Use a GFCI outlet; if something goes awry, it will minimize the current going where it isn&#8217;t supposed to before cutting off power.</p>
<p>As far as controlling AC power goes, you have a few options, depending on your application and comfort level.  No matter what you choose, I highly recommend making sure the Arduino connections are optically isolated, and the dangerous bits (anything with high voltage) are safely inside a separate, insulated box.  I&#8217;d say the easiest way to introduce AC power into your project would be to use a relay of some sort; this gives you limited on/off control, and it is relatively straightforward.  I wanted to be able to control the power level, so my circuit is a little more complicated, turning the AC current on and off every cycle to dial in exactly how much current/power gets delivered.</p>
<p>Okay, so bildr already has a <a href="http://wiki.bildr.org/index.php/Thermistor">pretty good page</a> (if I do say so myself) about how to use a thermistor to read temperature; it only takes one analog input (plus power and ground), as well as a <a href="http://wiki.bildr.org/index.php/resistor">resistor</a>.  So that&#8217;s easy as pie to setup.</p>
<p>Furthermore, there&#8217;s also an article on setting up and using the <a href="http://wiki.bildr.org/index.php/7-Segment_Serial_Display">Sparkfun 4-digit serial display</a>.  I think it&#8217;s pretty easy to set up with <a href="http://wiki.bildr.org/index.php/SPI">SPI</a> communication; it minimizes the pins you have to use for one or two displays, and using the <a href="http://arduiniana.org/libraries/NewSoftSerial/" target="_blank">NewSoftSerial library</a> for Arduino, you can use any digital pin you want to send SPI communications.  Of course, we don&#8217;t care what the board has to say back to us, so you really only need to hook up the transmission (TX) pin to the display&#8217;s RX pin.</p>
<p>That only leaves AC power control as the real beast.  I&#8217;ll save the gory details for getting under the hood of AC power control for a future post.  For the purposes of this, I literally put a black box into the schematic.</p>
<p>So how to tell the Arduino what temperature to shoot for?  I wired up a potentiometer for each heater I had.  One serial display displayed the current temperature; the other displays a number I control by turning the potentiometer.  At first, I tried simply controlling the &#8220;target&#8221; temperature, utilizing the Arduino <a href="http://arduino.cc/playground/Code/PIDLibrary" target="_blank">PID library</a> to do the dirty work calculating the power that should be delivered to the heater to reach and maintain the target temperature.</p>
</div>
<div class="rightColumn">
<a href="http://bildr.org/blog/wp-content/uploads/2011/08/2011-06-07_14-59-12_2312.jpg"><img src="http://bildr.org/blog/wp-content/uploads/2011/08/2011-06-07_14-59-12_2312-400x712.jpg" alt="" title="2011-06-07_14-59-12_2312" width="400" height="712" class="alignleft size-medium wp-image-1612" /></a>
<p class="caption">Experimental setup of two of the temperature controllers (all displays are of temperature b/c I was still trying PID control)</a></p>
</div>
</div>
<div class="wideBody">
<p>I don&#8217;t think it was a problem with the library, but more with my setup and lacking of proper &#8220;tuning&#8221; of the parameters, but this type of control didn&#8217;t work for me.  So I ended up using the potentiometers to just control the power delivered to my heaters (basically, turning my elegant Arduino AC control into a dimmer).  Then the second displays were just used to output the percent power of AC being delivered.</p>
<p>The last little bit of complexity I added (not shown) was to do some data recording using Sparkfun&#8217;s <a href="http://www.sparkfun.com/products/9802" target="_blank">microSD shield</a> (note, it doesn&#8217;t come with header pins).  To get it up and running, make use of their <a href="http://www.sparkfun.com/tutorials/172" target="_blank">Quickstart Guide</a>; it involves downloading a new library and learning a few new commands, but it&#8217;s a great shield to mix into your Arduino rotation.</p>
<p>By the time I got everything wired up (and when I use it, I actually double the number of thermistors and heaters, as well as measure the relative humidity), I use nearly all of the Arduino I/O pins.  But I guess that what an Arduino MEGA or <a href="http://www.arduino.cc/playground/Learning/4051" target="_blank">4051</a> is for.  One thing I did to maximize output while minimizing hardware was to add a flip switch that I would monitor and let it dictate what is output on my serial displays instead of just adding more displays (e.g. an open switch means I&#8217;ll output relative humidity; a closed switch, and I&#8217;ll send temperature as an output).</p>
</div>
<h3>About The Author</h3>
<div class="aboutAuthor"><img src="http://bildr.org/blog/wp-content/uploads/2011/08/user.png" /><br />
<span class="name">K-MOB</span><br />
<span class="about">K-MOB is a mechanical engineer who has learned to stop worrying and love electronics.  He discusses Mythbusters, physics and everyday science at <a href="warningsciencecontent.com">warningsciencecontent.com</a>.</span>
</div>
]]></content:encoded>
			<wfw:commentRss>http://bildr.org/2011/08/user-project-high-voltage-temperature-control/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>One Wire Digital Temperature. DS18B20 + Arduino</title>
		<link>http://bildr.org/2011/07/ds18b20-arduino/</link>
		<comments>http://bildr.org/2011/07/ds18b20-arduino/#comments</comments>
		<pubDate>Fri, 08 Jul 2011 12:22:43 +0000</pubDate>
		<dc:creator>ameyer</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[DS18B20]]></category>
		<category><![CDATA[Temperature]]></category>
		<category><![CDATA[Temperature Sensor]]></category>

		<guid isPermaLink="false">http://bildr.org/?p=1470</guid>
		<description><![CDATA[
I know&#8230; you are probably thinking &#8220;Another Thermometer! How many do you need to cover?&#8221; &#8211; Well&#8230; All of them. But really, they all have something different to offer. For instance this guy, the DS18B20, has a unique serial-number sent with it&#8217;s data, so if you needed to have 50 of these on one bus, [...]
]]></description>
			<content:encoded><![CDATA[<p><img class="noFrame" src="http://bildr.org/blog/wp-content/uploads/2011/07/DS18S20.jpg"/></p>
<div class="columnBody">
<div class="leftColumn">
I know&#8230; you are probably thinking &#8220;Another Thermometer! How many do you need to cover?&#8221; &#8211; Well&#8230; All of them. But really, they all have something different to offer. For instance this guy, the <a href="http://www.sparkfun.com/products/245">DS18B20</a>, has a unique serial-number sent with it&#8217;s data, so if you needed to have 50 of these on one bus, you could and still know exactly where the reading came from. And&#8230; It&#8217;s <a href="http://wiki.bildr.org/index.php/digital">digital</a> <a href="http://wiki.bildr.org/index.php/serial">serial</a> bus it uses to transmit the date is just one wire.</p>
<p>For this tutorial we will be using just one of them, and our code will only support the one. So if you need to read from a few or a lot of these, contact us in the forum and we can help you out.  There is also a good amount of code out there for using a bunch of these at once, but no examples of just the one.</p>
<h3>Hooking it up</h3>
<p>This is by far one of the more simple digital sensors to hookup. Aside from power and ground, it has a single digital signal pin that we will be connecting to digital pin 2 on our arduino. It also requires a 4.7k <a href="http://wiki.bildr.org/index.php/Pull_Up_Resistor">pull-up resistor</a> between the signal and power pin as shown in the illustration. (I tried the internal pull-ups on the arduino but it did not work)</p>
<p>There is a way this sensor can be hooked up with just 2 wires (no power), but it slows the code down, so I decided not to go that way.</p>
</div>
<div class="rightColumn">
<p><a href="http://bildr.org/blog/wp-content/uploads/2011/06/DS18S20-hookup.png"><img src="http://bildr.org/blog/wp-content/uploads/2011/06/DS18S20-hookup-400x237.png" alt="" title="DS18S20-hookup" width="400" height="237" class="alignleft size-medium wp-image-1472" /></a></p>
</div>
</div>
<h3>Code</h3>
<p>The code on the official <a href="http://www.arduino.cc/playground/Learning/OneWire">Arduino site was overly complex</a> and didn&#8217;t even return a number value at the end. This is much simpler, but only supports a single sensor on the bus as it is. Again, if you need more, ask us in the comments. This code will simply print a decimal value of the temperature in degrees Celsius to the serial terminal.</p>
<div class="columnBody">
<div class="leftColumn">
<p>To make this code work, <strong>before you load the code, or even open the Arduino program</strong>, we need to place the “OneWire” folder into your Arduino Library. If you don’t know where that is by default, Look to the right.</p>
<p>If you click the download button to the right of “Arduino” you can download the whole thing as a zip, so you dont need to copy all the files.</p>
</div>
<div class="rightColumn">
<h3>Default Library Folder Location</h3>
<p><span style="font-size: 10px; line-height:12px;"><strong>On your Mac:</strong>: In (home directory)/Documents/Arduino/libraries<br />
<strong>On your PC:</strong>: My Documents -> Arduino -> libraries<br />
<strong>On your Linux box:</strong>: (home directory)/sketchbook/libraries<br />
</span></p>
</div>
</div>

	<div class="clear">
	<script src="http://code.bildr.org/render/DS18B20/arduino.js"></script>
	</div>
	
]]></content:encoded>
			<wfw:commentRss>http://bildr.org/2011/07/ds18b20-arduino/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Line Sensing. QRE1113 Reflectance Sensor + Arduino</title>
		<link>http://bildr.org/2011/06/qre1113-arduino/</link>
		<comments>http://bildr.org/2011/06/qre1113-arduino/#comments</comments>
		<pubDate>Mon, 27 Jun 2011 13:41:33 +0000</pubDate>
		<dc:creator>ameyer</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[IR]]></category>
		<category><![CDATA[Line Sensor]]></category>
		<category><![CDATA[Proximity]]></category>
		<category><![CDATA[QRE1113]]></category>

		<guid isPermaLink="false">http://bildr.org/?p=1510</guid>
		<description><![CDATA[
The QRE1113 is a common reflectance sensor often used in robotic line followers. The sensor works by shining an IR LED down and seeing how much of that light bounces back using a phototransistor. Because dark colors will bounce back less of the light, the sensor can be used to tell the difference between white [...]
]]></description>
			<content:encoded><![CDATA[<p><img class="noFrame" src="http://bildr.org/blog/wp-content/uploads/2011/06/QRE113.jpg"/></p>
<div class="columnBody">
<div class="leftColumn">
<p>The QRE1113 is a common reflectance sensor often used in robotic line followers. The sensor works by shining an <a href="http://wiki.bildr.org/index.php/IR">IR</a> <a href="http://wiki.bildr.org/index.php/LED">LED</a> down and seeing how much of that light bounces back using a <a href="http://wiki.bildr.org/index.php/phototransistor">phototransistor</a>. Because dark colors will bounce back less of the light, the sensor can be used to tell the difference between white and black areas. So an array of these can be used to help a robot determine where a dark line is on the ground so it can follow it. But they can also be used to determine proximity under an inch.</p>
<p>Both <a href="http://www.pololu.com/">Pololu</a> and <a href="http://www.sparkfun.com">Sparkfun</a> sell <a href="http://www.sparkfun.com/products/9454">digital</a> and <a href="http://www.sparkfun.com/products/9453">analog</a> models of a QRE1113 breakout board. The <a href="http://www.pololu.com/catalog/product/958">analog version</a> is very simple, it just outputs an analog voltage on the signal pin relative to how much light was reflected. And you might think the <a href="http://www.pololu.com/catalog/product/959">digital version</a>, especially being called a line sensor by sparkfun, would just output HIGH when it sees a line, and LOW when it does not. But this is not the case.</p>
<p>The digital version is designed for times you do not have an <a href="http://wiki.bildr.org/index.php/analog">analog</a> input on your <a href="http://wiki.bildr.org/index.php/microcontroller">microcontroller</a> but still need an analog reading of how much light was reflected. It does this by allowing you to charge a <a href="http://wiki.bildr.org/index.php/capacitor">capacitor</a> on the board, and then timing how long it takes to discharge. The more light that is reflected, the less time it takes to discharge the capacitor. In my tests, the times ranged between 10 microseconds (10/million) to 2.5 milliseconds, so this is all done very quickly and wont put much of a delay in your code.</p>
<h3>Hooking Them Up</h3>
<p>Hooking the QRE1113 to your Arduino is very simple. It just needs power (5V), <a href="http://wiki.bildr.org/index.php/ground">ground</a>, and an <a href="http://wiki.bildr.org/index.php/analog">analog</a> or <a href="http://wiki.bildr.org/index.php/digital">digital</a> pin depending on what version you have.</p>
</div>
<div class="rightColumn">
<p><a href="http://bildr.org/blog/wp-content/uploads/2011/06/QRE113_analog.png"><img src="http://bildr.org/blog/wp-content/uploads/2011/06/QRE113_analog-400x275.png" alt="" title="QRE1113_analog" width="400" height="275" class="alignleft size-medium wp-image-1533" /></a></p>
<p><a href="http://bildr.org/blog/wp-content/uploads/2011/06/QRE113_digital.png"><img src="http://bildr.org/blog/wp-content/uploads/2011/06/QRE113_digital-400x275.png" alt="" title="QRE1113_digital" width="400" height="275" class="alignleft size-medium wp-image-1534" /></a></p>
</div>
</div>
<h3>Code</h3>
<p>The method of reading the values from the analog and digital version is very different, so we have 2 code examples for you.</p>
<h4>Analog Version</h4>
<div class="codesnip-container" >
<div class="codeHead">
				<a class="copy" href="#">Copy Code</a>
			</div>
<pre class="arduino codesnip" style="font-family:monospace;"><span class="co1">//Code for the QRE1113 Analog board</span>
<span class="co1">//Outputs via the serial terminal - Lower numbers mean more reflected</span>
<span class="kw4">int</span> QRE1113_Pin <span class="sy0">=</span> <span class="nu0">0</span><span class="sy0">;</span> <span class="co1">//connected to analog 0</span>

<span class="kw4">void</span> setup<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span>
  <span class="kw3">Serial</span>.<span class="me1">begin</span><span class="br0">&#40;</span>9600<span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span>

<span class="kw4">void</span> loop<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span>

  <span class="kw4">int</span> QRE_Value <span class="sy0">=</span> <span class="kw3">analogRead</span><span class="br0">&#40;</span>QRE1113_Pin<span class="br0">&#41;</span><span class="sy0">;</span>
  <span class="kw3">Serial</span>.<span class="me1">println</span><span class="br0">&#40;</span>QRE_Value<span class="br0">&#41;</span><span class="sy0">;</span> 

<span class="br0">&#125;</span></pre>
<div class="codeFoot">
				Unless otherwise stated, this code is released under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT License</a> &#8211; Please use, change and share it.
			</div>
</p></div>
<h4>Digital Version</h4>
<div class="codesnip-container" >
<div class="codeHead">
				<a class="copy" href="#">Copy Code</a>
			</div>
<pre class="arduino codesnip" style="font-family:monospace;"><span class="co1">//Code for the QRE1113 Digital board</span>
<span class="co1">//Outputs via the serial terminal - Lower numbers mean more reflected</span>
<span class="co1">//3000 or more means nothing was reflected.</span>

<span class="kw4">int</span> QRE1113_Pin <span class="sy0">=</span> <span class="nu0">2</span><span class="sy0">;</span> <span class="co1">//connected to digital 2</span>

<span class="kw4">void</span> setup<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span>
  <span class="kw3">Serial</span>.<span class="me1">begin</span><span class="br0">&#40;</span>9600<span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span>

<span class="kw4">void</span> loop<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span>

  <span class="kw4">int</span> QRE_Value <span class="sy0">=</span> readQD<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
  <span class="kw3">Serial</span>.<span class="me1">println</span><span class="br0">&#40;</span>QRE_Value<span class="br0">&#41;</span><span class="sy0">;</span> 

<span class="br0">&#125;</span>

<span class="kw4">int</span> readQD<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span>
  <span class="co1">//Returns value from the QRE1113 </span>
  <span class="co1">//Lower numbers mean more refleacive</span>
  <span class="co1">//More than 3000 means nothing was reflected.</span>
  <span class="kw3">pinMode</span><span class="br0">&#40;</span> QRE1113_Pin<span class="sy0">,</span> <span class="kw2">OUTPUT</span> <span class="br0">&#41;</span><span class="sy0">;</span>
  <span class="kw3">digitalWrite</span><span class="br0">&#40;</span> QRE1113_Pin<span class="sy0">,</span> <span class="kw2">HIGH</span> <span class="br0">&#41;</span><span class="sy0">;</span>
  <span class="kw3">delayMicroseconds</span><span class="br0">&#40;</span>10<span class="br0">&#41;</span><span class="sy0">;</span>
  <span class="kw3">pinMode</span><span class="br0">&#40;</span> QRE1113_Pin<span class="sy0">,</span> <span class="kw2">INPUT</span> <span class="br0">&#41;</span><span class="sy0">;</span>

  <span class="kw4">long</span> time <span class="sy0">=</span> <span class="kw3">micros</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>

  <span class="co1">//time how long the input is HIGH, but quit after 3ms as nothing happens after that</span>
  <span class="kw1">while</span> <span class="br0">&#40;</span><span class="kw3">digitalRead</span><span class="br0">&#40;</span>QRE1113_Pin<span class="br0">&#41;</span> <span class="sy0">==</span> <span class="kw2">HIGH</span> <span class="sy0">&amp;&amp;</span> <span class="kw3">micros</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="sy0">-</span> time <span class="sy0">&lt;</span> 3000<span class="br0">&#41;</span><span class="sy0">;</span>
  <span class="kw4">int</span> diff <span class="sy0">=</span> <span class="kw3">micros</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="sy0">-</span> time<span class="sy0">;</span>

  <span class="kw1">return</span> diff<span class="sy0">;</span>
<span class="br0">&#125;</span></pre>
<div class="codeFoot">
				Unless otherwise stated, this code is released under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT License</a> &#8211; Please use, change and share it.
			</div>
</p></div>
]]></content:encoded>
			<wfw:commentRss>http://bildr.org/2011/06/qre1113-arduino/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

