<?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>ArduinoFun.com Blog &#187; Arduino Sketch</title>
	<atom:link href="http://arduinofun.com/blog/index.php/tag/arduino-sketch/feed/" rel="self" type="application/rss+xml" />
	<link>http://arduinofun.com/blog</link>
	<description>- Think It - Build It - Share It -</description>
	<lastBuildDate>Thu, 01 Apr 2010 22:39:59 +0000</lastBuildDate>
	
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>JoyLite Maze (Build It!)</title>
		<link>http://arduinofun.com/blog/2009/12/31/joylite-maze-build-it/</link>
		<comments>http://arduinofun.com/blog/2009/12/31/joylite-maze-build-it/#comments</comments>
		<pubDate>Thu, 31 Dec 2009 14:35:46 +0000</pubDate>
		<dc:creator>Administrator</dc:creator>
				<category><![CDATA[Contest Entries]]></category>
		<category><![CDATA[8x8 RGB LED Matrix]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Arduino Sketch]]></category>
		<category><![CDATA[Arduino Tutorial]]></category>
		<category><![CDATA[Atari joystick]]></category>
		<category><![CDATA[JoyLite Maze]]></category>
		<category><![CDATA[LED]]></category>
		<category><![CDATA[rainbowduino]]></category>
		<category><![CDATA[RGB Matrix]]></category>

		<guid isPermaLink="false">http://arduinofun.com/blog/?p=377</guid>
		<description><![CDATA[Contest Entry by Joe Cochran
In another project, I created a way to control a 8&#215;8 RGB Matrix using an Atari Joystick. While waiting for one of the components to arrive, I had an idea that a maze could be constructed on the RGB Matrix and a user could go through the maze with a joystick.

Most [...]]]></description>
			<content:encoded><![CDATA[<p>Contest Entry by <a href="http://sites.google.com/site/joetcochran/home">Joe Cochran</a><br />
In <a href="http://sites.google.com/site/joetcochran/thejoyliteproject">another project</a>, I created a way to control a <strong>8&#215;8 RGB Matrix</strong> using an Atari Joystick. While waiting for one of the components to arrive, I had an idea that a maze could be constructed on the RGB Matrix and a user could go through the maze with a joystick.</p>
<p style="text-align: center;"><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="350" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="src" value="http://www.youtube.com/v/53seGJ-mPiI" /><embed type="application/x-shockwave-flash" width="425" height="350" src="http://www.youtube.com/v/53seGJ-mPiI"></embed></object></p>
<div>Most maze algorithms assume that the maze can have &#8220;paper-thin&#8221; walls. That is, that the occupiable spaces don&#8217;t occupy the same amount of space as the walls. However, with the RGB Matrix the walls have to be represented by a whole LED being turned on. So in essence each LED is marked as a &#8220;wall&#8221; or as an &#8220;occupiable space&#8221;</div>
<div>Joe has created a page that contains the detailed instructions on how to create your own JoyLite Maze. I am posting the link to it, rather than recreating it all again.</div>
<p><a href="http://sites.google.com/site/joetcochran/joylite-maze/how-to">JoyLite Maze &#8220;How To&#8221;</a>.</p>
<blockquote>
<div>Joe Says:Arduino has been a fantastic opportunity to for me rediscover the creative process. I became a software developer because I get a lot of satisfaction from turning an idea into reality. When you get down to it though, professional software development ends up being little more than manipulating some bits in databases and RAM. Nothing tangible. Arduino has allowed me to move beyond the &#8220;cyberspace&#8221; and into the &#8220;real world&#8221;, opening the door to physical computing with motors, switches, lights and dials. And while I may be short on knowledge in regards to the electrical and mechanical engineering aspects of these projects, the Arduino community is so healthy, friendly and capable that they help make learning this stuff a real treat too.</div>
</blockquote>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Farduinofun.com%2Fblog%2F2009%2F12%2F31%2Fjoylite-maze-build-it%2F&amp;linkname=JoyLite%20Maze%20%28Build%20It%21%29"><img src="http://arduinofun.com/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://arduinofun.com/blog/2009/12/31/joylite-maze-build-it/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Start Here Arduino Robot (Build It!)</title>
		<link>http://arduinofun.com/blog/2009/12/30/start-here-arduino-robot-build-it/</link>
		<comments>http://arduinofun.com/blog/2009/12/30/start-here-arduino-robot-build-it/#comments</comments>
		<pubDate>Wed, 30 Dec 2009 18:19:34 +0000</pubDate>
		<dc:creator>Administrator</dc:creator>
				<category><![CDATA[Contest Entries]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Arduino Code]]></category>
		<category><![CDATA[Arduino Robot]]></category>
		<category><![CDATA[Arduino Sketch]]></category>
		<category><![CDATA[Infrared  Sensors]]></category>
		<category><![CDATA[L239D Motor Driver]]></category>
		<category><![CDATA[Micro Servos]]></category>
		<category><![CDATA[Start Here Robot]]></category>

		<guid isPermaLink="false">http://arduinofun.com/blog/?p=372</guid>
		<description><![CDATA[Contest entry by Dane Edmonds. This is my first robot using Arduino , it uses a l239d motor driver and is basically my attempt at making a &#8220;start here&#8221; robot.
This is my first time using Arduino so I decided to build a robot that would help me learn arduino&#8217;s code , I wanted to start [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_373" class="wp-caption alignleft" style="width: 330px"><img class="size-full wp-image-373" title="Arduino Start Here Robot" src="http://arduinofun.com/blog/wp-content/uploads/2009/12/bir1.jpg" alt="Arduino Start Here Robot" width="320" height="240" /><p class="wp-caption-text">Arduino Start Here Robot</p></div>
<p>Contest entry by <a href="http://letsmakerobots.com/user/4333">Dane Edmonds</a>. This is my first robot using Arduino , it uses a l239d motor driver and is basically my attempt at making a <a href="http://letsmakerobots.com/start">&#8220;start here&#8221; robot</a>.</p>
<p>This is my first time using Arduino so I decided to build a robot that would help me learn arduino&#8217;s code , I wanted to start small and build up to harder things so I made the robot expandable , as I get better with coding I will add more things .  So I hope other people who are new to arduino can learn from this robot to</p>
<blockquote><p>Dane says: Arduino has meant a cheap and easy to use micro controller, giving people a chance to achieve their goals and has helped make school holidays less boring for me .</p></blockquote>
<p><a href="http://www.youtube.com/watch?v=561TOfpcI_Y">YouTube Video Available Here.</a></p>
<p><span id="more-372"></span></p>
<p><strong>Parts list :</strong></p>
<ul>
<li>1) Arduino starter pack X1 <a href="http://www.robotgear.com.au/Product.aspx/Details/337">http://www.robotgear.com.au/Product.aspx/Details/337</a></li>
<li>2) Solarbotics g8 motors and wheels X2 <a href="http://www.robotgear.com.au/Product.aspx/Details/316">http://www.robotgear.com.au/Product.aspx/Details/316</a></li>
<li>3) motor mounts for the g8s <a href="http://www.robotgear.com.au/Product.aspx/Details/323">http://www.robotgear.com.au/Product.aspx/Details/323</a> (I didn&#8217;t use them but they would be better) X2</li>
<li>4) infrared sensors X2 <a href="http://www.robotgear.com.au/Product.aspx/Details/309">http://www.robotgear.com.au/Product.aspx/Details/309</a></li>
<li>5) breadboard (about the same size as Arduino )</li>
<li>6) micro servos X2</li>
<li>7) l293d motor controller <a href="http://www.robotgear.com.au/Product.aspx/Details/345">http://www.robotgear.com.au/Product.aspx/Details/345</a></li>
<li> <img src='http://arduinofun.com/blog/wp-includes/images/smilies/icon_cool.gif' alt='8)' class='wp-smiley' /> some header pins (cut into 3 and solder wires to each pin)</li>
</ul>
<p><strong>Things you can add : </strong></p>
<ul>
<li><a href="http://www.robotgear.com.au/Product.aspx/Details/286">http://www.robotgear.com.au/Product.aspx/Details/286</a></li>
<li><a href="http://www.robotgear.com.au/Product.aspx/Details/347">http://www.robotgear.com.au/Product.aspx/Details/347</a></li>
</ul>
<p><strong>Build It! instructions:</strong></p>
<ul>
<li>1) cut thin scrap wood (about 8 millimeters thick) in to 2 squares of 13.5 cm x 13.5 cm</li>
<li>2) in one of the squares cut hole the same size as your servo base , about 1cm from one of the edges .</li>
<li>3) paint desired colour</li>
<li>4) using a hot glue gun glue the motors in place (as shown in top picture), with some small screws ,screw in the Arduino to the breadboard will have adhesive tape on the back, peel of plastic and stick in place.</li>
<li>5) using this walk through set up your motor controller <a href="http://letsmakerobots.com/node/2074">http://letsmakerobots.com/node/2074</a></li>
<li>6) drill 2 holes in the back corners of the wood to fit your spacers and one above the Arduino (do the same for the 2nd piece of wood .</li>
<li>7) put your servo in place , and screw into wood</li>
<li> <img src='http://arduinofun.com/blog/wp-includes/images/smilies/icon_cool.gif' alt='8)' class='wp-smiley' />  made a pan/tilt system with a bit of scrap metal , (you can do the same if you wish but is not needed )</li>
<li>9) screw in your infrared sensers(as shown below) attach header pins (look on the sensor connect VIN and GND to the bread board power lines  and OUT to a digital pin on your arduino.</li>
</ul>
<p><strong>Arduino Sketch</strong></p>
<pre>const <span style="color: #CC6600;">int</span> infra=3; 

const <span style="color: #CC6600;">int</span> infra2=4;  

  <span style="color: #CC6600;">void</span> <span style="color: #CC6600;"><strong>setup</strong></span>()

 {    

<span style="color: #CC6600;">Serial</span>.<span style="color: #CC6600;">begin</span>(9600);
<span style="color: #CC6600;">pinMode</span>(13,<span style="color: #006699;">OUTPUT</span>);
<span style="color: #CC6600;">pinMode</span>(12,<span style="color: #006699;">OUTPUT</span>);
<span style="color: #CC6600;">pinMode</span> (11,<span style="color: #006699;">OUTPUT</span>);
<span style="color: #CC6600;">pinMode</span> (10,<span style="color: #006699;">OUTPUT</span>);
<span style="color: #CC6600;">pinMode</span> (infra,<span style="color: #006699;">INPUT</span>);
<span style="color: #CC6600;">pinMode</span> (infra2,<span style="color: #006699;">INPUT</span>); 

} 

 <span style="color: #CC6600;">void</span> <span style="color: #CC6600;"><strong>loop</strong></span>()    {
<span style="color: #CC6600;">if</span> (<span style="color: #CC6600;">digitalRead</span>(infra)== <span style="color: #006699;">HIGH</span>)
{         driveforward();   

   }        

<span style="color: #CC6600;">if</span>(<span style="color: #CC6600;">digitalRead</span>(infra) == <span style="color: #006699;">LOW</span>)   

{       

  stopmot();      

  <span style="color: #CC6600;">delay</span> (500);      

  reverse();      

  <span style="color: #CC6600;">delay</span> (500);       

 right();        

<span style="color: #CC6600;">delay</span> (2000);  

  }         

  <span style="color: #CC6600;">else</span> <span style="color: #CC6600;">if</span> (<span style="color: #CC6600;">digitalRead</span>(infra2)== <span style="color: #006699;">LOW</span>)   

   { stopmot();       

 <span style="color: #CC6600;">delay</span> (500);      

  reverse();     

   <span style="color: #CC6600;">delay</span> (500);       

 left();        

<span style="color: #CC6600;">delay</span> (2000);     

 }   

         }             

  <span style="color: #CC6600;">void</span> driveforward()

 {   <span style="color: #CC6600;">digitalWrite</span>(13,<span style="color: #006699;">HIGH</span>);   

<span style="color: #CC6600;">digitalWrite</span>(10,<span style="color: #006699;">HIGH</span>);  

 <span style="color: #CC6600;">digitalWrite</span> (11,<span style="color: #006699;">LOW</span>); 

  <span style="color: #CC6600;">digitalWrite</span> (12,<span style="color: #006699;">LOW</span>);

 } 

 <span style="color: #CC6600;">void</span> stopmot()

 {    

<span style="color: #CC6600;">digitalWrite</span>(13,<span style="color: #006699;">LOW</span>);  

 <span style="color: #CC6600;">digitalWrite</span>(12,<span style="color: #006699;">LOW</span>);   

<span style="color: #CC6600;">digitalWrite</span>(11,<span style="color: #006699;">LOW</span>);  

 <span style="color: #CC6600;">digitalWrite</span>(10,<span style="color: #006699;">LOW</span>);

 } 

<span style="color: #CC6600;">void</span> reverse() 

{ 

  <span style="color: #CC6600;">digitalWrite</span>(12,<span style="color: #006699;">HIGH</span>);  

 <span style="color: #CC6600;">digitalWrite</span>(11,<span style="color: #006699;">HIGH</span>); 

  <span style="color: #CC6600;">digitalWrite</span> (13,<span style="color: #006699;">LOW</span>); 

  <span style="color: #CC6600;">digitalWrite</span> (10,<span style="color: #006699;">LOW</span>);

 } 

 <span style="color: #CC6600;">void</span> right()

 {   

<span style="color: #CC6600;">digitalWrite</span> (10,<span style="color: #006699;">HIGH</span>); 

  <span style="color: #CC6600;">digitalWrite</span> (13,<span style="color: #006699;">LOW</span>);  

 <span style="color: #CC6600;">digitalWrite</span> (12,<span style="color: #006699;">LOW</span>);  

 <span style="color: #CC6600;">digitalWrite</span> (11,<span style="color: #006699;">LOW</span>);

 } 

 <span style="color: #CC6600;">void</span> left()

 {  

 <span style="color: #CC6600;">digitalWrite</span> (13,<span style="color: #006699;">HIGH</span>); 

  <span style="color: #CC6600;">digitalWrite</span> (11,<span style="color: #006699;">LOW</span>);  

 <span style="color: #CC6600;">digitalWrite</span>  (12,<span style="color: #006699;">LOW</span>); 

  <span style="color: #CC6600;">digitalWrite</span> (10,<span style="color: #006699;">LOW</span>);

}</pre>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Farduinofun.com%2Fblog%2F2009%2F12%2F30%2Fstart-here-arduino-robot-build-it%2F&amp;linkname=Start%20Here%20Arduino%20Robot%20%28Build%20It%21%29"><img src="http://arduinofun.com/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://arduinofun.com/blog/2009/12/30/start-here-arduino-robot-build-it/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Connecting a 7-segment LED to the Arduino (Build It)</title>
		<link>http://arduinofun.com/blog/2009/12/06/connecting-a-7-segment-led-to-the-arduino-build-it/</link>
		<comments>http://arduinofun.com/blog/2009/12/06/connecting-a-7-segment-led-to-the-arduino-build-it/#comments</comments>
		<pubDate>Sun, 06 Dec 2009 14:36:32 +0000</pubDate>
		<dc:creator>Administrator</dc:creator>
				<category><![CDATA[Contest Entries]]></category>
		<category><![CDATA[7-Segment LED]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Arduino Code]]></category>
		<category><![CDATA[Arduino Sketch]]></category>
		<category><![CDATA[Arduino Starter Kit]]></category>
		<category><![CDATA[Arduino Tutorial]]></category>
		<category><![CDATA[LED]]></category>

		<guid isPermaLink="false">http://arduinofun.com/blog/?p=349</guid>
		<description><![CDATA[Fun with Arduino contest entry submitted by Jeff.
For a while now I&#8217;d been interested in things like networked objects and gps/location-awareness, and I think that soon enough we&#8217;re going to see a lot of &#8216;intelligent objects&#8217; out and about in the world.
I love the idea of being able to actually build something like that, but [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_350" class="wp-caption alignleft" style="width: 260px"><img class="size-full wp-image-350" title="7-Segment LED" src="http://arduinofun.com/blog/wp-content/uploads/2009/12/LED.jpg" alt="7-Segment LED" width="250" height="284" /><p class="wp-caption-text">7-Segment LED</p></div>
<p>Fun with Arduino contest entry submitted by <a href="http://totusterra.com/index.php">Jeff</a>.</p>
<p>For a while now I&#8217;d been interested in things like networked objects and gps/location-awareness, and I think that soon enough we&#8217;re going to see a lot of &#8216;intelligent objects&#8217; out and about in the world.</p>
<p>I love the idea of being able to actually build something like that, but there&#8217;s a lot I don&#8217;t know about the hardware side of things. What little electronics I studied was long in the past; I&#8217;d done a little coding for microcontrollers, but only a little. But there was something about the Arduino that made it seem more accessible.</p>
<p>So my wonderful wife, who is wonderful if I didn&#8217;t mention that, bought me the <a href="http://www.makershed.com/ProductDetails.asp?ProductCode=MSAPK2&amp;Show=TechSpecs" target="_blank">&#8220;Arduino Advanced Starter Kit&#8221;</a> and the accompanying book <a href="http://www.makershed.com/ProductDetails.asp?ProductCode=9780596155513">&#8220;Getting Started with the Arduino&#8221;</a> for my birthday.  Yay!</p>
<p><span id="more-349"></span></p>
<p>I have had enough hardware exposure that nothing in the package was a total mystery, and I understood the concept of breadboarding a circuit, so it only took maybe 15 minutes to get the software installed, a basic circuit built (ok, I stuck a LED onto two pins on the board), and wrote my first &#8216;hello world&#8217; blinky-light program. The Arduino uses the aptly named <a href="http://www.arduino.cc/en/Reference/HomePage">Arduino language</a> &#8212; it seems to be C with a light wrapper and a library, so it came pretty naturally.</p>
<p>Following along with the exercises in Getting Started, I experimented with the with the various inputs and outputs, got some hands-on-experience building the circuits out. It didn&#8217;t take me long at all to start wandering off-script and just building out random ideas that involved an LED and a button.</p>
<p>After a few hours, I thought it would be fun to do something a little more challenging. I went and went and picked up an 7-segment LED (<a href="http://www.radioshack.com/product/index.jsp?productId=2062557" target="_blank">Radio Shack part 276-075</a>).  With the pin designations, it was pretty easy to hook the 7 segments up to 7 outputs on the Arduino board.</p>
<p>On the software side, I mapped the segments onto bits &#8211; bit 0 maps to anode A, bit 1 to anode B, etc. &#8212; so the state of all 7 segments can be represented in a single byte. With the relatively small amount of memory available, compact representations are a good thing. Going the other way, I can look at that byte, and read each of the bits with bitRead() function, then set the LED segment appropriately.</p>
<p>Now that I had a working numeric LED, I needed a value to show on it. Borrowing a simple example from Getting Started, I wired up a photoresistor and had it report it&#8217;s state to Arduino&#8217;s analog input 0.</p>
<div id="attachment_351" class="wp-caption aligncenter" style="width: 450px"><img class="size-full wp-image-351" title="Arduino and 7-Segment LED" src="http://arduinofun.com/blog/wp-content/uploads/2009/12/lightreporting.jpg" alt="Arduino and 7-Segment LED" width="440" height="600" /><p class="wp-caption-text">Arduino and 7-Segment LED</p></div>
<p>The analog inputs report a value from 0-1023 but my LED can only display 0-9, so I used the map() function to convert the input range to the output range and get the corresponding value back out &#8212; then display that. To help stabilize the number and keep it from flickering between values too quickly, I only update the LED if the value has changed, and then hold for a moment.</p>
<p>The full source code is below:</p>
<pre>#define PHOTO 0

<span style="color: #CC6600;">void</span> <span style="color: #CC6600;"><strong>setup</strong></span>()
{
  <span style="color: #CC6600;">pinMode</span>(0, <span style="color: #006699;">OUTPUT</span>); <span style="color: #7E7E7E;">// -&gt; Anode A, bit 0 in the definitions</span>
  <span style="color: #CC6600;">pinMode</span>(1, <span style="color: #006699;">OUTPUT</span>); <span style="color: #7E7E7E;">// -&gt; Anode B, bit 1</span>
  <span style="color: #CC6600;">pinMode</span>(2, <span style="color: #006699;">OUTPUT</span>); <span style="color: #7E7E7E;">// -&gt; Anode C, bit 2</span>
  <span style="color: #CC6600;">pinMode</span>(3, <span style="color: #006699;">OUTPUT</span>); <span style="color: #7E7E7E;">// -&gt; Anode D, bit 3</span>
  <span style="color: #CC6600;">pinMode</span>(4, <span style="color: #006699;">OUTPUT</span>); <span style="color: #7E7E7E;">// -&gt; Anode E, bit 4</span>
  <span style="color: #CC6600;">pinMode</span>(5, <span style="color: #006699;">OUTPUT</span>); <span style="color: #7E7E7E;">// -&gt; Anode F, bit 5</span>
  <span style="color: #CC6600;">pinMode</span>(6, <span style="color: #006699;">OUTPUT</span>); <span style="color: #7E7E7E;">// -&gt; Anode G, bit 6</span>
}

<span style="color: #7E7E7E;">// encode the on/off state of the LED segments for the characters</span>
<span style="color: #7E7E7E;">// '0' to '9' into the bits of the bytes</span>
const <span style="color: #CC6600;">byte</span> numDef[10] = { 63, 6, 91, 79, 102, 109, 124, 7, 127, 103 };

<span style="color: #7E7E7E;">// keep track of the old value</span>
<span style="color: #CC6600;">int</span> oldVal = -1;

<span style="color: #CC6600;">void</span> <span style="color: #CC6600;"><strong>loop</strong></span>()
{
  <span style="color: #7E7E7E;">// grab the input from the photoresistor</span>
  <span style="color: #CC6600;">int</span> input = <span style="color: #CC6600;">analogRead</span>(PHOTO);

  <span style="color: #7E7E7E;">// convert the input range (0-1023) to the range we can</span>
  <span style="color: #7E7E7E;">// display on the LED (0-9)</span>
  <span style="color: #CC6600;">int</span> displayVal = <span style="color: #CC6600;">map</span>(input, 0, 1023, 0, 9);

  <span style="color: #7E7E7E;">// if the value has changed, then update the LED and hold for a</span>
  <span style="color: #7E7E7E;">// brief moment to help with the debouncing.</span>
  <span style="color: #CC6600;">if</span> (displayVal != oldVal)
  {
    setSegments( numDef[displayVal] );
    <span style="color: #CC6600;">delay</span>(250);
  }
}

<span style="color: #CC6600;">void</span> setSegments(<span style="color: #CC6600;">byte</span> segments)
{
  <span style="color: #7E7E7E;">// for each of the segments of the LED</span>
  <span style="color: #CC6600;">for</span> (<span style="color: #CC6600;">int</span> s = 0; s &lt; 7; s++)
  {
    <span style="color: #CC6600;">int</span> bitVal = <span style="color: #CC6600;">bitRead</span>( segments, s ); <span style="color: #7E7E7E;">// grab the bit</span>
    <span style="color: #CC6600;">digitalWrite</span>(s, bitVal); <span style="color: #7E7E7E;">// set the segment</span>
  }
}</pre>
<p>Jeff also has another great Arduino tutorial for</p>
<h3><a href="http://totusterra.com/index.php/2009/10/31/using-the-555-timer-as-an-external-clock">Using the 555 timer as an external clock for the Arduino</a></h3>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Farduinofun.com%2Fblog%2F2009%2F12%2F06%2Fconnecting-a-7-segment-led-to-the-arduino-build-it%2F&amp;linkname=Connecting%20a%207-segment%20LED%20to%20the%20Arduino%20%28Build%20It%29"><img src="http://arduinofun.com/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://arduinofun.com/blog/2009/12/06/connecting-a-7-segment-led-to-the-arduino-build-it/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>LED Cube and Arduino Lib (Build It)</title>
		<link>http://arduinofun.com/blog/2009/12/02/led-cube-and-arduino-lib-build-it/</link>
		<comments>http://arduinofun.com/blog/2009/12/02/led-cube-and-arduino-lib-build-it/#comments</comments>
		<pubDate>Wed, 02 Dec 2009 11:56:33 +0000</pubDate>
		<dc:creator>Administrator</dc:creator>
				<category><![CDATA[Contest Entries]]></category>
		<category><![CDATA[3x3x3 LED cube]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Arduino Library]]></category>
		<category><![CDATA[Arduino Sketch]]></category>
		<category><![CDATA[Arduino Tutorial]]></category>
		<category><![CDATA[LED cube]]></category>

		<guid isPermaLink="false">http://arduinofun.com/blog/?p=331</guid>
		<description><![CDATA[Fun with Arduino contest entry submitted by Gamaiel Zavala.
There are other Instructables about building LED cubes, this one is different for several reasons:
1. It&#8217;s built with a low number of off-the-shelf components and hooks up directly to the Arduino.
2. A clear, easy to reproduce circuit diagram is provided with plenty of photos.
3. A unique approach [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_332" class="wp-caption alignleft" style="width: 250px"><img class="size-full wp-image-332" title="LED Cube with Arduino" src="http://arduinofun.com/blog/wp-content/uploads/2009/12/ledcube1.jpg" alt="LED Cube with Arduino" width="240" height="240" /><p class="wp-caption-text">LED Cube with Arduino</p></div>
<p>Fun with Arduino contest entry submitted by Gamaiel Zavala.</p>
<p>There are other <a href="http://www.instructables.com/id/LED-Cube-and-Arduino-Lib/" target="_blank">Instructables</a> about building LED cubes, this one is different for several reasons:</p>
<p>1. It&#8217;s built with a low number of off-the-shelf components and hooks up directly to the Arduino.<br />
2. A clear, easy to reproduce circuit diagram is provided with plenty of photos.<br />
3. A unique approach is used for the software which makes programming the cube easier and more expressive.<br />
<span id="more-331"></span></p>
<p><strong>Parts needed:</strong></p>
<p>-   1 Perfboard<br />
-   3 NPN Transistors (2N2222, 2N3904, BC547, etc.)<br />
- 12 Resistors (~220 ohms and ~22k ohms)<br />
- 13 Headers (male or female)<br />
- 27 LEDs<br />
- Jumper wires</p>
<h2><span>Prepare the LEDs</span></h2>
<div style="margin-left: 0px;">
<div id="attachment_336" class="wp-caption alignleft" style="width: 250px"><img class="size-full wp-image-336" title="LED Jig" src="http://arduinofun.com/blog/wp-content/uploads/2009/12/jig.jpg" alt="LED Jig" width="240" height="240" /><p class="wp-caption-text">LED Jig</p></div>
</div>
<div style="margin-left: 0px;">This step largely follows the <a href="http://www.instructables.com/id/LED-Cube-4x4x4/" target="_blank">LED Cube 4&#215;4x4</a> but we&#8217;ll be building a 3&#215;3x3 cube instead. A cube of this size is about as big as it gets without introducing additional circuitry and complexity. We&#8217;ll need a total of 27 LEDs that will be grouped into three sets of nine.</p>
<p>Each set of nine LEDs will share a common connection amongst their cathodes (negative leads). I&#8217;ll refer to each of these sets as a &#8220;level&#8221;. Each of the nine LEDs on a level is connected to the corresponding LED on the other two levels through their anodes (positive leads). These will be referred to as &#8220;columns&#8221;. If that didn&#8217;t make sense it will become self explanatory as we build the cube.</p>
<p>To start we&#8217;ll use a drill to create a jig out of a small piece of scrap wood. The jig will hold the LEDs in place while we solder them. I decided to space the holes around 5/8 of an inch apart (~15 mm) but the exact distance isn&#8217;t critical. The hole should have a tight fit around the LED since we don&#8217;t want them to move around while soldering.</p>
<div id="attachment_339" class="wp-caption alignleft" style="width: 250px"><img class="size-full wp-image-339" title="Preparing the LEDs" src="http://arduinofun.com/blog/wp-content/uploads/2009/12/led1.jpg" alt="Preparing the LEDs" width="240" height="240" /><p class="wp-caption-text">Preparing the LEDs</p></div>
<p>Once the jig is done we&#8217;re going to bend the cathode of each LED in a 90 degree angle. The cathode is identifiable in three ways: 1) It&#8217;s the shorter leg, 2) It&#8217;s on the flat side of a round LED, 3) it&#8217;s connected to the larger piece inside the LED.  Make sure you bend the cathode in the same direction for all of the LEDs.</p>
<p>Now we&#8217;re ready to begin soldering.</p></div>
<div style="margin-left: 0px;"></div>
<div style="margin-left: 0px;">
<h2></h2>
<h2><span>Solder the LEDs</span></h2>
<div style="margin-left: 0px;">
<div id="attachment_337" class="wp-caption alignleft" style="width: 250px"><img class="size-full wp-image-337" title="LEDs ready to solder." src="http://arduinofun.com/blog/wp-content/uploads/2009/12/solder1.jpg" alt="LEDs ready to solder." width="240" height="240" /><p class="wp-caption-text">LEDs ready to solder.</p></div>
</div>
<div style="margin-left: 0px;">First place nine of the LEDs in your newly built jig. Position them so that the legs point in the same counter-clockwise direction. The photos show the cathode pointing clockwise with the anode facing out, but I&#8217;d turn the LEDs around if I did it again in order to keep the leg from obstructing the view of the LED.</p>
<p>Solder the sides together, one pair on each side. Use small clips to keep the legs clamped together while applying the solder.</p>
<p>Once each of the four sides are soldered, move the clips to hold the corners together and apply solder to each. Lastly, solder the cathode of the middle LED to one of the sides and trim away the excess.</p>
<p>Repeat three times.</p>
<p>You should now have three sets of nine LEDs. Position two of the sets one on top of the other. Keep the distance equal to the spacing already established between LEDs. Once you&#8217;re comfortable with the spacing you can clamp each set of legs using two clips, one in each direction, to keep the legs firmly in place while soldering. You may need to bend around a LED to get a good connection. Solder each of the nine pairs, one at a time.</p>
<p>Do this one more time and you&#8217;re done with the cube.</p>
<p>Place the cube on one side of the the perfboard. Make sure the nine legs are positioned apart evenly while you guide each one  through a hole. My board has five holes between each set of legs. You want to leave as much room as possible on the other end of the perfboard to fit the various components.</p>
<p>Add a few clips to hold the legs in place once you&#8217;re happy with the positioning. Leave plenty of leg poking through the bottom since this will make it easier to solder the resistors later. Turn the board over and solder each of the legs to keep them in place. Flip the cube back over once all the legs have been soldered.</p>
<p>Lastly we need to solder a lead from each of the levels down through the bottom of the board. Strip a piece of solid wire and bend a small hook on one end. Hang the hook on one of the center LEDs legs and guide it through a hole on the perfboard. Solder the hook end to keep the wire in place. Repeat again for the other two levels.</p>
<p>The next step is to build the rest of the circuit.</p></div>
</div>
<div style="margin-left: 0px;"></div>
<div style="margin-left: 0px;">
<h2><span>Build the Circuit</span></h2>
<div style="margin-left: 0px;">
<div id="attachment_341" class="wp-caption alignleft" style="width: 250px"><img class="size-full wp-image-341" title="LED 3x3x3 Cube" src="http://arduinofun.com/blog/wp-content/uploads/2009/12/ledbrd1.jpg" alt="LED 3x3x3 Cube" width="240" height="240" /><p class="wp-caption-text">LED 3x3x3 Cube</p></div>
</div>
<div style="margin-left: 0px;">The circuit is pretty simple. Each of the nine columns will connect to a pin on the Arduino through a current limiting resistor. Each of the three levels connects to ground via a PNP transistor when activated by an Arduino pin.</p>
<p>We&#8217;ll be using 12 output pins total on the Arduino but there are 18 LEDs to power. The trick is that only a single level can be lit at a time. When a level is connected to ground, each of the LEDs on that level can be powered individually through one of the nine other Arduino pins.  If we light the levels fast enough it will appear as if all three levels are lit at the same time.</p>
<p>Let&#8217;s build the circuit.</p>
<p>The first step is to prepare the nine current limiting resistors. I&#8217;m using 220 ohms per pin which will draw around 22mA. The value may vary depending on the LEDs that are being used but stay between about 135 and 470 ohms. Each pin is capable of sourcing up to 40mA.</p>
<p>In order to save room we want to solder the resistors in a vertical position. Bend one lead down so that both leads are parallel to each other. Do this for all nine of the resistors.</p>
<p>Once the resistors are ready we&#8217;ll solder them one by one. To make it easy we&#8217;re going to solder the resistor leads directly to the other components instead of using a separate wire for each. One end of the resistor will connect to a column and the other will connect to a header. Start with the first row of LEDs which is closest to the resistors and work your way back.</p>
<p>Once each row is finished you can use a small piece of tape to isolate the overlapping leads in order to prevent a short. Refer to the photos and diagram to see what this will look like once it&#8217;s finished.</p>
<p>Now that the columns are out of the way, the next step is to solder the components which control the levels. The base of a NPN transistor will be activated by an Arduino pin through a current limiting resistor of 22k (or thereabouts). This will connect the corresponding level to ground which will allow current to flow through the LEDs. Refer to the photos and diagram.</p>
<p>The circuit is now complete, time to move on to the software!</p></div>
</div>
<div style="margin-left: 0px;"></div>
<div style="margin-left: 0px;">
<h2><span>Using the Software</span></h2>
<div style="margin-left: 0px;"><object style="width: 320px; height: 265px;" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="320" height="265" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="src" value="http://www.youtube.com/v/q1Xm2trRTrQ&amp;hl=en_US&amp;fs=1&amp;" /><param name="align" value="left" /><param name="vspace" value="10" /><param name="hspace" value="10" /><embed style="width: 320px; height: 265px;" type="application/x-shockwave-flash" width="320" height="265" src="http://www.youtube.com/v/q1Xm2trRTrQ&amp;hl=en_US&amp;fs=1&amp;" hspace="10" vspace="10" align="left"></embed></object>I was found a few code examples to control LED cubes on the net. They all required large arrays of binary or hex data to instruct the LEDs. I figured that there must be an easier way to program a cube so I set out to write my own software.</p>
<p>The first decision was to make the software mirror the hardware. That meant addressing each LED by column and level instead of using raw port data or the traditional x, y, z. The second decision was to start with basic functions, like turning a single light on or off, and building up from there.</p>
<p>Lastly I decided to introduce two features that are useful for effects. One is a buffer feature which allows the basic functions to build up more complex patterns, and the other is a sequence function which lights an array of lights one at a time or all at once.</p>
<p>This grew organically as procedural code and loose functions. It was very easy from there to follow the <a rel="nofollow" href="http://arduino.cc/en/Hacking/LibraryTutorial">library tutorial</a> in order to encapsulate the functionality into a class and create a reusable Arduino library.</p>
<p>Be sure to check out the <a rel="nofollow" href="http://www.gzipped.com/electronics/arduino/code/ledcube/LedCube.cpp">class</a> and <a rel="nofollow" href="http://www.gzipped.com/electronics/arduino/code/ledcube/ledcube.pde">example sketch</a> or <a rel="nofollow" href="http://www.gzipped.com/electronics/arduino/code/ledcube/LedCube.zip">download the library</a> .</div>
</div>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Farduinofun.com%2Fblog%2F2009%2F12%2F02%2Fled-cube-and-arduino-lib-build-it%2F&amp;linkname=LED%20Cube%20and%20Arduino%20Lib%20%28Build%20It%29"><img src="http://arduinofun.com/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://arduinofun.com/blog/2009/12/02/led-cube-and-arduino-lib-build-it/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Arduino Autonomous Robot</title>
		<link>http://arduinofun.com/blog/2009/11/25/arduino-autonomous-robot/</link>
		<comments>http://arduinofun.com/blog/2009/11/25/arduino-autonomous-robot/#comments</comments>
		<pubDate>Wed, 25 Nov 2009 20:59:10 +0000</pubDate>
		<dc:creator>Administrator</dc:creator>
				<category><![CDATA[Project Files]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Arduino Code]]></category>
		<category><![CDATA[Arduino Robot]]></category>
		<category><![CDATA[Arduino Sketch]]></category>
		<category><![CDATA[Autonomous Robot]]></category>
		<category><![CDATA[IR Sensor]]></category>
		<category><![CDATA[Parallax Ping Sonar]]></category>
		<category><![CDATA[Robot]]></category>
		<category><![CDATA[Sensor]]></category>
		<category><![CDATA[Sharp Sensor]]></category>

		<guid isPermaLink="false">http://arduinofun.com/blog/?p=275</guid>
		<description><![CDATA[This is a repost of a previous project. I am still working to get the older post back online from when we upgraded Wordpress.
The robot was basically built using a Parallax Boe Bot chassis. Rather than using the Basic Stamp we added an Arduino with a proto shield to control the robot functions.
You can use [...]]]></description>
			<content:encoded><![CDATA[<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="320" height="240" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="src" value="http://www.youtube.com/v/6J_eh1HPu54" /><param name="align" value="left" /><param name="vspace" value="5" /><param name="hspace" value="5" /><embed type="application/x-shockwave-flash" width="320" height="240" src="http://www.youtube.com/v/6J_eh1HPu54" hspace="5" vspace="5" align="left"></embed></object>This is a repost of a previous project. I am still working to get the older post back online from when we upgraded Wordpress.</p>
<p>The robot was basically built using a Parallax Boe Bot chassis. Rather than using the Basic Stamp we added an <a href="http://store.arduinofun.com/freeduino-usb-complete-kit-arduino-duemilanove-compatible.html">Arduino</a> with a <a href="http://store.arduinofun.com/freeduino-protoshield-kit-for-arduino.html">proto shield</a> to control the robot functions.</p>
<p>You can use any type of chassis for this project. The robot moves about using a ping sonar and <a href="http://store.arduinofun.com/infrared-proximity-sensor--sharp-gp2y0a2021.html">IR sensors</a> to avoid running into any objects. As you can see in the video, it was a bit thrown off by our kitten. We added additional items such as a wireless camera that sends audio/video back to our TV.<span id="more-275"></span>The original design for this was created by an Instructable&#8217;s member and can be <a href="http://www.instructables.com/id/BOB-V20/">found here</a>.</p>
<p><strong>Items you will need for this project:</strong></p>
<ul>
<li><a href="http://store.arduinofun.com/freeduino-usb-complete-kit-arduino-duemilanove-compatible.html">Arduino/Freeduino</a> or <a href="http://store.arduinofun.com/breadboard-arduino-kit.html">Breadboard Arduino</a></li>
<li>(3) <a href="http://store.arduinofun.com/infrared-sensor-jumper-wire--3pin-js3.html">3-Wire Sensor Cables</a></li>
<li><a href="http://store.arduinofun.com/breadboard-400-tie-po400.html">Breadboard</a> (small) or <a href="http://store.arduinofun.com/breadboard-840-tie-po840.html">Breadboard</a> (large)</li>
<li><a href="http://store.arduinofun.com/freeduino-protoshield-kit-for-arduino.html">Protoshield</a></li>
<li>(3) <a href="http://store.arduinofun.com/infrared-proximity-sensor--sharp-gp2y0a2021.html">Sharp IR Sensors</a></li>
<li><a href="http://store.arduinofun.com/5v-1a-switching-voltage-regulat51.html">5V 1A Switching voltage regulator</a></li>
<li><a href="http://store.arduinofun.com/wire-jumper-kit-for-breadboards.html">Various lengths of wire</a></li>
<li><a href="http://store.arduinofun.com/5mm-red-and-green-leds-pk-of510.html">LED</a></li>
<li><a href="http://store.arduinofun.com/220-ohm-resistor-pk-22010.html">220 Ohm resistor</a></li>
<li><a href="http://store.arduinofun.com/4-aa-battery-holde4.html">Optional &#8211; 4 AA Battery Holder</a></li>
<li>Piezo Speaker/Element</li>
<li>Parallax Ping))) Ultrasonic Rangefinder</li>
<li>(2) Parallax Continuous Rotation Servos</li>
<li>1 Parallax Standard Rotation Servos</li>
<li>9.6V Ni-Cd Rechargeable Battery (or any other 8-AA cell <a href="http://store.arduinofun.com/4-aa-battery-holde4.html">battery     pack</a>/any rechargeable battery pack above 9V)</li>
<li>Optional Method: <a href="http://store.arduinofun.com/dual-motor-breakout-board.html">Dual Motor Breakout</a> and <a href="http://store.arduinofun.com/12vdc-mabuchi-rs380ph-12380.html">2 DC Motors</a> (<a href="http://arduinofun.com/blog/2009/10/25/duel-motor-driver/">Tutorial Available Here</a>)</li>
</ul>
<div id="attachment_310" class="wp-caption alignleft" style="width: 330px"><a href="http://www.flickr.com/photos/34908673@N00/4133522899/sizes/l/"><img class="size-full wp-image-310" title="Arduino Autonomous Robot" src="http://arduinofun.com/blog/wp-content/uploads/2009/11/lars1.jpg" alt="Arduino Autonomous Robot" width="320" height="240" /></a><p class="wp-caption-text">Arduino Autonomous Robot</p></div>
<p>The standard servo will be used to mount the Ping Rangefinder. This will give you a back and forth sweep motion as the robot travels around. The two continuous rotation servos are used for the wheels. You do not need to use the Parallax brand of servos, other brands will work. You may have to adjust the PWM values in the source code to go with the servos you are using.</p>
<p>It is also possible to use <a href="http://store.arduinofun.com/motors.html">DC motors</a> and edit the code, which would be considerably cheaper. You could use a SN754410 Quad Half H-Bridge to drive two DC motors. <a href="http://arduinofun.com/blog/2009/10/25/duel-motor-driver/">Tutorial for how to do this is available here</a>.</p>
<p>The Arduino hook up is pretty simple. You will have the following:</p>
<ul>
<li>Pin (Analog) 0: Left Sensor</li>
<li>Pin (Analog) 1: Center Sensor</li>
<li>Pin (Analog) 2: Right Sensor</li>
<li>Pin 5: Pan Servo</li>
<li>Pin 6: Left Drive Servo</li>
<li>Pin 7: Ultrasonic Rangefinder ( &#8216;Ping)))&#8217; )</li>
<li>Pin 9: Right Drive Servo</li>
<li>Pin 11: Piezo Speaker</li>
</ul>
<div id="attachment_313" class="wp-caption alignleft" style="width: 330px"><a href="http://www.flickr.com/photos/34908673@N00/4133522649/sizes/l/"><img class="size-full wp-image-313" title="Shield Close-up" src="http://arduinofun.com/blog/wp-content/uploads/2009/11/lars2.jpg" alt="Shield Close-up" width="320" height="240" /></a><p class="wp-caption-text">Shield Close-up</p></div>
<p>Radioshack sells an RC car battery as well as connector repair kit. You can solder the repair kit connector onto the shield, and then be able to hook up your battery to power the servos with. You can use a separate <a href="http://store.arduinofun.com/4-aa-battery-holde4.html">battery holder</a> to power the Arduino.</p>
<p>Make all your connections onto <a href="http://store.arduinofun.com/freeduino-protoshield-kit-for-arduino.html">the shield</a>. This way everything can remain in place if you need to use your Arduino for something else and save you from needing to tear apart everything.</p>
<p>for power to the shield, you won&#8217;t need any extra filter capacitors since the <a href="http://store.arduinofun.com/5v-1a-switching-voltage-regulat51.html">5V switching  regulator</a> has them built in. We used a small project box to hold the battery in place, and was able to attach the wireless camera on top of it.</p>
<p>The Arduino and camera are power source 1, while the servos and sensors are power source 2 (the RC battery). A small piece of PVC pipe mounted onto a cable clip will help you to keep your wires all organized to a central point and be less likely to get caught or tangled up into something as the robot is moving around.</p>
<p><strong>Arduino Sketch</strong></p>
<pre><span style="color: #7E7E7E;">// Begin Robot Code</span>
<span style="color: #CC6600;">int</span> micVal;
<span style="color: #CC6600;">int</span> cdsVal;
<span style="color: #CC6600;">int</span> irLval;  <span style="color: #7E7E7E;">// Left IR</span>
<span style="color: #CC6600;">int</span> irCval;  <span style="color: #7E7E7E;">// Center IR</span>
<span style="color: #CC6600;">int</span> irRval;  <span style="color: #7E7E7E;">// Right IR</span>

<span style="color: #CC6600;">int</span> i;   <span style="color: #7E7E7E;">// Generic Counter</span>
<span style="color: #CC6600;">int</span> x;  <span style="color: #7E7E7E;">// Generic Counter</span>
<span style="color: #CC6600;">int</span> PLval;  <span style="color: #7E7E7E;">// Pulse Width for Left Servo</span>
<span style="color: #CC6600;">int</span> PRval;  <span style="color: #7E7E7E;">// Pulse Width for Right Servo</span>
<span style="color: #CC6600;">int</span> cntr;  <span style="color: #7E7E7E;">// Generic Counter Used for Determining amt. of Object Detections</span>
<span style="color: #CC6600;">int</span> counter; <span style="color: #7E7E7E;">// Generic Counter</span>
<span style="color: #CC6600;">int</span> clrpth;  <span style="color: #7E7E7E;">// amt. of Milliseconds Of Unobstructed Path</span>
<span style="color: #CC6600;">int</span> objdet;  <span style="color: #7E7E7E;">// Time an Object was Detected</span>
<span style="color: #CC6600;">int</span> task;  <span style="color: #7E7E7E;">// Routine to Follow for Clearest Path</span>
<span style="color: #CC6600;">int</span> pwm;  <span style="color: #7E7E7E;">// Pulse Width for Pan Servo</span>
<span style="color: #CC6600;">boolean</span> add;  <span style="color: #7E7E7E;">// Whether to Increment or Decrement PW Value for Pan Servo</span>
<span style="color: #CC6600;">int</span> distance;  <span style="color: #7E7E7E;">// Distance to Object Detected via Ultrasonic Ranger</span>
<span style="color: #CC6600;">int</span> oldDistance;  <span style="color: #7E7E7E;">// Previous Distance Value Read from Ultrasonic Ranger</span>

<span style="color: #CC6600;">float</span> scale = 1.9866666666666666666666666666667;  <span style="color: #7E7E7E;">// *Not Currently Used*</span>

<span style="color: #CC6600;">int</span> LeftPin = 6;  <span style="color: #7E7E7E;">// Left Servo</span>
<span style="color: #CC6600;">int</span> RightPin = 9;  <span style="color: #7E7E7E;">// Right Servo</span>
<span style="color: #CC6600;">int</span> PiezoPin = 11;  <span style="color: #7E7E7E;">// Piezo</span>
<span style="color: #CC6600;">int</span> PingServoPin = 5;  <span style="color: #7E7E7E;">// Pan Servo</span>
<span style="color: #CC6600;">int</span> irLPin = 0;            <span style="color: #7E7E7E;">// Analog 0; Left IR</span>
<span style="color: #CC6600;">int</span> irCPin = 1;            <span style="color: #7E7E7E;">// Analog 1; Center IR</span>
<span style="color: #CC6600;">int</span> irRPin = 2;            <span style="color: #7E7E7E;">// Analog 2; Right IR</span>

<span style="color: #CC6600;">int</span> ultraSoundSignal = 7; <span style="color: #7E7E7E;">// Ultrasound signal pin</span>
<span style="color: #CC6600;">int</span> val = 0;              <span style="color: #7E7E7E;">// Used for Ultrasonic Ranger</span>
<span style="color: #CC6600;">int</span> ultrasoundValue = 0;  <span style="color: #7E7E7E;">// Raw Distance Val</span>
<span style="color: #CC6600;">int</span> oldUltrasoundValue;  <span style="color: #7E7E7E;">// *Not used*</span>
<span style="color: #CC6600;">int</span> pulseCount;        <span style="color: #7E7E7E;">// Generic Counter</span>
<span style="color: #CC6600;">int</span> timecount = 0; <span style="color: #7E7E7E;">// Echo counter</span>
<span style="color: #CC6600;">int</span> ledPin = 13; <span style="color: #7E7E7E;">// LED connected to digital pin 13</span>

#define BAUD 9600
#define CmConstant 1/29.034

<span style="color: #CC6600;">void</span> <span style="color: #CC6600;"><strong>setup</strong></span>() {
  <span style="color: #CC6600;">Serial</span>.<span style="color: #CC6600;">begin</span>(9600);
  <span style="color: #CC6600;">pinMode</span>(PiezoPin, <span style="color: #006699;">OUTPUT</span>);
  <span style="color: #CC6600;">pinMode</span>(ledPin, <span style="color: #006699;">OUTPUT</span>);
  <span style="color: #CC6600;">pinMode</span>(LeftPin, <span style="color: #006699;">OUTPUT</span>);
  <span style="color: #CC6600;">pinMode</span>(RightPin, <span style="color: #006699;">OUTPUT</span>);
  <span style="color: #CC6600;">pinMode</span>(PingServoPin, <span style="color: #006699;">OUTPUT</span>);
  <span style="color: #CC6600;">pinMode</span>(irLPin, <span style="color: #006699;">INPUT</span>);
  <span style="color: #CC6600;">pinMode</span>(irCPin, <span style="color: #006699;">INPUT</span>);
  <span style="color: #CC6600;">pinMode</span>(irRPin, <span style="color: #006699;">INPUT</span>);
  <span style="color: #CC6600;">for</span>(i = 0; i &lt; 500; i++) {
    <span style="color: #CC6600;">digitalWrite</span>(PiezoPin, <span style="color: #006699;">HIGH</span>);
    <span style="color: #CC6600;">delayMicroseconds</span>(1000);
    <span style="color: #CC6600;">digitalWrite</span>(PiezoPin, <span style="color: #006699;">LOW</span>);
    <span style="color: #CC6600;">delayMicroseconds</span>(1000);
  }
  <span style="color: #CC6600;">for</span>(i = 0; i &lt; 20; i++) {
  <span style="color: #CC6600;">digitalWrite</span>(PingServoPin, <span style="color: #006699;">HIGH</span>);
  <span style="color: #CC6600;">delayMicroseconds</span>(655 * 2);
  <span style="color: #CC6600;">digitalWrite</span>(PingServoPin, <span style="color: #006699;">LOW</span>);
  <span style="color: #CC6600;">delay</span>(20);
  }
  ultrasoundValue = 600;
  i = 0;
}

<span style="color: #CC6600;">void</span> <span style="color: #CC6600;"><strong>loop</strong></span>()
{
  <span style="color: #7E7E7E;">//Scan();</span>
  Look();
  Go();
}
<span style="color: #CC6600;">void</span> Look() {
  irLval = <span style="color: #CC6600;">analogRead</span>(irLPin);
  irCval = <span style="color: #CC6600;">analogRead</span>(irCPin);
  irRval = <span style="color: #CC6600;">analogRead</span>(irRPin);
  <span style="color: #7E7E7E;">//if(counter &gt; 10) {</span>
    <span style="color: #7E7E7E;">//counter = 0;</span>
    <span style="color: #7E7E7E;">//readPing();</span>
  <span style="color: #7E7E7E;">//}</span>
  <span style="color: #CC6600;">if</span>(irLval &gt; 200) {
    PLval = 850;
    PRval = 820;
    x = 5;
    cntr = cntr + 1;
    clrpth = 0;
    objdet = <span style="color: #CC6600;">millis</span>();
  }
  <span style="color: #CC6600;">else</span> <span style="color: #CC6600;">if</span>(irCval &gt; 200) {
    PLval = 850;
    PRval = 820;
    x = 10;
    cntr = cntr + 1;
    clrpth = 0;
    objdet = <span style="color: #CC6600;">millis</span>();
  }
  <span style="color: #CC6600;">else</span> <span style="color: #CC6600;">if</span>(irRval &gt; 200) {
    PLval = 650;
    PRval = 620;
    x = 5;
    cntr = cntr + 1;
    clrpth = 0;
    objdet = <span style="color: #CC6600;">millis</span>();
  }
  <span style="color: #CC6600;">else</span> {
    x = 1;
    PLval = 850;
    PRval = 620;
    counter = counter + 1;
    clrpth = (<span style="color: #CC6600;">millis</span>() - objdet);
    <span style="color: #CC6600;">if</span>(add == <span style="color: #CC6600;">true</span>) {
      pwm = pwm + 50;
    }
    <span style="color: #CC6600;">else</span> <span style="color: #CC6600;">if</span>(add == <span style="color: #CC6600;">false</span>) {
      pwm = pwm - 50;
    }
    <span style="color: #CC6600;">if</span>(pwm &lt; 400) {
      pwm = 400;
      add = <span style="color: #CC6600;">true</span>;
    }
    <span style="color: #CC6600;">if</span>(pwm &gt; 950) {
      pwm = 950;
      add = <span style="color: #CC6600;">false</span>;
    }
    <span style="color: #CC6600;">digitalWrite</span>(PingServoPin, <span style="color: #006699;">HIGH</span>);
    <span style="color: #CC6600;">delayMicroseconds</span>(pwm * 2);
    <span style="color: #CC6600;">digitalWrite</span>(PingServoPin, <span style="color: #006699;">LOW</span>);
    <span style="color: #CC6600;">delay</span>(20);
    readPing();
    <span style="color: #CC6600;">if</span>(ultrasoundValue &lt; 500) {
      cntr = cntr + 1;
      <span style="color: #CC6600;">switch</span>(pwm) {
        <span style="color: #CC6600;">case</span> 400:
          x = 7;
          PLval = 650;
          PRval = 650;
          Go();
          break;
        <span style="color: #CC6600;">case</span> 500:
          x = 10;
          PLval = 650;
          PRval = 650;
          Go();
          break;
        <span style="color: #CC6600;">case</span> 600:
          x = 14;
          PLval = 850;
          PRval = 850;
          Go();
          break;
        <span style="color: #CC6600;">case</span> 700:
          x = 10;
          PLval = 850;
          PRval = 850;
          Go();
          break;
        <span style="color: #CC6600;">case</span> 950:
          x = 7;
          PLval = 850;
          PRval = 850;
          Go();
          break;
      }
    }
  }
  <span style="color: #7E7E7E;">//Serial.print("clrpth: ");</span>
  <span style="color: #7E7E7E;">//Serial.println(clrpth);</span>
  <span style="color: #7E7E7E;">//Serial.print("objdet: ");</span>
  <span style="color: #7E7E7E;">//Serial.println(objdet);</span>
  <span style="color: #7E7E7E;">//Serial.print("cntr: ");</span>
  <span style="color: #7E7E7E;">//Serial.println(cntr);</span>
  <span style="color: #CC6600;">if</span>(cntr &gt; 25 &amp;&amp; clrpth &lt; 2000) {
    clrpth = 0;
    cntr = 0;
    Scan();
  }
}
<span style="color: #CC6600;">void</span> Go() {
  <span style="color: #CC6600;">for</span>(i = 0; i &lt; x; i++) {
    <span style="color: #CC6600;">digitalWrite</span>(LeftPin, <span style="color: #006699;">HIGH</span>);
    <span style="color: #CC6600;">delayMicroseconds</span>(PLval * 2);
    <span style="color: #CC6600;">digitalWrite</span>(LeftPin, <span style="color: #006699;">LOW</span>);
    <span style="color: #CC6600;">digitalWrite</span>(RightPin, <span style="color: #006699;">HIGH</span>);
    <span style="color: #CC6600;">delayMicroseconds</span>(PRval * 2);
    <span style="color: #CC6600;">digitalWrite</span>(RightPin, <span style="color: #006699;">LOW</span>);
    <span style="color: #CC6600;">delay</span>(20);
  }
}
<span style="color: #CC6600;">void</span> readPing() {  <span style="color: #7E7E7E;">// Get Distance from Ultrasonic Ranger</span>
 timecount = 0;
 val = 0;
 <span style="color: #CC6600;">pinMode</span>(ultraSoundSignal, <span style="color: #006699;">OUTPUT</span>); <span style="color: #7E7E7E;">// Switch signalpin to output</span>

<span style="color: #7E7E7E;">/* Send low-high-low pulse to activate the trigger pulse of the sensor</span>
<span style="color: #7E7E7E;"> * -------------------------------------------------------------------</span>
<span style="color: #7E7E7E;"> */</span>

<span style="color: #CC6600;">digitalWrite</span>(ultraSoundSignal, <span style="color: #006699;">LOW</span>); <span style="color: #7E7E7E;">// Send low pulse</span>
<span style="color: #CC6600;">delayMicroseconds</span>(2); <span style="color: #7E7E7E;">// Wait for 2 microseconds</span>
<span style="color: #CC6600;">digitalWrite</span>(ultraSoundSignal, <span style="color: #006699;">HIGH</span>); <span style="color: #7E7E7E;">// Send high pulse</span>
<span style="color: #CC6600;">delayMicroseconds</span>(5); <span style="color: #7E7E7E;">// Wait for 5 microseconds</span>
<span style="color: #CC6600;">digitalWrite</span>(ultraSoundSignal, <span style="color: #006699;">LOW</span>); <span style="color: #7E7E7E;">// Holdoff</span>

<span style="color: #7E7E7E;">/* Listening for echo pulse</span>
<span style="color: #7E7E7E;"> * -------------------------------------------------------------------</span>
<span style="color: #7E7E7E;"> */</span>

<span style="color: #CC6600;">pinMode</span>(ultraSoundSignal, <span style="color: #006699;">INPUT</span>); <span style="color: #7E7E7E;">// Switch signalpin to input</span>
val = <span style="color: #CC6600;">digitalRead</span>(ultraSoundSignal); <span style="color: #7E7E7E;">// Append signal value to val</span>
<span style="color: #CC6600;">while</span>(val == <span style="color: #006699;">LOW</span>) { <span style="color: #7E7E7E;">// Loop until pin reads a high value</span>
  val = <span style="color: #CC6600;">digitalRead</span>(ultraSoundSignal);
}

<span style="color: #CC6600;">while</span>(val == <span style="color: #006699;">HIGH</span>) { <span style="color: #7E7E7E;">// Loop until pin reads a high value</span>
  val = <span style="color: #CC6600;">digitalRead</span>(ultraSoundSignal);
  timecount = timecount +1;            <span style="color: #7E7E7E;">// Count echo pulse time</span>
}

<span style="color: #7E7E7E;">/* Writing out values to the serial port</span>
<span style="color: #7E7E7E;"> * -------------------------------------------------------------------</span>
<span style="color: #7E7E7E;"> */</span>

ultrasoundValue = timecount; <span style="color: #7E7E7E;">// Append echo pulse time to ultrasoundValue</span>

<span style="color: #7E7E7E;">//serialWrite('A'); // Example identifier for the sensor</span>
<span style="color: #7E7E7E;">//printInteger(ultrasoundValue);</span>
<span style="color: #7E7E7E;">//serialWrite(10);</span>
<span style="color: #7E7E7E;">//serialWrite(13);</span>

<span style="color: #7E7E7E;">/* Lite up LED if any value is passed by the echo pulse</span>
<span style="color: #7E7E7E;"> * -------------------------------------------------------------------</span>
<span style="color: #7E7E7E;"> */</span>

<span style="color: #CC6600;">if</span>(timecount &gt; 0){
  <span style="color: #CC6600;">digitalWrite</span>(ledPin, <span style="color: #006699;">HIGH</span>);
}
} 
<span style="color: #CC6600;">void</span> Scan() {   <span style="color: #7E7E7E;">// Scan for the Clearest Path</span>
  oldDistance = 30;
  task = 0;
  <span style="color: #CC6600;">for</span>(i = 1; i &lt; 5; i++) {
    <span style="color: #CC6600;">switch</span>(i) {
      <span style="color: #CC6600;">case</span> 1:
        <span style="color: #7E7E7E;">//Serial.println("Pos. 1");</span>
        pwm = 1125;    <span style="color: #7E7E7E;">///  incr. by 100 from 1085</span>
        break;
      <span style="color: #CC6600;">case</span> 2:
        <span style="color: #7E7E7E;">//Serial.println("Pos. 2");</span>
        pwm = 850; <span style="color: #7E7E7E;">//// increased by 100 from 850</span>
        break;
      <span style="color: #CC6600;">case</span> 3:
        <span style="color: #7E7E7E;">//Serial.println("Pos. 3");</span>
        pwm = 400;
        break;
      <span style="color: #CC6600;">case</span> 4:
        <span style="color: #7E7E7E;">//Serial.println("Pos. 4");</span>
        pwm = 235;
        break;
    }
    <span style="color: #CC6600;">for</span>(pulseCount = 0; pulseCount &lt; 20; pulseCount++) {  <span style="color: #7E7E7E;">// Adjust Pan Servo and Read USR</span>
      <span style="color: #CC6600;">digitalWrite</span>(PingServoPin, <span style="color: #006699;">HIGH</span>);
      <span style="color: #CC6600;">delayMicroseconds</span>(pwm * 2);
      <span style="color: #CC6600;">digitalWrite</span>(PingServoPin, <span style="color: #006699;">LOW</span>);
      readPing();
      <span style="color: #CC6600;">delay</span>(20);
    }
    distance = ((<span style="color: #CC6600;">float</span>)ultrasoundValue * CmConstant);   <span style="color: #7E7E7E;">// Calculate Distance in Cm</span>
    <span style="color: #CC6600;">if</span>(distance &gt; oldDistance) {  <span style="color: #7E7E7E;">// If the Newest distance is longer, replace previous reading with it</span>
      oldDistance = distance;
      task = i;   <span style="color: #7E7E7E;">// Set task equal to Pan Servo Position</span>
    }
  }
  <span style="color: #7E7E7E;">//Serial.print("Task: ");</span>
  <span style="color: #7E7E7E;">//Serial.println(task);</span>
  <span style="color: #7E7E7E;">//Serial.print("distance: ");</span>
  <span style="color: #7E7E7E;">//Serial.println(distance);</span>
  <span style="color: #7E7E7E;">//Serial.print("oldDistance: ");</span>
  <span style="color: #7E7E7E;">//Serial.println(oldDistance);</span>
  distance = 50;  <span style="color: #7E7E7E;">// Prevents Scan from Looping</span>
  <span style="color: #CC6600;">switch</span>(task) {   <span style="color: #7E7E7E;">// Determine which task should be carried out</span>
    <span style="color: #CC6600;">case</span> 0:  <span style="color: #7E7E7E;">// Center was clearest</span>
      x = 28;
      PLval = (850);
      PRval = (850);
      Go();
      break;
    <span style="color: #CC6600;">case</span> 1:  <span style="color: #7E7E7E;">// 90 degrees Left was Clearest</span>
      x = 14;
      PLval = (650);
      PRval = (650);
      Go();
      break;
    <span style="color: #CC6600;">case</span> 2:  <span style="color: #7E7E7E;">// 45 degrees left</span>
      x = 7;
      PLval = (650);
      PRval = (650);
      Go();
      break;
    <span style="color: #CC6600;">case</span> 3:  <span style="color: #7E7E7E;">// 45 degrees right</span>
      x = 7;
      PLval = (850);
      PRval = (850);
      Go();
      break;
    <span style="color: #CC6600;">case</span> 4:  <span style="color: #7E7E7E;">// 90 degrees right</span>
      x = 14;
      PLval = (850);
      PRval = (850);
      Go();
      break;
  }
}

<span style="color: #7E7E7E;">// End Robot Code</span></pre>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Farduinofun.com%2Fblog%2F2009%2F11%2F25%2Farduino-autonomous-robot%2F&amp;linkname=Arduino%20Autonomous%20Robot"><img src="http://arduinofun.com/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://arduinofun.com/blog/2009/11/25/arduino-autonomous-robot/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Arduino PIR Motion Sensing Bridge with Solar Powered LED Lighting</title>
		<link>http://arduinofun.com/blog/2009/11/15/arduino-pir-motion-sensing-bridge-with-solar-powered-led-lighting/</link>
		<comments>http://arduinofun.com/blog/2009/11/15/arduino-pir-motion-sensing-bridge-with-solar-powered-led-lighting/#comments</comments>
		<pubDate>Mon, 16 Nov 2009 03:14:56 +0000</pubDate>
		<dc:creator>Administrator</dc:creator>
				<category><![CDATA[Project Files]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Arduino Code]]></category>
		<category><![CDATA[Arduino PIR Sensing]]></category>
		<category><![CDATA[Arduino Sketch]]></category>
		<category><![CDATA[Columbus]]></category>
		<category><![CDATA[Columbus State]]></category>
		<category><![CDATA[LED Lighting]]></category>
		<category><![CDATA[Motion Detection]]></category>
		<category><![CDATA[Motion Sensor]]></category>
		<category><![CDATA[OH]]></category>
		<category><![CDATA[Parallax PIR Sensor]]></category>
		<category><![CDATA[Solar Power]]></category>

		<guid isPermaLink="false">http://arduinofun.com/blog/?p=266</guid>
		<description><![CDATA[The bridge, “Passage” by L. Brower Hatcher at Columbus State, is one of the most outstanding and notable landmarks on campus. Connecting the main parking garage and Davidson Hall over Spring Street, the bridge offers safe passage above the fast moving one-way traffic below. Painted bright red, it also adds a strong visual contrast against [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_267" class="wp-caption alignleft" style="width: 310px"><img class="size-medium wp-image-267" title="Bridge Passage, courtesy of Professor Tom Robbins, Architecture" src="http://arduinofun.com/blog/wp-content/uploads/2009/11/bridge1sm-300x223.jpg" alt="Bridge Passage,courtesy of Professor Tom Robbins, Architecture" width="300" height="223" /><p class="wp-caption-text">Bridge Passage, photo courtesy of Professor Tom Robbins, Architecture</p></div>
<p>The bridge, “Passage” by L. Brower Hatcher at Columbus State, is one of the most outstanding and notable landmarks on campus. Connecting the main parking garage and Davidson Hall over Spring Street, the bridge offers safe passage above the fast moving one-way traffic below. Painted bright red, it also adds a strong visual contrast against the blue sky above and the green grass below.</p>
<p>The bridge contains many educational symbols and decorative metal icons mounted along the passage, which at one time were lighted at night by fiber-optics, creating a moving array of colors and light. This night-time light display has been noticeably absent for several years, apparently due to the mechanical failure of the high-powered “luminaries” which project colored light through the fiber optic cables.</p>
<div id="attachment_269" class="wp-caption alignleft" style="width: 310px"><img class="size-medium wp-image-269" title="Bridge Icons" src="http://arduinofun.com/blog/wp-content/uploads/2009/11/bridge2sm-300x223.jpg" alt="Bridge Icons" width="300" height="223" /><p class="wp-caption-text">Bridge Icons</p></div>
<p>As a class project, we designed a <strong>Solar Powered LED Lighting</strong> system to replace the existing outdated system that no longer works. (I can&#8217;t reveal the design yet here until things are approved) After thorough investigation, our class determined that the luminaries, located on the side of the bridge, most likely failed due to heat build-up, and possibly corrosion from exhaust and salt water mist from the traffic below. By contacting the vendor, we discovered that the 277 VAC model PH-3001 luminaries installed when the bridge was commissioned are no longer manufactured, and the replacement units would not be compatible with any of the PH-3001 units which still may be repairable on the bridge.  This means that to light the bridge again using the high-powered Metal-Halide luminaries, all 14 units would need to be replaced, at a minimum cost of $13,000.00 USD, not including labor.</p>
<p>It is also important to note, that the PH-3001 units are extremely difficult to maintain. Maintenance is very labor intensive, and consumes a large block of time for maintenance personnel who obviously have a multitude of other important tasks, maintaining a large campus the size of Columbus State. The bulbs burn out frequently, with a replacement cost of $211.00 each, or approximately $3000.00 USD per year. The units are also located in a difficult to reach location, and the fragile glass color wheels which require frequent cleaning and maintenance because of pollution from the traffic below, are easily damaged during maintenance.<span id="more-266"></span></p>
<p><strong>Cost Benefit Analysis:</strong></p>
<p>As noted earlier, the old Metal Halide lighting units are very labor intensive, and difficult to maintain. Due to heat buildup inside the enclosed units (Metal Halide bulbs run very hot), the bulbs would need to be changed yearly at a material cost of $3000.00 USD. Added to this amount would be a minimum of 28 hours of labor at $40 per hour, or $1120 in labor costs. The 14 units each consume approximately 200 watts of power per hour, or a total of $3.36 per day, $1226 per year. This would bring the approximate operating costs for the old lighting units to $3000 + $1120 + $1226 = $5346.00 per year operating cost.</p>
<p>Since the Solar Powered LED illuminated bridge runs off of the Sun’s energy, electrical costs and Carbon footprint would be Zero. LED light bulbs have an average MTBF (Mean time between failure) of 50,000 to 100,000 hours, or approximately 20 times that of the metal halide bulbs. By eliminating the mechanical rotating color wheels, valuable maintenance costs for an LED lighting system would be greatly reduced, to possibly only several hours per year. <strong>The estimated cost savings for the Solar Powered LED lighting system would be over $5000.00 USD per year.</strong></p>
<p>So far the school has seemed to drag their feet with getting things done. Each day when I go to class and walk across the bridge I day dream about more stuff to add to the design which brings me to my original intent for this post, which is how to connect a PIR sensor to an Arduino.</p>
<p>The bridge has lighted square panels along the walkway. What I would like to see added is the ability for each panel to light up as a person gets close and then turn off as they move further away. This I feel will add to the cost savings since the walk way lights will only be in use at night when there is traffic on the bridge. If nobody is on the bridge, there is no need for them to be on at that time since the only purpose they serve is to see where you are walking.</p>
<div id="attachment_271" class="wp-caption alignleft" style="width: 310px"><img class="size-medium wp-image-271" title="Arduino with PIR Sensor" src="http://arduinofun.com/blog/wp-content/uploads/2009/11/100_1512-300x225.jpg" alt="Arduino with PIR Sensor" width="300" height="225" /><p class="wp-caption-text">Arduino with PIR Sensor</p></div>
<p><strong>Connecting a PIR sensor to an Arduino board can be done easily.</strong> PIR sensors consist of 3 pins, Vcc (Positive Voltage), Vss (Ground), and Signal. Interfacing it to the Arduino only requires +5v, GND and a digital input pin.</p>
<p>I put a short video clip on <a href="http://www.youtube.com/watch?v=Wn5-fyzOLOs" target="_blank">YouTube</a> showing how the sensor works and the code is below.</p>
<p>I am thinking I could easily put together a small board and have each one located throughout the bridge with PIR sensors connected to them to control the individual squares. Or possibly have one central location for a control station and each PIR sensor runs to it.</p>
<p>Then as you walk, each panel will light up and turn off a few seconds later as you move away from it. The panels are staggered all the way down the walkway, so this would give a nice effect at night as someone is walking across the bridge.</p>
<p>Another thought I had was to tie all the walkway panels into one PIR at the entrance and one PIR at the exit of the bridge (maybe one in the middle also) and then the bridge would light up in 2-3 stages, rather than individual panels. Kind of boring, but serves its purpose for safety.</p>
<p>Additional Resources:</p>
<p><a href="http://www.parallax.com/dl/docs/prod/audiovis/PIRSensor-V1.1.pdf">Parallax PIR Sensor Datasheet</a></p>
<p><a href="http://www.arduino.cc/playground/Code/PIRsense">Arduino PIRsense</a></p>
<p><strong>Arduino Sketch:</strong></p>
<pre><span style="color: #7E7E7E;">// Parallax PIR sensor's output</span>

<span style="color: #7E7E7E;">//VARS</span>
<span style="color: #7E7E7E;">//the time we give the sensor to calibrate (10-60 secs according to the datasheet)</span>
<span style="color: #CC6600;">int</span> calibrationTime = 30;        

<span style="color: #7E7E7E;">//the time when the sensor outputs a low impulse</span>
<span style="color: #CC6600;">long</span> <span style="color: #CC6600;">unsigned</span> <span style="color: #CC6600;">int</span> lowIn;         

<span style="color: #7E7E7E;">//the amount of milliseconds the sensor has to be low </span>
<span style="color: #7E7E7E;">//before we assume all motion has stopped</span>
<span style="color: #CC6600;">long</span> <span style="color: #CC6600;">unsigned</span> <span style="color: #CC6600;">int</span> pause = 5000;  

<span style="color: #CC6600;">boolean</span> lockLow = <span style="color: #CC6600;">true</span>;
<span style="color: #CC6600;">boolean</span> takeLowTime;  

<span style="color: #CC6600;">int</span> pirPin = 3;    <span style="color: #7E7E7E;">//the digital pin connected to the PIR sensor's output</span>
<span style="color: #CC6600;">int</span> ledPin = 13;

<span style="color: #7E7E7E;">//SETUP</span>
<span style="color: #CC6600;">void</span> <span style="color: #CC6600;"><strong>setup</strong></span>(){
  <span style="color: #CC6600;">Serial</span>.<span style="color: #CC6600;">begin</span>(9600);
  <span style="color: #CC6600;">pinMode</span>(pirPin, <span style="color: #006699;">INPUT</span>);
  <span style="color: #CC6600;">pinMode</span>(ledPin, <span style="color: #006699;">OUTPUT</span>);
  <span style="color: #CC6600;">digitalWrite</span>(pirPin, <span style="color: #006699;">LOW</span>);

  <span style="color: #7E7E7E;">//give the sensor some time to calibrate</span>
  <span style="color: #CC6600;">Serial</span>.<span style="color: #CC6600;">print</span>(<span style="color: #006699;">"calibrating sensor "</span>);
    <span style="color: #CC6600;">for</span>(<span style="color: #CC6600;">int</span> i = 0; i &lt; calibrationTime; i++){
      <span style="color: #CC6600;">Serial</span>.<span style="color: #CC6600;">print</span>(<span style="color: #006699;">"."</span>);
      <span style="color: #CC6600;">delay</span>(1000);
      }
    <span style="color: #CC6600;">Serial</span>.<span style="color: #CC6600;">println</span>(<span style="color: #006699;">" done"</span>);
    <span style="color: #CC6600;">Serial</span>.<span style="color: #CC6600;">println</span>(<span style="color: #006699;">"SENSOR ACTIVE"</span>);
    <span style="color: #CC6600;">delay</span>(50);
  }

<span style="color: #7E7E7E;">////////////////////////////</span>
<span style="color: #7E7E7E;">//LOOP</span>
<span style="color: #CC6600;">void</span> <span style="color: #CC6600;"><strong>loop</strong></span>(){

     <span style="color: #CC6600;">if</span>(<span style="color: #CC6600;">digitalRead</span>(pirPin) == <span style="color: #006699;">HIGH</span>){
       <span style="color: #CC6600;">digitalWrite</span>(ledPin, <span style="color: #006699;">HIGH</span>);   <span style="color: #7E7E7E;">//the led visualizes the sensors output pin state</span>
       <span style="color: #CC6600;">if</span>(lockLow){
         <span style="color: #7E7E7E;">//makes sure we wait for a transition to LOW before any further output is made:</span>
         lockLow = <span style="color: #CC6600;">false</span>;
         <span style="color: #CC6600;">Serial</span>.<span style="color: #CC6600;">println</span>(<span style="color: #006699;">"---"</span>);
         <span style="color: #CC6600;">Serial</span>.<span style="color: #CC6600;">print</span>(<span style="color: #006699;">"motion detected at "</span>);
         <span style="color: #CC6600;">Serial</span>.<span style="color: #CC6600;">print</span>(<span style="color: #CC6600;">millis</span>()/1000);
         <span style="color: #CC6600;">Serial</span>.<span style="color: #CC6600;">println</span>(<span style="color: #006699;">" sec"</span>);
         <span style="color: #CC6600;">delay</span>(50);
         }         
         takeLowTime = <span style="color: #CC6600;">true</span>;
       }

     <span style="color: #CC6600;">if</span>(<span style="color: #CC6600;">digitalRead</span>(pirPin) == <span style="color: #006699;">LOW</span>){
       <span style="color: #CC6600;">digitalWrite</span>(ledPin, <span style="color: #006699;">LOW</span>);  <span style="color: #7E7E7E;">//the led visualizes the sensors output pin state</span>

       <span style="color: #CC6600;">if</span>(takeLowTime){
        lowIn = <span style="color: #CC6600;">millis</span>();          <span style="color: #7E7E7E;">//save the time of the transition from high to LOW</span>
        takeLowTime = <span style="color: #CC6600;">false</span>;       <span style="color: #7E7E7E;">//make sure this is only done at the start of a LOW phase</span>
        }
       <span style="color: #7E7E7E;">//if the sensor is low for more than the given pause, </span>
       <span style="color: #7E7E7E;">//we assume that no more motion is going to happen</span>
       <span style="color: #CC6600;">if</span>(!lockLow &amp;&amp; <span style="color: #CC6600;">millis</span>() - lowIn &gt; pause){
           <span style="color: #7E7E7E;">//makes sure this block of code is only executed again after </span>
           <span style="color: #7E7E7E;">//a new motion sequence has been detected</span>
           lockLow = <span style="color: #CC6600;">true</span>;
           <span style="color: #CC6600;">Serial</span>.<span style="color: #CC6600;">print</span>(<span style="color: #006699;">"motion ended at "</span>);      <span style="color: #7E7E7E;">//output</span>
           <span style="color: #CC6600;">Serial</span>.<span style="color: #CC6600;">print</span>((<span style="color: #CC6600;">millis</span>() - pause)/1000);
           <span style="color: #CC6600;">Serial</span>.<span style="color: #CC6600;">println</span>(<span style="color: #006699;">" sec"</span>);
           <span style="color: #CC6600;">delay</span>(50);
           }
       }
  }</pre>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Farduinofun.com%2Fblog%2F2009%2F11%2F15%2Farduino-pir-motion-sensing-bridge-with-solar-powered-led-lighting%2F&amp;linkname=Arduino%20PIR%20Motion%20Sensing%20Bridge%20with%20Solar%20Powered%20LED%20Lighting"><img src="http://arduinofun.com/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://arduinofun.com/blog/2009/11/15/arduino-pir-motion-sensing-bridge-with-solar-powered-led-lighting/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Secret Knock Detecting Door Lock (Build It)</title>
		<link>http://arduinofun.com/blog/2009/11/02/secret-knock-detecting-door-lock-build-it/</link>
		<comments>http://arduinofun.com/blog/2009/11/02/secret-knock-detecting-door-lock-build-it/#comments</comments>
		<pubDate>Tue, 03 Nov 2009 00:36:51 +0000</pubDate>
		<dc:creator>Administrator</dc:creator>
				<category><![CDATA[Contest Entries]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Arduino Project]]></category>
		<category><![CDATA[Arduino Projects]]></category>
		<category><![CDATA[Arduino Sketch]]></category>
		<category><![CDATA[Arduino Tutorial]]></category>
		<category><![CDATA[H-Bridge]]></category>
		<category><![CDATA[Knock Sensor]]></category>
		<category><![CDATA[Microcontroller]]></category>
		<category><![CDATA[Piezo]]></category>
		<category><![CDATA[Sensor]]></category>
		<category><![CDATA[source code]]></category>

		<guid isPermaLink="false">http://arduinofun.com/blog/?p=234</guid>
		<description><![CDATA[Contest Entry by Steve Hoefer
How many times have you seen a secret hideout with a secret knock?  It&#8217;s a staple of cheesy dramas, Saturday afternoon movies, and tree houses throughout the world.
While working on another project I ran across the Arduino knock sensor tutorial.  Sensing a single knock is a great little project for learning [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_235" class="wp-caption alignleft" style="width: 326px"><img class="size-full wp-image-235" title="Side view" src="http://arduinofun.com/blog/wp-content/uploads/2009/11/slk1.jpg" alt="Side view" width="316" height="239" /><p class="wp-caption-text">Side view</p></div>
<p><strong><a href="http://grathio.com/2009/11/secret-knock-detecting-door-lock.html">Contest Entry by <span><span>Steve Hoefer</span></span></a></strong></p>
<p>How many times have you seen a secret hideout with a secret knock?  It&#8217;s a staple of cheesy dramas, Saturday afternoon movies, and tree houses throughout the world.</p>
<p>While working on another project I ran across the <a href="http://www.arduino.cc/en/Tutorial/Knock">Arduino knock sensor tutorial</a>.  Sensing a single knock is a great little project for learning about microcontrollers, but what about sensing specific knocks?  <em>Seeeeecret </em>knocks?  And if we could detect a secret knock, shouldn&#8217;t it unlock a door?   If you can&#8217;t tell by looking this was cobbled together from spare stuff around the lab, it&#8217;s not much more than a piezo speaker, a tiny gear reduction motor, and an <a href="http://www.arduino.cc/">Arduino</a>. And PVC pipe.</p>
<p><span id="more-234"></span></p>
<p><strong>UPDATE: 12/31/09</strong> &#8211; Since this posting, Steve has updated the blog a bit, tweaked the code a bit and published a full Instructable.</p>
<p><a href="http://grathio.com/2009/11/secret-knock-detecting-door-lock.html">http://grathio.com/2009/11/secret-knock-detecting-door-lock.html</a></p>
<p><a href="http://www.instructables.com/id/Secret-Knock-Detecting-Door-Lock/">http://www.instructables.com/id/Secret-Knock-Detecting-Door-Lock/</a></p>
<p>**<strong>Disclaimer</strong>: This was built with stuff I had lying around the lab.  How about a video to explain:</p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="320" height="265" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/zE5PGeh2K9k&amp;hl=en&amp;fs=1&amp;color1=0x2b405b&amp;color2=0x6b8ab6" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="320" height="265" src="http://www.youtube.com/v/zE5PGeh2K9k&amp;hl=en&amp;fs=1&amp;color1=0x2b405b&amp;color2=0x6b8ab6" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p>A microphone (okay, really a speaker) presses against the door and listens for knocks.  If it hears the right number of knocks in the right cadence it triggers the motor to turn the deadbolt and unlock the door.  If the sequence isn&#8217;t recognized, the system resets and listens for knocks again.</p>
<p>The default code is <a href="http://en.wikipedia.org/wiki/Shave_and_a_Haircut">Shave and a Hair Cut</a> but if that&#8217;s too obvious you can enter a new knock sequence by holding down the red button and knocking your new secret knock (up to 20 knocks).  The rhythm of your favorite song, Morse code, whatever!  The widget will play back your knock (by blinking the lights) so you can be sure it heard everything correctly.</p>
<p>The whole thing is attached to the door with suction cups</p>
<p>The components are simple, most of the work is done in the microcontroller.  The source code for the Arduino is available at the bottom of the page if you&#8217;re curious.</p>
<p><strong>How does it work?</strong></p>
<p>First it records the time between knocks.  If there is a long wait for a knock it stops listening and starts analyzing.</p>
<div id="attachment_236" class="wp-caption alignleft" style="width: 190px"><a href="http://grathio.com/assets_c/2009/10/knock_lock_circuit-256.html"><img class="size-full wp-image-236" title="Basic circuity" src="http://arduinofun.com/blog/wp-content/uploads/2009/11/slk2.jpg" alt="Basic circuity" width="180" height="240" /></a><p class="wp-caption-text">Basic circuity</p></div>
<p>First it checks the number of knocks.  If that&#8217;s right, we go on to more vigorous authentication.   First it converts the absolute timing of the knocks to the rhythm of the knocks.  This lets us knock fast or slow and as long as we get the rhythm right it will unlock.  That way I can still unlock the door if I&#8217;m tired or full of caffeine.  After this it compares the timing with the secret key and if any individual knock is off by too much or the whole thing is off by a certain average amount the door stays locked.  If not, we trigger the motor to turn and the lock to unlock.  If the programming button is pressed it saves the rhythm information and then plays it back.</p>
<p>The detection is surprisingly accurate and can even be dialed up so it&#8217;s precise enough  to detect an individual person&#8217;s variation on a knock, similar to a Morse coder&#8217;s &#8216;<a href="http://books.google.com/books?id=k3XeGh9PXAYC&amp;lpg=PA677&amp;ots=PLV5LGJ712&amp;dq=code%20breaking%20world%20war%20II%20fist%20-first&amp;pg=PA677#v=onepage&amp;q=&amp;f=false">fist</a>&#8216;.  (Though when the verifying is this tight it also triggers false negatives which are annoying.)</p>
<p>To keep things simple (and it&#8217;s because it&#8217;s what I had available) a motor is attached to the deadbolt using two pieces of spring steel bolted across the D shaft of the motor so that the connection will slip when the lock turns as far as it can. A more precise (and probably durable) way to do it would be to use a servo to turn the lock or have a detector sense when the lock had reached its extent.  Or replace the dead bolt with a solenoid.  Or whatever else you can think of.</p>
<div id="attachment_237" class="wp-caption alignleft" style="width: 329px"><img class="size-full wp-image-237" title="Circuit fitting" src="http://arduinofun.com/blog/wp-content/uploads/2009/11/slk3.jpg" alt="Circuit fitting" width="319" height="239" /><p class="wp-caption-text">Circuit fitting</p></div>
<p>The rest of the electronics are nothing special.  Its so simple that just adding feedback LEDs almost doubled the parts count.  The Arduino has a lot of unused potential on this project.</p>
<p>No proper schematic yet, but there&#8217;s a layout and parts list at the bottom of the page. Look for a fully documented <a href="http://www.instructables.com/">Instructable</a> soon.</p>
<p>With some extra electronics (an <a href="http://en.wikipedia.org/wiki/H-bridge">H-bridge</a>) it would be possible to have the door automatically lock as well as unlock. Other improvements or changes that someone could do:</p>
<ul>
<li>Adding a knob to adjust the sensitivity.</li>
<li>Building it into an actual door knocker.</li>
<li>Using a more economical microcontroller and enabling a sleep mode for better battery life.</li>
<li>Making the whole package small enough to fit inside the door.</li>
<li>Storing several knocks so several people can have their own private knocks.</li>
<li>Adding a real-time clock and using different knocks for different days of the week or times of day.</li>
<li>Listening for door bell presses rather than door knocks.</li>
<li>Adding a servo or solenoid powered knocker to provide feedback through the door.  It could then offer a challenge-response security where the door starts a knock sequence and the user has to finish it correctly.</li>
<li>Rather than listening for knocks, putting a photoresistor in the peep hole and detecting flashes of light from a pocket flashlight or simply by placing your hand over the peephole. Or an infrared receiver and use special key presses on a remote control.</li>
</ul>
<div id="attachment_241" class="wp-caption alignleft" style="width: 310px"><a href="http://grathio.com/assets_c/2009/10/knock_sensor_layout_and_parts_list-277.html"><img class="size-medium wp-image-241" title="Knock sensor layout" src="http://arduinofun.com/blog/wp-content/uploads/2009/11/knock_sensor_layout-300x153.jpg" alt="Knock sensor layout (click for larger view)" width="300" height="153" /></a><p class="wp-caption-text">Knock sensor layout (click for larger view)</p></div>
<p>Do I have to point out that this is not a great security measure since overhearing a knock sequence is pretty trivial?  No.  But it&#8217;s fun to make and play with.</p>
<p><strong>Here&#8217;s my code:</strong> If you have trouble with cut and paste below you can <a href="http://grathio.com/assets/secret_knock_detector.pde">download the .pde file here</a>.</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="coMULTI">/* Detects patterns of knocks and triggers a motor to unlock</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">it if the pattern is correct.</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">By Steve Hoefer http://grathio.com</span></div>
</li>
<li class="li2">
<div class="de2"><span class="coMULTI">Version 0.1.09.10.24</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">Licensed under Creative Commons Attribution-Noncommercial-Share Alike 3.0</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">Analog Pin 0: Piezo speaker (connected to ground with 1M pulldown resistor)</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">Digital Pin 2: Switch to enter a new code. &nbsp;Short this to enter programming mode.</span></div>
</li>
<li class="li2">
<div class="de2"><span class="coMULTI">Digital Pin 3: DC gear reduction motor attached to the lock. (Or a motor controller or</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">a solenoid or other unlocking mechanisim.)</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">Digital Pin 4: Green LED.</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">Digital Pin 5: Red LED.</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">*/</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// Pin definitions</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw4">const</span> <span class="kw4">int</span> knockSensor = <span class="nu0">0</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// Piezo sensor on pin 0.</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw4">const</span> <span class="kw4">int</span> programSwitch = <span class="nu0">2</span>;</div>
</li>
<li class="li2">
<div class="de2"><span class="co1">// If this is high we program a new code.</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw4">const</span> <span class="kw4">int</span> lockMotor = <span class="nu0">3</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// Gear motor used to turn the lock.</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw4">const</span> <span class="kw4">int</span> redLED = <span class="nu0">4</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// Status LED</span></div>
</li>
<li class="li2">
<div class="de2"><span class="kw4">const</span> <span class="kw4">int</span> greenLED = <span class="nu0">5</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// Status LED</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// Tuning constants.</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// Could be made vars and hooked to potentiometers for soft configuration, etc.</span></div>
</li>
<li class="li2">
<div class="de2"><span class="kw4">const</span> <span class="kw4">int</span> threshold = <span class="nu0">4</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// Minimum signal from the piezo to register as a knock</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw4">const</span> <span class="kw4">int</span> rejectValue = <span class="nu0">25</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// If an individual knock is off by this percentage of a knock we don&#8217;t unlock..</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw4">const</span> <span class="kw4">int</span> averageRejectValue = <span class="nu0">15</span>;</div>
</li>
<li class="li2">
<div class="de2"><span class="co1">// If the average timing of the knocks is off by this percent we don&#8217;t unlock.</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw4">const</span> <span class="kw4">int</span> knockFadeTime = <span class="nu0">150</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// milliseconds we allow a knock to fade before we listen for another one. (Debounce timer.)</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw4">const</span> <span class="kw4">int</span> lockTurnTime = <span class="nu0">450</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// milliseconds that we run the motor to get it to go a half turn.</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw4">const</span> <span class="kw4">int</span> maximumKnocks = <span class="nu0">20</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// Maximum number of knocks to listen for.</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw4">const</span> <span class="kw4">int</span> knockComplete = <span class="nu0">1200</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// Longest time to wait for a knock before we assume that it&#8217;s finished.</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// Variables.</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw4">int</span> secretCode<span class="br0">&#91;</span>maximumKnocks<span class="br0">&#93;</span> = <span class="br0">&#123;</span><span class="nu0">50</span>, <span class="nu0">25</span>, <span class="nu0">25</span>, <span class="nu0">50</span>, <span class="nu0">100</span>, <span class="nu0">50</span>, <span class="nu0">0</span>, <span class="nu0">0</span>, <span class="nu0">0</span>, <span class="nu0">0</span>, <span class="nu0">0</span>, <span class="nu0">0</span>, <span class="nu0">0</span>, <span class="nu0">0</span>, <span class="nu0">0</span>, <span class="nu0">0</span>, <span class="nu0">0</span>, <span class="nu0">0</span>, <span class="nu0">0</span>, <span class="nu0">0</span><span class="br0">&#125;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// Initial setup: &quot;Shave and a Hair Cut, two bits.&quot;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw4">int</span> knockReadings<span class="br0">&#91;</span>maximumKnocks<span class="br0">&#93;</span>;</div>
</li>
<li class="li2">
<div class="de2"><span class="co1">// When someone knocks this array fills with delays between knocks.</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw4">int</span> knockSensorValue = <span class="nu0">0</span>; <span class="co1">// Last reading of the knock sensor.</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw4">void</span> setup<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">pinMode<span class="br0">&#40;</span>knockSensor, OUTPUT<span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">pinMode<span class="br0">&#40;</span>lockMotor, OUTPUT<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">pinMode<span class="br0">&#40;</span>redLED, OUTPUT<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">pinMode<span class="br0">&#40;</span>greenLED, OUTPUT<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">pinMode<span class="br0">&#40;</span>programSwitch, INPUT<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li2">
<div class="de2"><span class="co1">//Serial.begin(19200);</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// Uncomment the Serial.bla lines for debugging.</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//Serial.println(&quot;Program start.&quot;); &nbsp;// This line too.</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">digitalWrite<span class="br0">&#40;</span>greenLED, HIGH<span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2"><span class="co1">// Green LED on, everything is go.</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw4">void</span> loop<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// Listen for any knock at all.</span></div>
</li>
<li class="li2">
<div class="de2">knockSensorValue = analogRead<span class="br0">&#40;</span>knockSensor<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">if</span> <span class="br0">&#40;</span>knockSensorValue &gt;=threshold<span class="br0">&#41;</span><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">listenToSecretKnock<span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span> </div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// Records the timing of knocks.</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw4">void</span> listenToSecretKnock<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//Serial.println(&quot;knock starting&quot;); &nbsp; &nbsp;// debug.</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw4">int</span> i = <span class="nu0">0</span>;</div>
</li>
<li class="li2">
<div class="de2"><span class="co1">// First lets reset the listening array.</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">for</span> <span class="br0">&#40;</span>i=<span class="nu0">0</span>;i=threshold<span class="br0">&#41;</span><span class="br0">&#123;</span> &nbsp; <span class="co1">//got another knock&#8230;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//record the delay time.</span></div>
</li>
<li class="li1">
<div class="de1">now=millis<span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">knockReadings<span class="br0">&#91;</span>currentKnockNumber<span class="br0">&#93;</span> = now-startTime;</div>
</li>
<li class="li2">
<div class="de2">currentKnockNumber ++; &nbsp; <span class="co1">//increment the counter</span></div>
</li>
<li class="li1">
<div class="de1">startTime=now;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// and reset our timer for the next knock</span></div>
</li>
<li class="li1">
<div class="de1">digitalWrite<span class="br0">&#40;</span>greenLED, LOW<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">delay<span class="br0">&#40;</span>knockFadeTime<span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2"><span class="co1">// again, a little delay to let the knock decay.</span></div>
</li>
<li class="li1">
<div class="de1">digitalWrite<span class="br0">&#40;</span>greenLED, HIGH<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">now=millis<span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//did we timeout or run out of knocks?</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span> <span class="kw1">while</span> <span class="br0">&#40;</span><span class="br0">&#40;</span>now-startTime &lt; knockComplete<span class="br0">&#41;</span> &amp;amp;&amp;amp; <span class="br0">&#40;</span>currentKnockNumber &lt; maximumKnocks<span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//we&#8217;ve got our knock recorded, lets see if it&#8217;s valid</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">if</span> <span class="br0">&#40;</span>validateKnock<span class="br0">&#40;</span><span class="br0">&#41;</span> == <span class="kw2">true</span><span class="br0">&#41;</span><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">triggerDoorUnlock<span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span> <span class="kw1">else</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//Serial.println(&quot;Secret knock failed.&quot;);</span></div>
</li>
<li class="li2">
<div class="de2">digitalWrite<span class="br0">&#40;</span>greenLED, LOW<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// We didn&#8217;t unlock, so blink the red LED as visual feedback.</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">for</span> <span class="br0">&#40;</span>i=<span class="nu0">0</span>;i&lt;<span class="nu0">4</span>;i++<span class="br0">&#41;</span><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; digitalWrite<span class="br0">&#40;</span>redLED, HIGH<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; delay<span class="br0">&#40;</span><span class="nu0">100</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; digitalWrite<span class="br0">&#40;</span>redLED, LOW<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; delay<span class="br0">&#40;</span><span class="nu0">100</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; digitalWrite<span class="br0">&#40;</span>greenLED, HIGH<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li2">
<div class="de2"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// Runs the motor (or whatever) to unlock the door.</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw4">void</span> triggerDoorUnlock<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//Serial.println(&quot;Door unlocked!&quot;);</span></div>
</li>
<li class="li2">
<div class="de2"><span class="kw4">int</span> i=<span class="nu0">0</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// turn the motor on for a bit.</span></div>
</li>
<li class="li1">
<div class="de1">digitalWrite<span class="br0">&#40;</span>lockMotor, HIGH<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">digitalWrite<span class="br0">&#40;</span>greenLED, HIGH<span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2"><span class="co1">// And the green LED too.</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">delay <span class="br0">&#40;</span>lockTurnTime<span class="br0">&#41;</span>; &nbsp; <span class="co1">// Wait a bit.</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">digitalWrite<span class="br0">&#40;</span>lockMotor, LOW<span class="br0">&#41;</span>; &nbsp;<span class="co1">// Turn the motor off.</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// Blink the green LED a few times for more visual feedback.</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">for</span> <span class="br0">&#40;</span>i=<span class="nu0">0</span>; i &lt; <span class="nu0">5</span>; i++<span class="br0">&#41;</span><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">digitalWrite<span class="br0">&#40;</span>greenLED, LOW<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">delay<span class="br0">&#40;</span><span class="nu0">100</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">digitalWrite<span class="br0">&#40;</span>greenLED, HIGH<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">delay<span class="br0">&#40;</span><span class="nu0">100</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// Sees if our knock matches the secret.</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// returns true if it&#8217;s a good knock, false if it&#8217;s not.</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// todo: break it into smaller functions for readability.</span></div>
</li>
<li class="li1">
<div class="de1">boolean validateKnock<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span></div>
</li>
<li class="li2">
<div class="de2"><span class="kw4">int</span> i=<span class="nu0">0</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// simplest check first: Did we get the right number of knocks?</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw4">int</span> currentKnockCount = <span class="nu0">0</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw4">int</span> secretKnockCount = <span class="nu0">0</span>;</div>
</li>
<li class="li2">
<div class="de2"><span class="kw4">int</span> maxKnockInterval = <span class="nu0">0</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// We use this later to normalize the times.</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">for</span> <span class="br0">&#40;</span>i=<span class="nu0">0</span>;i <span class="nu0">0</span><span class="br0">&#41;</span><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">currentKnockCount++;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">if</span> <span class="br0">&#40;</span>secretCode<span class="br0">&#91;</span>i<span class="br0">&#93;</span> &gt; <span class="nu0">0</span><span class="br0">&#41;</span><span class="br0">&#123;</span> &nbsp;<span class="co1">//todo: precalculate this.</span></div>
</li>
<li class="li1">
<div class="de1">secretKnockCount++;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li2">
<div class="de2"><span class="kw1">if</span> <span class="br0">&#40;</span>knockReadings<span class="br0">&#91;</span>i<span class="br0">&#93;</span> &gt; maxKnockInterval<span class="br0">&#41;</span><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// collect normalization data while we&#8217;re looping.</span></div>
</li>
<li class="li1">
<div class="de1">maxKnockInterval = knockReadings<span class="br0">&#91;</span>i<span class="br0">&#93;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// If we&#8217;re recording a new knock, save the info and get out of here.</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">if</span> <span class="br0">&#40;</span>digitalRead<span class="br0">&#40;</span>programSwitch<span class="br0">&#41;</span>==HIGH<span class="br0">&#41;</span><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">for</span> <span class="br0">&#40;</span>i=<span class="nu0">0</span>;i&lt; maximumKnocks ; i++<span class="br0">&#41;</span><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">digitalWrite<span class="br0">&#40;</span>greenLED, LOW<span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">digitalWrite<span class="br0">&#40;</span>redLED, LOW<span class="br0">&#41;</span>; <span class="co1">// only turn it on if there&#8217;s a delay</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">if</span> <span class="br0">&#40;</span>secretCode<span class="br0">&#91;</span>i<span class="br0">&#93;</span> &gt; <span class="nu0">0</span><span class="br0">&#41;</span><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">delay<span class="br0">&#40;</span> map<span class="br0">&#40;</span>secretCode<span class="br0">&#91;</span>i<span class="br0">&#93;</span>,<span class="nu0">0</span>, <span class="nu0">100</span>, <span class="nu0">0</span>, maxKnockInterval<span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// Expand the time back out to what it was. &nbsp;Roughly.</span></div>
</li>
<li class="li1">
<div class="de1">digitalWrite<span class="br0">&#40;</span>greenLED, HIGH<span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">digitalWrite<span class="br0">&#40;</span>redLED, HIGH<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">delay<span class="br0">&#40;</span><span class="nu0">50</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">return</span> <span class="kw2">false</span>;</div>
</li>
<li class="li2">
<div class="de2"><span class="co1">// We don&#8217;t unlock the door when we are recording a new knock.</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">if</span> <span class="br0">&#40;</span>currentKnockCount != secretKnockCount<span class="br0">&#41;</span><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">return</span> <span class="kw2">false</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">/* &nbsp;Now we compare the relative intervals of our knocks, not the absolute time between them.</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">(ie: if you do the same pattern slow or fast it should still open the door.)</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">This makes it less picky, which while making it less secure can also make it</span></div>
</li>
<li class="li2">
<div class="de2"><span class="coMULTI">less of a pain to use if you&#8217;re tempo is a little slow or fast.</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">*/</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw4">int</span> totaltimeDifferences=<span class="nu0">0</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw4">int</span> timeDiff=<span class="nu0">0</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">for</span> <span class="br0">&#40;</span>i=<span class="nu0">0</span>;i rejectValue<span class="br0">&#41;</span><span class="br0">&#123;</span> <span class="co1">// Individual value too far out of whack</span></div>
</li>
<li class="li2">
<div class="de2"><span class="kw1">return</span> <span class="kw2">false</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">totaltimeDifferences += timeDiff;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// It can also fail if the whole thing is too inaccurate.</span></div>
</li>
<li class="li2">
<div class="de2"><span class="kw1">if</span> <span class="br0">&#40;</span>totaltimeDifferences/secretKnockCount&gt;averageRejectValue<span class="br0">&#41;</span><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">return</span> <span class="kw2">false</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">return</span> <span class="kw2">true</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Farduinofun.com%2Fblog%2F2009%2F11%2F02%2Fsecret-knock-detecting-door-lock-build-it%2F&amp;linkname=Secret%20Knock%20Detecting%20Door%20Lock%20%28Build%20It%29"><img src="http://arduinofun.com/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://arduinofun.com/blog/2009/11/02/secret-knock-detecting-door-lock-build-it/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Silly String Shooting Spider (Build It)</title>
		<link>http://arduinofun.com/blog/2009/11/01/silly-string-shooting-spider-contest-entry/</link>
		<comments>http://arduinofun.com/blog/2009/11/01/silly-string-shooting-spider-contest-entry/#comments</comments>
		<pubDate>Mon, 02 Nov 2009 00:43:22 +0000</pubDate>
		<dc:creator>Administrator</dc:creator>
				<category><![CDATA[Contest Entries]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Arduino Duemilanove]]></category>
		<category><![CDATA[Arduino Project]]></category>
		<category><![CDATA[Arduino Sketch]]></category>
		<category><![CDATA[ATmega328]]></category>
		<category><![CDATA[LED]]></category>
		<category><![CDATA[Parallax Ping Sonar]]></category>
		<category><![CDATA[Relay]]></category>
		<category><![CDATA[Sensor]]></category>

		<guid isPermaLink="false">http://arduinofun.com/blog/?p=215</guid>
		<description><![CDATA[Contest Entry by Todd Harrison
I had great fun this Halloween with a silly string shooting spider!  My plan was to use an Arduino micro-controller developer board to control my son’s “Teenage Mutant Ninja Turtle” RC car that already shoots silly string.  I didn’t get the spider to actually squirt the silly string but when you’re looking at [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_216" class="wp-caption alignleft" style="width: 330px"><strong><a><img class="size-full wp-image-216" title="Silly String Spider" src="http://arduinofun.com/blog/wp-content/uploads/2009/11/sillyspider.jpg" alt="Silly String Spider" width="320" height="239" /></a></strong><p class="wp-caption-text">Silly String Spider</p></div>
<p><strong><a href="http://www.toddfun.com/2009/10/31/silly-string-shooting-halloween-spider/">Contest Entry by Todd Harrison</a></strong></p>
<p>I had great fun this Halloween with a silly string shooting spider!  My plan was to use an Arduino micro-controller developer board to control my son’s “<a href="http://www.amazon.com/Playmates-Teenage-Mutant-Turtles-Spewer/dp/B0007SMKK8" target="_blank">Teenage Mutant Ninja Turtle</a>” RC car that already shoots silly string.  I didn’t get the spider to actually squirt the silly string but when you’re looking at a big black spider and something shoots silly string at you from the same direction it scares you just the same.</p>
<p>I was inspired to do this 4 hour marathon build by a blog posting by Eric on <a title="www.Instructables.com" href="http://www.instructables.com/id/Arduino-controlled-Silly-String-shooter/" target="_blank">www.Instructables.com</a>. Eric created a silly string shooting pumpkin which was so incredible I just had to build a spider for Halloween that did the same.<span id="more-215"></span></p>
<p>My major problem was that once I heard about Eric’s pumpkin I only had a day to get the supplies and about 4 hours of free time to wire-up something, code it and get it out in the front yard before the kids started coming for tricks or treats.</p>
<p><strong>Here is a component breakdown of the final prop.</strong></p>
<ul>
<li>The red dot and arrow point      to the <a href="http://www.amazon.com/Playmates-Teenage-Mutant-Turtles-Spewer/dp/B0007SMKK8" target="_blank">RC car </a>hiding under      a bush.</li>
<li>2) <a href="http://www.amazon.com/Playmates-Teenage-Mutant-Turtles-Spewer/dp/B0007SMKK8" target="_blank">RC car</a> remote      control.</li>
<li>3) <a href="http://www.radioshack.com/product/index.jsp?productId=2062478" target="_blank">Relay</a> used by pin 2      on the Arduino to fire the remote control’s silly string button.</li>
<li>4) <a href="http://www.arduino.cc/" target="_blank">Arduino</a> board: <a href="http://arduino.cc/en/Main/ArduinoBoardDuemilanove" target="_blank">Duemilanove with ATmega328</a> Purchased      from <a href="http://www.adafruit.com/index.php?main_page=product_info&amp;cPath=17&amp;products_id=50" target="_blank">adafruit.com</a></li>
<li>5) Small blue servo to yank      on the spiders leg: <a href="http://www.hobbypartz.com/kahaoubrmo11.html" target="_blank">TowerPro SG-50</a>.</li>
<li>6) Two red LEDs for spider      eyes. Not on the spider I know, I ran out of dev time</li>
<li>7) <a href="http://www.makershed.com/ProductDetails.asp?ProductCode=MKPX5" target="_blank">Parallax Ping)))</a> sonar sensor, held up with helping hands.</li>
<li>8 ) Big black spider</li>
</ul>
<div id="attachment_217" class="wp-caption alignleft" style="width: 330px"><img class="size-full wp-image-217" title="Silly String Spider Parts" src="http://arduinofun.com/blog/wp-content/uploads/2009/11/sillyspider2.jpg" alt="Silly String Spider Parts" width="320" height="239" /><p class="wp-caption-text">Silly String Spider Parts</p></div>
<p>I originally wanted the string to shoot from the spider’s behind but I really didn’t have time for that so I hid the RC car in the bushes behind the spider and loaded it with a fresh can of silly string.  All I really had to do was get the Arduino to sense somebody getting to close to the spider’s face and then “POW!” fire the silly string using the car’s remote control.</p>
<p>Just for extra effect I wanted the spider to move using a servo and have red LED eyes that blinked.  I also wanted the blinking and servo movement to ramp up faster and faster as a person got closer. To get this effect I used a <a href="http://www.parallax.com/Store/Sensors/ObjectDetection/tabid/176/CategoryID/51/List/0/Level/a/ProductID/92/Default.aspx?SortField=ProductName,ProductName" target="_blank">Parallax</a> Ping))) sonar sensor to track the approaching prey as well as to calculate an agitation delay.  The agitation delay was used to make the spider look more and more upset as the person got closer. If somebody was at a great distance the LED eyes flashed slow and the spider made slow jerking motions, but as the distance delay multiplier shortened the eyes flash furiously fast and the spider would jerk like mad!  If the trick-or-treater dared get closer the Arduino would fire a relay connected to the remote control and they would get a face full of silly string.</p>
<div id="attachment_221" class="wp-caption alignleft" style="width: 330px"><img class="size-full wp-image-221" title="Silly String Spider Board Control" src="http://arduinofun.com/blog/wp-content/uploads/2009/11/ssboard.jpg" alt="Silly String Spider Board Control" width="320" height="239" /><p class="wp-caption-text">Silly String Spider Board Control</p></div>
<p>A lot of people did have the nerve to walk up on the spider but in the dark it took them a second to even realize they had just been doused in the face with silly string, but then they would laugh and do it again just for fun.  It only really scared a few that didn’t expect anything or were just standing behind the intended victim who was fortunately to short to get hit.</p>
<p>I didn’t get time to mount the eyes in the spider’s head but the red flashing LEDs on the control board seemed to have the same effect as they would have had if they were on the spider.  They were only needed to get the kids attention in the dark.</p>
<p><strong>Arduino Sketch:</strong></p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="co2">#include</span></div>
</li>
<li class="li1">
<div class="de1">Servo myservo; &nbsp;<span class="co1">// create servo object to control a servo</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw4">int</span> pingPin = <span class="nu0">7</span>; <span class="co1">// pin for ping sensor</span></div>
</li>
<li class="li2">
<div class="de2"><span class="kw4">int</span> stringPin = <span class="nu0">2</span>; <span class="co1">// pin that will fire the silly string remote</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw4">int</span> LED_Eyes_Pin = <span class="nu0">11</span>; <span class="co1">// pin for the two eyes</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw4">int</span> multiplier; <span class="co1">// multiplier for delay</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw4">int</span> delay_time; <span class="co1">// time to delay before next step</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li2">
<div class="de2"><span class="kw4">void</span> setup<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; pinMode<span class="br0">&#40;</span>LED_Eyes_Pin, OUTPUT<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; pinMode<span class="br0">&#40;</span>stringPin, OUTPUT<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; myservo.<span class="me1">attach</span><span class="br0">&#40;</span><span class="nu0">9</span><span class="br0">&#41;</span>; &nbsp;<span class="co1">// attaches the servo on pin 9 to the servo object</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; Serial.<span class="me1">begin</span><span class="br0">&#40;</span><span class="nu0">9600</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; digitalWrite<span class="br0">&#40;</span>stringPin, LOW<span class="br0">&#41;</span>; &nbsp; &nbsp;<span class="co1">//make sure this is off so we don’t shoot string</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw4">void</span> loop<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; ping<span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; eyes_and_servo<span class="br0">&#40;</span><span class="nu0">0</span>,<span class="nu0">0</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; delay<span class="br0">&#40;</span>delay_time<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; ping<span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; eyes_and_servo<span class="br0">&#40;</span><span class="nu0">100</span>,<span class="nu0">255</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; delay<span class="br0">&#40;</span>delay_time<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw4">void</span> eyes_and_servo<span class="br0">&#40;</span><span class="kw4">int</span> servo_pos, <span class="kw4">int</span> eye_pulse<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; analogWrite<span class="br0">&#40;</span>LED_Eyes_Pin, eye_pulse<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; myservo.<span class="me1">write</span><span class="br0">&#40;</span>servo_pos<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw4">void</span> ping<span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
<li class="li2">
<div class="de2"><span class="br0">&#123;</span> &nbsp;<span class="kw4">long</span> duration, inches;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="co1">// The PING))) is triggered by a HIGH pulse of 2 or more microseconds.</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="co1">// We give a short LOW pulse beforehand to ensure a clean HIGH pulse.</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; pinMode<span class="br0">&#40;</span>pingPin, OUTPUT<span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; digitalWrite<span class="br0">&#40;</span>pingPin, LOW<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; delayMicroseconds<span class="br0">&#40;</span><span class="nu0">2</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; digitalWrite<span class="br0">&#40;</span>pingPin, HIGH<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; delayMicroseconds<span class="br0">&#40;</span><span class="nu0">5</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; digitalWrite<span class="br0">&#40;</span>pingPin, LOW<span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="co1">// The same pin is used to read the signal from the PING))): a HIGH</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="co1">// pulse whose duration is the time (in microseconds) from the sending</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="co1">// of the ping to the reception of its echo off of an object.</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; pinMode<span class="br0">&#40;</span>pingPin, INPUT<span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; duration = pulseIn<span class="br0">&#40;</span>pingPin, HIGH<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="co1">// convert the time into a distance</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; inches = microsecondsToInches<span class="br0">&#40;</span>duration<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; multiplier = inches/<span class="nu0">10</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; delay_time = inches * multiplier;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>delay_time &gt; <span class="nu0">1000</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>delay_time = <span class="nu0">500</span>;<span class="br0">&#125;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>delay_time &lt; <span class="nu0">300</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp;digitalWrite<span class="br0">&#40;</span>stringPin, HIGH<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp;delay<span class="br0">&#40;</span><span class="nu0">500</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp;digitalWrite<span class="br0">&#40;</span>stringPin, LOW<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp;delay<span class="br0">&#40;</span><span class="nu0">2000</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="br0">&#125;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; Serial.<span class="me1">print</span><span class="br0">&#40;</span>delay_time<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; Serial.<span class="me1">print</span><span class="br0">&#40;</span>” delay time; inches are= “<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; Serial.<span class="me1">print</span><span class="br0">&#40;</span>inches<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; Serial.<span class="me1">println</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw4">long</span> microsecondsToInches<span class="br0">&#40;</span><span class="kw4">long</span> microseconds<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">return</span> microseconds / <span class="nu0">74</span> / <span class="nu0">2</span>;</div>
</li>
<li class="li2">
<div class="de2"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p><strong>Project Videos</strong><br />
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="320" height="240" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/nG1tazzDkAU&amp;hl=en&amp;fs=1&amp;color1=0x2b405b&amp;color2=0x6b8ab6" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="320" height="240" src="http://www.youtube.com/v/nG1tazzDkAU&amp;hl=en&amp;fs=1&amp;color1=0x2b405b&amp;color2=0x6b8ab6" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="320" height="240" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/HOJeZQfNOQI&amp;hl=en&amp;fs=1&amp;color1=0x2b405b&amp;color2=0x6b8ab6" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="320" height="240" src="http://www.youtube.com/v/HOJeZQfNOQI&amp;hl=en&amp;fs=1&amp;color1=0x2b405b&amp;color2=0x6b8ab6" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Farduinofun.com%2Fblog%2F2009%2F11%2F01%2Fsilly-string-shooting-spider-contest-entry%2F&amp;linkname=Silly%20String%20Shooting%20Spider%20%28Build%20It%29"><img src="http://arduinofun.com/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://arduinofun.com/blog/2009/11/01/silly-string-shooting-spider-contest-entry/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Arduino Halloween Dropping Spider (Build It)</title>
		<link>http://arduinofun.com/blog/2009/11/01/arduino-halloween-dropping-spider-contest-entry/</link>
		<comments>http://arduinofun.com/blog/2009/11/01/arduino-halloween-dropping-spider-contest-entry/#comments</comments>
		<pubDate>Sun, 01 Nov 2009 20:32:34 +0000</pubDate>
		<dc:creator>Administrator</dc:creator>
				<category><![CDATA[Contest Entries]]></category>
		<category><![CDATA[Adafruit Protoshield]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Arduino Duemilanove]]></category>
		<category><![CDATA[Arduino Project]]></category>
		<category><![CDATA[Arduino Sketch]]></category>
		<category><![CDATA[Arduino Twitter]]></category>
		<category><![CDATA[Futaba Servos]]></category>
		<category><![CDATA[ioBridge Monitor]]></category>
		<category><![CDATA[LED]]></category>
		<category><![CDATA[Parallax]]></category>
		<category><![CDATA[PIR Motion Sensor]]></category>
		<category><![CDATA[Servo]]></category>
		<category><![CDATA[Wireless Webcam]]></category>
		<category><![CDATA[X10 Firecracker]]></category>

		<guid isPermaLink="false">http://arduinofun.com/blog/?p=196</guid>
		<description><![CDATA[ 
Contest Entry by Noel Portugal
My Halloween project consisted of a dropping spider triggered by a PIR motion sensor mounted on a Jackolantern. The motion sensor triggered a dropping spider, lights, sounds, low laying fog and finally a tweet with a picture attached. 
Setup: It&#8217;s all pretty basic. The arduino controlled the PIR motion sensor, the servos [...]]]></description>
			<content:encoded><![CDATA[<p><strong> </strong></p>
<div id="attachment_206" class="wp-caption alignleft" style="width: 330px"><strong><strong><img class="size-full wp-image-206" title="Halloween Dropping Spider" src="http://arduinofun.com/blog/wp-content/uploads/2009/11/DSC_0171.JPG" alt="Halloween Dropping Spider" width="320" height="214" /></strong></strong><p class="wp-caption-text">Halloween Dropping Spider</p></div>
<p><strong>Contest Entry by <a href="http://noelportugal.blogspot.com/2009/11/halloween-dropping-spider-jackolantern.html">Noel Portugal</a></strong></p>
<p>My Halloween project consisted of a dropping spider triggered by a PIR motion sensor mounted on a Jackolantern. The motion sensor triggered a dropping spider, lights, sounds, low laying fog and finally a <a href="http://twitter.com/ioalerts">tweet</a> with a picture attached.<strong> </strong></p>
<p><strong>Setup</strong>: It&#8217;s all pretty basic. The arduino controlled the PIR motion sensor, the servos for dropping spider reel, Jackolantern LED lights, toy with scary sound, and the X10 CM17A. Then the arduino sent a serial message to the ioBridge serial API telling to GET the URL of my site. Then on my site I had a bash script with a while loop looking for request coming from the ioBridge server, then the script played a sound, grab the picture from a wireless webcam and post it to twitter via twitpic&#8217;s API using cURL.<span id="more-196"></span></p>
<p><strong> </strong></p>
<div id="attachment_197" class="wp-caption alignleft" style="width: 330px"><strong><strong><img class="size-full wp-image-197" title="Arduino Halloween Dropping Spider" src="http://arduinofun.com/blog/wp-content/uploads/2009/11/DSC_0187.JPG" alt="Arduino Halloween Dropping Spider" width="320" height="214" /></strong></strong><p class="wp-caption-text">Arduino Halloween Dropping Spider</p></div>
<p><strong>Arduino Sketch</strong><br />
<a href="http://noelportugal.googlepages.com/DroppingSpider.pde">Here is the arduino sketch</a>. I used the X10Firecracker and the Servo libraries as well as the PIR sensor example from the <a href="http://www.arduino.cc/playground/Code/PIRsense">arduino playground</a>.</p>
<p><strong>Spider Reel</strong><br />
I end up using an VHS tape as a reel. I had to modify one servo to have continuous rotation. I used <a href="http://www.kronosrobotics.com/an116/GAN116.shtml">this guide</a> to do so. The second servo just did the lift part.</p>
<p><strong>ioBridge Monitor</strong><br />
To establish the arduino-ioBridge serial communication I was planning to use an RF solution, but due to time constraints I had to use a long speaker cable to connect the arduino TX to ioBridge&#8217;s Serial Board RX with one wire and the second for GND.</p>
<p>This is the bash script I used to trigger a sound as well as send a twitpic.</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="co2">#!/bin/bash</span></div>
</li>
<li class="li1">
<div class="de1">booCounter=$<span class="nu0">1</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">while</span> <span class="kw2">true</span>;do</div>
</li>
<li class="li1">
<div class="de1">status=`tail -n <span class="nu0">1</span> /private/var/log/apache2/access_log | cut -f <span class="nu0">1</span> -d <span class="st0">&quot;-&quot;</span>`</div>
</li>
<li class="li2">
<div class="de2"><span class="kw1">if</span> <span class="br0">&#91;</span> <span class="st0">&quot;$status&quot;</span> = <span class="st0">&quot;00.00.000.000 &quot;</span> <span class="br0">&#93;</span></div>
</li>
<li class="li1">
<div class="de1">then</div>
</li>
<li class="li1">
<div class="de1">echo <span class="st0">&quot;Boo&quot;</span> &gt;&gt; /private/var/log/apache2/access_log</div>
</li>
<li class="li1">
<div class="de1">afplay /full/path/Halloween/werewolf.<span class="me1">mp3</span></div>
</li>
<li class="li1">
<div class="de1">msg=<span class="st0">&quot;Boo, victim $booCounter just got really scared&quot;</span></div>
</li>
<li class="li2">
<div class="de2">sleep <span class="nu0">5</span></div>
</li>
<li class="li1">
<div class="de1">curl -O http:<span class="co1">//www.mywebcam.com/IMAGE.JPG</span></div>
</li>
<li class="li1">
<div class="de1">curl -F media=@/full/path/Halloween/IMAGE.<span class="me1">JPG</span> -F <span class="st0">&quot;username=username&quot;</span> -F <span class="st0">&quot;password=password&quot;</span> -F</div>
</li>
<li class="li1">
<div class="de1"><span class="st0">&quot;message=$msg&quot;</span> http:<span class="co1">//twitpic.com/api/uploadAndPost</span></div>
</li>
<li class="li1">
<div class="de1">let booCounter=booCounter<span class="nu0">+1</span></div>
</li>
<li class="li2">
<div class="de2">fi</div>
</li>
<li class="li1">
<div class="de1">done</div>
</li>
</ol>
</div>
<p>I used my mac os x Apache 2 server. I had to give write permissions to the access_log so I could append a bogus line as a &#8220;break&#8221;.</p>
<p><strong>These are the parts that I used for this project:</strong></p>
<p><a href="http://arduino.cc/en/Main/ArduinoBoardDuemilanove">Arduino Duemilanove </a><br />
o <a href="http://www.adafruit.com/index.php?main_page=product_info&amp;products_id=51">Adafruit Protoshield</a></p>
<p><a href="http://iobridge.com/">ioBridge IO-204</a><br />
o <a href="http://iobridge.com/store/">ioBridge Serial Smart Board</a></p>
<p>x10 Firecracker <a href="http://kbase.x10.com/wiki/Firecracker">CM17A</a><br />
o x10 Transeiver, Appliance and lamp modules</p>
<p>VHS tape<br />
o <a href="http://iobridge.com/store/">2 Futaba S3003 servos</a><br />
o Nylon rope</p>
<p>Plastic Jackolantern<br />
o <a href="http://www.radioshack.com/product/index.jsp?productId=2906724">Parallax PIR sensor</a><br />
o 2 red LEDs<br />
+ 2 1K resistors<br />
o <a href="http://www.target.com/Big-Time-Toys-Checklane-Yada/dp/B001F3EPQQ">Checklane Yada Yada Yada</a> (thanks Erick for the tip <a href="http://www.instructables.com/id/Arduino-controlled-Silly-String-shooter/">http://www.instructables.com/id/Arduino-controlled-Silly-String-shooter/</a>)<br />
+ 1 2N2222 tranisistor<br />
+ 1 10k resistor</p>
<p>Fog Machine<br />
o <a href="http://www.radioshack.com/product/index.jsp?productId=2049721">125VAC/10A DPDT Plug-In Relay</a> (as a switch combined with x10)<br />
o Styrofoam cooler and dryer hose and Ice to create low laying fog.</p>
<p>Wireless webcam<br />
Lights and accesories<br />
o Incandescent black light, strobe light, black light bulbs.</p>
<p><strong>Project Video:</strong><br />
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="320" height="265" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/ahfG8N8Z2YI&amp;hl=en&amp;fs=1&amp;color1=0x2b405b&amp;color2=0x6b8ab6" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="320" height="265" src="http://www.youtube.com/v/ahfG8N8Z2YI&amp;hl=en&amp;fs=1&amp;color1=0x2b405b&amp;color2=0x6b8ab6" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Farduinofun.com%2Fblog%2F2009%2F11%2F01%2Farduino-halloween-dropping-spider-contest-entry%2F&amp;linkname=Arduino%20Halloween%20Dropping%20Spider%20%28Build%20It%29"><img src="http://arduinofun.com/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://arduinofun.com/blog/2009/11/01/arduino-halloween-dropping-spider-contest-entry/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Open Source ADM-Robot 1.0 (part 1)</title>
		<link>http://arduinofun.com/blog/2009/11/01/open-source-adm-robot-1-0-part-1/</link>
		<comments>http://arduinofun.com/blog/2009/11/01/open-source-adm-robot-1-0-part-1/#comments</comments>
		<pubDate>Sun, 01 Nov 2009 18:37:13 +0000</pubDate>
		<dc:creator>Administrator</dc:creator>
				<category><![CDATA[Project Files]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Arduino Project]]></category>
		<category><![CDATA[Arduino Robot]]></category>
		<category><![CDATA[Arduino Sketch]]></category>
		<category><![CDATA[GridConnect]]></category>
		<category><![CDATA[Open Source Project]]></category>
		<category><![CDATA[Open Source Robot]]></category>
		<category><![CDATA[PCB]]></category>
		<category><![CDATA[Printed Circuit Board]]></category>
		<category><![CDATA[Recycling]]></category>
		<category><![CDATA[Robot]]></category>
		<category><![CDATA[Science Fair Projects]]></category>
		<category><![CDATA[WiFly]]></category>

		<guid isPermaLink="false">http://arduinofun.com/blog/?p=174</guid>
		<description><![CDATA[It&#8217;s that time of year again&#8230; where the sounds of knowledge fill the home labs, garages and basements across the globe. Here in the ArduinoFun lab, we have been busy working on this years project ADM-Robot 1.0 aka Recycle-bot.
I will be posting progress photos and notes as we go along to document the process for [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_175" class="wp-caption alignleft" style="width: 330px"><img class="size-full wp-image-175" title="Drew and Jacob - Soldering boards" src="http://arduinofun.com/blog/wp-content/uploads/2009/11/sf1.jpg" alt="Drew and Jacob - Soldering boards" width="320" height="240" /><p class="wp-caption-text">Drew and Jacob - Soldering boards</p></div>
<p>It&#8217;s that time of year again&#8230; where the sounds of knowledge fill the home labs, garages and basements across the globe. Here in the ArduinoFun lab, we have been busy working on this years project ADM-Robot 1.0 aka Recycle-bot.</p>
<p>I will be posting progress photos and notes as we go along to document the process for our science fair project.</p>
<p>What is ADM 1.0? Basically we built an Arduino, added a Dual Motor Controller to it and a small prototyping area. Hence the name ADM (Arduino Dual Motor).  The board works and is programmed just like a normal Arduino. For the science fair, part of the rules stated we could not use an actual Arduino board, but were able to build or modify our own.<span id="more-174"></span></p>
<div id="attachment_176" class="wp-caption alignleft" style="width: 330px"><img class="size-full wp-image-176" title="Shawn and Jacob - Drilling component holes" src="http://arduinofun.com/blog/wp-content/uploads/2009/11/sf2.jpg" alt="Shawn and Jacob - Drilling component holes" width="320" height="240" /><p class="wp-caption-text">Shawn and Jacob - Drilling component holes</p></div>
<p>Below is a zip file which contains the files that will allow you to create your own PCB file. According to Drew and Jacob, Recycle bot will be used in school to help drive interest in getting classmates to start recycling. &#8220;Having a cool robot moving around the lunch room to collect your recyclables will encourage everyone to participate because it is so cool!&#8221;</p>
<p>We will be using a metal trash can that we found at the store that just looks like it was meant to be a robot.</p>
<p>To make a copy of the PCB, you can follow the <a href="http://www.instructables.com/id/Creating-Printed-Circuit-Boards-with-a-INKJET-Prin/">Instructable that I created</a> that uses a home Inkjet printer. The entire process works really well and the boards have turned out great.</p>
<p><a href="http://arduinofun.com/files/adm1.zip"></a></p>
<div id="attachment_183" class="wp-caption alignleft" style="width: 330px"><a><img class="size-full wp-image-183" title="Drew and Jacob - Prototyping ADM 1.0" src="http://arduinofun.com/blog/wp-content/uploads/2009/11/sf3.jpg" alt="Drew and Jacob - Prototyping ADM 1.0" width="320" height="240" /></a><p class="wp-caption-text">Drew and Jacob - Prototyping ADM 1.0</p></div>
<p><a href="http://arduinofun.com/files/adm1.zip">This zip file</a> contains two PDF files (solder side &amp; component side), for printing your own circuit board.</p>
<p>Once we get a little further along I will start posting some videos, photos and Arduino sketches that we use.</p>
<p>We are also working with <a href="http://www.gridconnect.com/wiflygsxkit.html">GridConnect</a> on a project, and hopefully if all goes well ADM will be enabled with WiFly</p>
<p>Board Photos on My <a href="http://www.flickr.com/photos/34908673@N00/">Flickr</a> Page.</p>
<p><a href="http://www.flickr.com/photos/34908673@N00/4067482659/">Component Side</a>, <a href="http://www.flickr.com/photos/34908673@N00/4068232404/">Solder Side</a></p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Farduinofun.com%2Fblog%2F2009%2F11%2F01%2Fopen-source-adm-robot-1-0-part-1%2F&amp;linkname=Open%20Source%20ADM-Robot%201.0%20%28part%201%29"><img src="http://arduinofun.com/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://arduinofun.com/blog/2009/11/01/open-source-adm-robot-1-0-part-1/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
