tag:blogger.com,1999:blog-84101404571226249732024-03-20T06:58:12.674-05:00The "Arduino, Kinect and related rants" BlogNMhttp://www.blogger.com/profile/03556991654093947404noreply@blogger.comBlogger19125tag:blogger.com,1999:blog-8410140457122624973.post-86754056657190483712013-01-03T11:17:00.005-06:002023-06-28T18:02:12.894-05:00The Fluid Wall Chapter<a href="https://www.packtpub.com/product/mastering-opencv-with-practical-computer-vision-projects/9781849517829" imageanchor="1" style="clear: left; display: inline !important; float: left; margin-bottom: 1em; margin-right: 1em; text-align: center;"><img border="0" src="https://content.packt.com/B02054/cover_image_small.jpeg" /></a><br />
<span style="font-family: inherit;">Late last year the complete development process of the Fluid Wall application was published as an online chapter in the book 'Mastering OpenCV with Practical Computer Vision Projects' The book contains a few absolutely amazing projects by some of the experts in OpenCV and the field of computer vision.</span><br />
<span style="font-family: inherit;"><br /></span>
<span style="font-family: inherit;">I am in no way an OpenCV expert, and am very grateful to have our Fluid Wall project included in the book as an online ad-on. This humble chapter you will attempt to give a detailed explanation about how we integrated the Kinect data through OpenNI and OpenCV with fluid mechanics of a fluid simulation from Jos Stam to create a fun, interactive program.</span><br />
<span style="font-family: inherit;"><br /></span>
<span style="font-family: inherit;"><br /></span>
<span style="font-family: inherit;">Furthermore, I would like to make acknowledgement here:</span><br />
<span style="font-family: inherit;"><br /></span>
<ul>
<hr />
<span style="color: #999999;">
I wanted to especially mention the work of another student from Texas A&M, whose name you will undoubtedly come across in the code included for this chapter. Fluid Wall was developed as part of a student project by <a href="http://www.futurelightstudios.com/">Austin Hines</a> and myself. Major credit for the project goes to Austin, as he was the creative mind behind it. He was also responsible for the arduous job of implementing the fluid simulation code into our application. Even though he wasn't able to participate in writing this chapter due to a number of work- and study-related preoccupations, but loads of credit for this project goes to him.
</span><hr />
</ul>
<span style="font-family: inherit;"><br /></span>
<span style="font-family: inherit;">See the following links for more details about the project or the book..</span><br />
<ul><span style="font-family: inherit;">
<li>Fluid Wall: <a href="http://code.google.com/p/fluidwall/">http://code.google.com/p/fluidwall/</a></li>
<li>The book: <a href="https://www.packtpub.com/product/mastering-opencv-with-practical-computer-vision-projects/9781849517829">http://www.packtpub.com/cool-projects-with-opencv/book</a></li>
<li>The Fluid Wall chapter: <a href="http://goo.gl/4msXc">http://goo.gl/4msXc</a></li>
</span></ul>
<span style="font-family: inherit;">
</span>NMhttp://www.blogger.com/profile/03556991654093947404noreply@blogger.com0tag:blogger.com,1999:blog-8410140457122624973.post-82455898510776608762011-10-04T13:37:00.000-05:002011-10-04T13:37:54.258-05:00Project FluidWall<br />
This is a project I have been working on with another student from Texas A&M Visualization Lab, Austin Hines.<br />
<br />
<a href="http://vizaphysical.blogspot.com/2011/04/visualization-of-final-project.html">Here's</a> a link to the project's initial draft on Austin's blog.<br />
We've also made this project opensource and created a whole separate blog for FluidWall.<br />
FluidWall Source: <a href="http://code.google.com/p/fluidwall/">http://code.google.com/p/fluidwall/</a><br />
FluidWall Blog: <a href="http://fluidwall.blogspot.com/">http://fluidwall.blogspot.com</a><br />
<br />
The idea was to use the depth information and user tracking from the Kinect to be able to interact with a fluid simulation on the screen. Austin Hines worked on all aspects related to the fluid simulation, while I handled exploring and integrating the SDK that would let us communicate with the Kinect with the most ease. Using the OpenNI along with with NITE middle ware we were able to get some really nice and simple depth data working with our simulation. This allowed us to have silhouettes of people / objects (whatever the depth sensor returned) to interact with fluid on the screen. Any movements would trigger the fluid which would dissipate in a bluish-white whirl. as depicted in pictures of the original idea on Austin's blog (mentioned above).<br />
<br />
Soon we were able to track users and send appropriate data into the fluid simulation. This allowed us to start emitting different colors for different users.<br />
<br />
The final result was quite amazing...<br />
<div class="separator" style="clear: both;">
<br /></div>
<iframe allowfullscreen="" frameborder="0" height="349" src="http://www.youtube.com/embed/FTSpvcU6ZKM" width="560"></iframe><br />
NMhttp://www.blogger.com/profile/03556991654093947404noreply@blogger.com0tag:blogger.com,1999:blog-8410140457122624973.post-61795417311920936842011-10-04T13:33:00.002-05:002011-10-04T13:33:23.254-05:00The Kinect SDK of Choice [OpenNI + Primesense + CLNUI]<br />
<b><span class="Apple-style-span" style="font-size: large;">Driving the Kinect Camera</span></b><br />
Using the OpenNI SDK with PrimeSense's Driver and middle-ware, life has been much simpler :)<br />
Here's what it can do right after the installation:<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<b><span class="Apple-style-span" style="font-size: large;">The Motor was Another Story Altogether</span></b></div>
<div class="separator" style="clear: both; text-align: left;">
The only problem with the PrimeSense driver was it does not support the Kinect Motor. So, after several experiments and some time searching online forums for a solution, it was discovered that the PrimeSense Sensor's camera driver and CLNUI motor + audio drivers can be installed to run side-by-side.</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
This is what the Device manager might look like on a Windows XP machine with the two installed together:</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhjSywOLUvEMa9bXraXOV8wPtHG-9q5F9vPsCvuD7qUEjp28gM2OHxpQE0agfKWf5cOXMCMXmho75OsU90VQMjpb5UUOtEe76DDaIC9RCw9FACBcVgEGBkXe2PbWeQbaHkJfXxXxcrAjl2F/s1600/dvm.jpg" imageanchor="1" style="clear: left; margin-bottom: 1em; margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhjSywOLUvEMa9bXraXOV8wPtHG-9q5F9vPsCvuD7qUEjp28gM2OHxpQE0agfKWf5cOXMCMXmho75OsU90VQMjpb5UUOtEe76DDaIC9RCw9FACBcVgEGBkXe2PbWeQbaHkJfXxXxcrAjl2F/s1600/dvm.jpg" /></a></td></tr>
<tr><td class="tr-caption" style="font-size: 13px; text-align: center;">On a Win XP Machine</td></tr>
</tbody></table>
On Windows 7 it somehow mixes up the CL Devices and PrimeSensor names, but the drivers still work fine.<br />
<br />
<b>How to make them work together (on Windows):</b><br />
We had to do the triple installation for the OpenNI+Sensor+NITE and the installation for CLNUI Devices could be done either before or after them (we've tried both versions on different machines).<br />
<br />
Once installed, the Kinect will probably have the first driver you installed as its primary driver. So, you'll have to go into the Device Manager and manually change the driver for the Camera to 'Kinect Camera' and the Motor to 'NUI Motor'.<br />
NMhttp://www.blogger.com/profile/03556991654093947404noreply@blogger.com0tag:blogger.com,1999:blog-8410140457122624973.post-46864926549814267532011-10-04T13:27:00.001-05:002011-10-04T13:30:25.920-05:00And now, for something entirely different: Taming the Kinect<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj9uJsVArSB6-103yN883yAFTBBHz9yYjAmdUJmYI5WPxK3Ygzwh7Y8-LEBYlS4k5lQXnnvG8IcC6rWOnoxMqYjGRVpTVEYNVOYQ2CTG5CCdNr0brrFboX-NvDk7OJ0cNZQoinxHwHR_bzJ/s1600/kinect_test.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="334" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj9uJsVArSB6-103yN883yAFTBBHz9yYjAmdUJmYI5WPxK3Ygzwh7Y8-LEBYlS4k5lQXnnvG8IcC6rWOnoxMqYjGRVpTVEYNVOYQ2CTG5CCdNr0brrFboX-NvDk7OJ0cNZQoinxHwHR_bzJ/s640/kinect_test.jpg" width="640" /></a></div>
<br />
<br />
I had started a separate blog for my Kinect-based projects, but somehow it doesn't seem to be as popular. Therefore I've decided to transfer my Kinect related posts to this blog. So, here goes:<br />
<br />
-------------------------------------<br />
<br />
Here I share with you some general information and helpful links to all the Kinect-related open source content and websites I was able to find along the way during my search for the solution for using the Kinect on my computer:<br />
<br />
<b><span class="Apple-style-span" style="font-size: large;">The <a href="http://openkinect.org/wiki/Main_Page">OpenKinect</a> Community</span></b><br />
OpenKinect is a very informative open community for updates and latest information on the current progress on the Kinect libraries and other software being developed by users all over the internet. There is also a lot of useful hardware information for understanding how the Kinect works and about USB devices and protocols in general for anyone interested in finding out more.<br />
<br />
Here are all the open-source and freely available SDK's I came across when I first started searching for ways to use the Kinect with my computer. The pros and cons I've discussed here are based solely on my own experience using the SDK's.<br />
<b><span class="Apple-style-span" style="font-size: large;"><br /></span></b><br />
<b><span class="Apple-style-span" style="font-size: large;">Attempt #1: <a href="http://codelaboratories.com/nui">Code Lab's NUI Platform</a></span></b><br />
<br />
The first result I found when searching for an SDK for the Kinect was the Code Laboratories' NUI Platform. The libraries were developed by AlexP, the first person to have <a href="http://www.ubergizmo.com/2010/11/microsoft-kinect-hacked-already-but-not-for-money/">hacked a Kinect</a> sensor for use with a computer since after its release.<br />
<br />
<b>Pros:</b><br />
<div>
<div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">
<div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">
</div>
<ul>
<li>Pristine C# libraries and sample code. </li>
<li>Using Visual Studio Express, the provided sample code compiled and runs quite easily.</li>
<li><a href="http://codelaboratories.com/forums/viewthread/416/#code">C++ API</a> is also available from the Code Lab website (No samples in C++ though)</li>
<li>Installation and running the sample code was a breeze on Windows 7 (I tried it on a quad core machine running an NVidia GT9800 graphics card).</li>
</ul>
</div>
<div>
<div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">
<b>Cons:</b></div>
</div>
</div>
<div>
<ul>
<li>No samples for C/C++ (I found a <a href="https://github.com/robbeofficial/KinectTouch">sample code</a> by another user on their forum, but I wasn't able to run it). Still, creating a simple code on C++ by just using their API was simple enough once I figured out the flow of control from the C# samples.</li>
<li>There are no skeleton-extraction and /or tracking options on this SDK (yet). One can possibly work out how to use some middle-ware (like the NITE libraries available for use with the OpenNI framework) to accomplish that. But there isn't any support available on the CodeLab website for skeleton detection and tracking (...yet).</li>
<li>Doesn't seem to work on my old Dell laptop (XPS M1210 running WinXP: dual core, NVidia Go7400). The RGB video would show, but it refused to display any depth data. (the laptop does have a USB 2.0, so it's not a USB port issue) I don't believe the problem is caused by any requirements from the Kinect but the limitation might be on the driver/SDK side.</li>
</ul>
<div>
<div>
</div>
Still, overall a very neat and nicely put together SDK without any messy compilations and multiple installs - just install the '<a href="http://codelaboratories.com/nui/">CL NUI Platform Installer</a>' (available on the right-hand-side panel) and you're done. That should install the Drivers & the SDK, along with all the required windows paths to the system, and even add the samples in the installed directory with Visual Studio project solutions ready to be run. </div>
<div>
<br /></div>
<div>
Very neat, indeed!<br />
<br />
<b><span class="Apple-style-span" style="font-size: large;">Attempt #2: <a href="http://openkinect.org/wiki/Getting_Started">Libfreenect</a></span></b><br />
This is the platform actively supported by the <a href="http://openkinect.org/wiki/Main_Page">OpenKinect</a> community. It is constantly being updated and includes a ton of user support on its forums.<br />
<br />
<b>Pros:</b><br />
<br />
<ul>
<li>Cross Platform drivers, SDK and support.</li>
<li><a href="http://openkinect.org/wiki/Main_Page#Wrappers">Wrappers</a> for multiple languages </li>
<li><a href="http://openkinect.org/wiki/Documentation">Documentation</a>, very detailed. </li>
<li>Both High Level and Low Level <a href="http://openkinect.org/wiki/Documentation#Technical_Documentation">APIs</a> available</li>
<li>Compilation instructions for several programming environments, including Visual Studio</li>
</ul>
<div>
<b>Cons:</b></div>
<div>
<ul>
<li>No pre-compiled binaries for the SDK available. You have to compile them separately for the SDK to work for your specific system and programming environment.</li>
<li>Complicated compilation process - several different libraries have to be downloaded from various sources and installed separately from the main code. </li>
<li>No people tracking, gesture/skeleton tracking options. No integration with a middle-ware (such as NITE) available.</li>
</ul>
</div>
<br />
<br />
<br />
<b><span class="Apple-style-span" style="font-size: large;">Attempt #3: <a href="http://www.openni.org/downloadfiles">OpenNI + PrimeSense Sensor + PrimeSense NITE</a></span></b><br />
<br />
This was a set of three different components that had to be installed separately, but they worked together quite nicely to provide the most out of my Kinect experience! The setup comprises of the following three to be installed in order as follows:<br />
<ul>
<li><a href="http://www.openni.org/">OpenNI</a> (Kinect SDK)</li>
<li><a href="http://www.openni.org/downloadfiles/openni-compliant-hardware-binaries/32-stable">PrimeSensor/SensorKinect</a> from PrimeSense (Driver)</li>
<li><a href="http://www.primesense.com/?p=515">NITE</a> from PrimeSense (Middle-ware for skeleton & gesture recognition etc.)</li>
</ul>
<div>
There are some compatibility issues with different versions of these, however the combination of versions on <a href="http://kinect.dashhacks.com/kinect-guides/2011/02/02/beginners-guide-setting-your-microsoft-kinect-windows-pc-hacking">this</a> site (although a little old) worked together perfectly for me.</div>
<div>
</div>
<div>
<br /></div>
<div>
<b>Pros:</b><br />
<ul>
<li>Works great on both computers I tried it on, the Win7 quad-core machine as well as the WinXP dual-core laptop (both mentioned above)!</li>
<li>Cross Platform (Windows & MacOSX support, I wasn't able to find info on Linux usage).</li>
</ul>
OpenNI Installation</div>
<div>
<ul>
<li>Works great when all the right versions are installed in the correct order.</li>
<li>Several different sample provided with source and pre-compiled binaries for doing all sorts of stuff: from getting simple RGB & depth images to detecting people as separate objects and tracking them.</li>
<li><u>Documentation included! (Very detailed too!)</u></li>
</ul>
<div>
NITE Installation</div>
</div>
</div>
</div>
<div>
<ul>
<li>NITE installs separately and provides its own list of amazing samples. Works as the middle-ware for detecting people when using OpenNI.</li>
<li><u>Includes its own Documentation! (Also very detailed)</u></li>
<li>Several samples provided (separate from the ones from OpenNI). Again source and binaries both included. Let's you explore several hand-tracking options. </li>
</ul>
<div>
<br /></div>
<div>
<b>Cons:</b></div>
</div>
<div>
<ul>
<li>Making sure I had all the compatible versions of OpenNI and Primesense was a bit of a pain. </li>
<li>Installs as three parts - as compared to the 1 installation for the CL NUI Devices mentioned above.</li>
<li>No Motor or Audio driver included in the PrimeSense Sensor (not a game-breaker though, it plays well with the CLNUI package to let you control the motor through the CLNUI SDK).</li>
</ul>
<div>
<br /></div>
</div>
<div>
</div>
NMhttp://www.blogger.com/profile/03556991654093947404noreply@blogger.com0tag:blogger.com,1999:blog-8410140457122624973.post-41940050551214677062011-03-16T08:16:00.025-05:002011-05-22T21:58:52.854-05:00Fritzing.org: Create Awesome PCB layouts to document your projectsFrom the <a href="http://fritzing.org/">Fritzing</a> website:<br />
<br />
"We are creating a software and website in the spirit of <a href="http://processing.org/">Processing</a> and <a href="http://arduino.cc/">Arduino</a>, developing a tool that allows users to document their prototypes, sharethem with others, teach electronics in a classroom, and to create a pcb layout for professional manufacturing."<br />
<br />
<iframe allowfullscreen="" frameborder="0" height="390" src="http://www.youtube.com/embed/Hxhd4HKrWpg" width="480"></iframe><br />
<br />
I'll be trying my hands on the Fritzing software next time I work on an Arduino project. Maybe one day I'll even have time to go back and fix my older posts to have better documentation à la Fritzing! :)NMhttp://www.blogger.com/profile/03556991654093947404noreply@blogger.com0tag:blogger.com,1999:blog-8410140457122624973.post-92229223440545980002011-03-16T08:15:00.046-05:002011-05-22T22:17:59.262-05:00Maxbotix XL-EZ2: Ultrasonic Range Finder<div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; text-align: justify;"><span class="Apple-style-span" style="font-family: inherit;">The Ultrasonic Range Finder is a sensor device that measures distance between the sensor and another object. It sends out an ultrasonic sound beam and measures the time taken for it to bounce back off of the closest object in front of it. Then depending on the length of the time interval, it determines the range (distance) to the nearest object in inches. </span></div><div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; text-align: justify;"><span class="Apple-style-span" style="font-family: inherit;">This kind of a sensor can be used in robotics to help navigate unmanned vehicles or in robotics to help them avoid running into walls or other objects. The rangefinder would detect when there is something in front of the vehicle and the vehicle or robot can be programmed to either stop or to try going around the obstacle. The ultrasonic rangefinders can also be used in stationary installations, like machines, appliances or artwork to activate certain switches based on the distance of a person from the sensor.</span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: justify;"><span class="Apple-style-span" style="font-family: inherit;"><br />
</span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: justify;"><span class="Apple-style-span" style="font-family: inherit;"><u><span class="Apple-style-span" style="font-size: large;"><b style="mso-bidi-font-weight: normal;">About the</b><b> </b><b style="mso-bidi-font-weight: normal;">Maxbotix XL-EZ2 Ultrasonic Rangefinder:</b></span></u><span style="background-attachment: initial; background-clip: initial; background-color: black; background-image: initial; background-origin: initial; border-bottom-color: black; border-bottom-style: none; border-bottom-width: 1pt; border-left-color: black; border-left-style: none; border-left-width: 1pt; border-right-color: black; border-right-style: none; border-right-width: 1pt; border-top-color: black; border-top-style: none; border-top-width: 1pt; color: black; padding-bottom: 0in; padding-left: 0in; padding-right: 0in; padding-top: 0in;"> </span><b style="mso-bidi-font-weight: normal;"><o:p></o:p></b></span></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjhUI2Dnqzo5uW0D1zLUzR8B13X4PrB0uo92sneMU9OeIlvGsNWHwXNdBXp-ZEBZj2hq4RfX_5xpx4C8RWts44_00SEcFmxfp6LP8yMm7j6AoOvS7K2TYp5lPUc8g7LU1M4uf7LK58_FQA/s1600/IMG_2693.JPG" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><span class="Apple-style-span" style="font-family: inherit;"><img border="0" height="150" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjhUI2Dnqzo5uW0D1zLUzR8B13X4PrB0uo92sneMU9OeIlvGsNWHwXNdBXp-ZEBZj2hq4RfX_5xpx4C8RWts44_00SEcFmxfp6LP8yMm7j6AoOvS7K2TYp5lPUc8g7LU1M4uf7LK58_FQA/s200/IMG_2693.JPG" width="200" /></span></a></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: justify;"><br />
The MaxSonar XL-EZ2 Ultrasonic Rangefinder by MaxBotix used here gives the user an option of reading in the range either as serial, analog or PWM inputs. The sample codes mentioned here use the analog input method (pin3 on the rangefinder) to read in the ranges. The ranges being read appear to be precise from around 20cm to up to even around five meters. However the closer range values tended to fall into a dead zone on distances less than ~20cm when reading through the rangefinder's analog interface for the code below. <br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgTz3SwdDofMVCW21Ci00hEdM-eCzb0jF-mvQ5ilp1dxg8hGxy8PUauewlRGkbzKQ57qWpuIrv8GYs7JOytoQ8YOw4yA_5vUDYPClecIE8B54W-i8gKmfHHl2Abw-YkfZ8OB4IRL4xK1cE/s1600/IMG_2620.JPG" imageanchor="1" style="clear: right; display: inline !important; float: right; margin-bottom: 1em; margin-left: 1em;"><span class="Apple-style-span" style="font-family: inherit;"><img border="0" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgTz3SwdDofMVCW21Ci00hEdM-eCzb0jF-mvQ5ilp1dxg8hGxy8PUauewlRGkbzKQ57qWpuIrv8GYs7JOytoQ8YOw4yA_5vUDYPClecIE8B54W-i8gKmfHHl2Abw-YkfZ8OB4IRL4xK1cE/s320/IMG_2620.JPG" width="320" /></span></a><br />
<span class="Apple-style-span" style="font-family: inherit;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: inherit;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: inherit;">It is also possible to read the data in PWM or serial format on this module. Separate pins are used for these (pin2 for PWM, pin5 for Serial data). The user can also set the Serial output pin's mode to read either asynchronous Serial data, or simply just a pulse instead. The beam size of the rangefinder also varies depending upon the input voltage. It can be connected to 3.3V to up to 5V to increase total area that the ultrasonic beam covers. The code below can be used with either voltage.</span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0in; text-align: center;"><div style="text-align: left;"><span class="Apple-style-span" style="font-family: inherit;"><br />
</span></div><div style="text-align: left;"><span class="Apple-style-span" style="font-family: inherit;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: inherit;"><br />
</span></div><div style="text-align: left;"><b style="mso-bidi-font-weight: normal;"><u><span class="Apple-style-span" style="font-family: inherit; font-size: large;">Circuit:</span></u></b></div></div><div class="separator" style="clear: both; line-height: normal; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiOSOqKjB1y9HzqrzCTjcFdTOm6vgmz5bzlUS2J2WL-CYWY_hzdiPqgseFiuBPdMPtPfiajTtysygqPeXndpiuqSjv0Mif7iTU2YnkEPcnoFT31FT_5OiXPsp830om5U9mHb1_FPBWTjM4/s1600/IMG_2627.JPG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><span class="Apple-style-span" style="font-family: inherit;"><img border="0" height="300" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiOSOqKjB1y9HzqrzCTjcFdTOm6vgmz5bzlUS2J2WL-CYWY_hzdiPqgseFiuBPdMPtPfiajTtysygqPeXndpiuqSjv0Mif7iTU2YnkEPcnoFT31FT_5OiXPsp830om5U9mHb1_FPBWTjM4/s400/IMG_2627.JPG" width="400" /></span></a><span class="Apple-style-span" style="font-family: inherit; margin-left: 1em; margin-right: 1em;"></span></div><div align="center" class="MsoNormal" style="line-height: normal; text-align: center;"><b><span class="Apple-style-span" style="font-family: inherit;"><br />
</span></b></div><div class="separator" style="clear: both; line-height: normal; text-align: center;"><span class="Apple-style-span" style="clear: left; float: left; font-family: inherit; margin-bottom: 1em; margin-right: 1em;"><span class="Apple-style-span" style="font-family: inherit;"><img border="0" height="300" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjPCG2Noq267N_Yo1dnXUlsh0mfWWCLdm_DtUvKloakR-CzzCLKndUKxk9lGVBqBmkhBIq5XHk3U8LArRwT6bbnfSvdtQw_DnkxxUi_USm7tbgTiUpFHizvAJegN4WObA4kkjjiZ8OhDS0/s400/IMG_2621.JPG" width="400" /></span></span></div><div class="separator" style="clear: both; line-height: normal; text-align: center;"><span class="Apple-style-span" style="font-family: inherit;"><br />
</span></div><div class="separator" style="clear: both; line-height: normal; text-align: left;"></div><div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; tab-stops: 167.25pt;"><b style="mso-bidi-font-weight: normal;"><u><span class="Apple-style-span" style="font-family: inherit;"><br />
</span></u></b><br />
<span class="Apple-style-span" style="font-family: inherit;"><b style="mso-bidi-font-weight: normal;"><u><span class="Apple-style-span" style="font-size: large;">Schematic:</span></u></b><b style="mso-bidi-font-weight: normal;"><u><o:p></o:p></u></b></span></div><div class="separator" style="clear: both; text-align: center;"><span class="Apple-style-span" style="clear: left; float: left; font-family: inherit; margin-bottom: 1em; margin-right: 1em;"><span class="Apple-style-span" style="font-family: inherit;"><img border="0" height="361" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi1Y2dt8JsNLBen8HEVQqBHJPpRf0knOdX2udQsGCyHnMCOCQkwiANnwgjWc8JbPA57VZFWNbaGVBtu91CLdBUexnAnSRhR7t_x6cKA_8ugehusdZ24gwz7nl0IBs3we8LtyiKkEQ1kXBs/s400/schematic_Rangefinder.png" width="400" /></span></span></div><div class="separator" style="clear: both; text-align: left;"></div><div class="MsoNormal" style="display: inline !important; font-weight: bold; line-height: normal; text-decoration: underline;"><div style="display: inline !important;"><b style="mso-bidi-font-weight: normal;"><u><span class="Apple-style-span" style="font-family: inherit;">Sample Arduino Program:</span></u></b></div></div>This code simply takes the input from the rangefinder's analog pin and checks it against a threshold to light up an LED if an object is too close.<span class="Apple-style-span"> </span><br />
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt; margin-left: 0in; margin-right: 0in; margin-top: 12pt;"><span class="Apple-style-span" style="font-family: inherit;"> </span></div><table border="1" cellpadding="0" cellspacing="0" class="MsoNormalTable" style="background: #F2F2F2; border-collapse: collapse; border: none; mso-border-alt: solid #BFBFBF .5pt; mso-border-insideh: .5pt solid #BFBFBF; mso-border-insidev: .5pt solid #BFBFBF; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-pattern: solid #F2F2F2; mso-shading: windowtext; mso-yfti-tbllook: 1184;"><tbody>
<tr style="mso-yfti-firstrow: yes; mso-yfti-irow: 0; mso-yfti-lastrow: yes;"> <td style="border: solid #BFBFBF 1.0pt; mso-border-alt: solid #BFBFBF .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 6.65in;" valign="top" width="638"><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-family: 'Courier New', Courier, monospace; font-size: x-small;">/* <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-family: 'Courier New', Courier, monospace; font-size: x-small;">This code takes in the input from the rangefinder's analog pin. <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-family: 'Courier New', Courier, monospace; font-size: x-small;">The pin returns distance (in inches) from the sensor to the <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-family: 'Courier New', Courier, monospace; font-size: x-small;">closest object in front of it. If an object is closer than the <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-family: 'Courier New', Courier, monospace; font-size: x-small;">threshold distance, the LED lights up.<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace; font-size: x-small;"><br />
</span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-family: 'Courier New', Courier, monospace; font-size: x-small;">Setup:<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-family: 'Courier New', Courier, monospace; font-size: x-small;">Connect the analog pin (3/AX) of the rangefinder to the Arduino <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-family: 'Courier New', Courier, monospace; font-size: x-small;">Board's Analog input pin0. Connect the ground and v++ on the <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-family: 'Courier New', Courier, monospace; font-size: x-small;">rangefinder to a GND and 5V on the Arduino respectively. Connect <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-family: 'Courier New', Courier, monospace; font-size: x-small;">the LED to pin13 and GND.<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace; font-size: x-small;"><br />
</span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-family: 'Courier New', Courier, monospace; font-size: x-small;">By Naureen Mahmood<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace; font-size: x-small;"><br />
</span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-family: 'Courier New', Courier, monospace; font-size: x-small;">*/<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace; font-size: x-small;"><br />
</span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-family: 'Courier New', Courier, monospace; font-size: x-small;">#define THRESHOLD 30 // threshold distance in inches<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-family: 'Courier New', Courier, monospace; font-size: x-small;">#define LED_PIN 13 // LED output pin<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-family: 'Courier New', Courier, monospace; font-size: x-small;">#define RF_PIN 0 // Range Finder input pin<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace; font-size: x-small;"><br />
</span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-family: 'Courier New', Courier, monospace; font-size: x-small;">void setup()<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-family: 'Courier New', Courier, monospace; font-size: x-small;">{<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-family: 'Courier New', Courier, monospace; font-size: x-small;"> Serial.begin(9600);<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-family: 'Courier New', Courier, monospace; font-size: x-small;"> pinMode(RF_PIN, INPUT); <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-family: 'Courier New', Courier, monospace; font-size: x-small;"> pinMode(LED_PIN, OUTPUT); <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-family: 'Courier New', Courier, monospace; font-size: x-small;">}<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace; font-size: x-small;"><br />
</span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-family: 'Courier New', Courier, monospace; font-size: x-small;">void loop() <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-family: 'Courier New', Courier, monospace; font-size: x-small;">{<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-family: 'Courier New', Courier, monospace; font-size: x-small;"> // Read distance on Rangefinder's analog pin<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-family: 'Courier New', Courier, monospace; font-size: x-small;"> int distance = analogRead(RF_PIN);<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-family: 'Courier New', Courier, monospace; font-size: x-small;"> Serial.println(distance); // Print measured distance<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-family: 'Courier New', Courier, monospace; font-size: x-small;"> <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-family: 'Courier New', Courier, monospace; font-size: x-small;"> // if an object is closer than threshold distance, turn on LED<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-family: 'Courier New', Courier, monospace; font-size: x-small;"> if (distance < THRESHOLD)<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-family: 'Courier New', Courier, monospace; font-size: x-small;"> digitalWrite(LED_PIN, HIGH);<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-family: 'Courier New', Courier, monospace; font-size: x-small;"> else <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-family: 'Courier New', Courier, monospace; font-size: x-small;"> digitalWrite(LED_PIN, LOW);<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-family: 'Courier New', Courier, monospace; font-size: x-small;">}</span><b style="font-family: inherit;"><o:p></o:p></b></div></td> </tr>
</tbody></table><span class="Apple-style-span" style="font-family: inherit;"><br />
</span><br />
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt; text-decoration: underline;"><span class="Apple-style-span" style="font-family: inherit; font-weight: 800;"><br />
</span></div><div class="MsoNormal" style="font-weight: bold; line-height: normal; text-decoration: underline;"><b style="mso-bidi-font-weight: normal;"><u><span class="Apple-style-span" style="font-family: inherit;"><span class="Apple-style-span" style="font-size: large;">Sample Arduino Program (with averaged values to avoid jitters):</span><o:p></o:p></span></u></b></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span class="Apple-style-span" style="font-family: inherit;">In this code, to avoid jitters, we take an average of 50 input samples before printing out the measured distance. If the measured distance is less than 30 inches, the LED on pin 13 is turned on.</span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;"><u><span class="Apple-style-span" style="font-family: inherit;"><br />
</span></u></div><table border="1" cellpadding="0" cellspacing="0" class="MsoNormalTable" style="background: #F2F2F2; border-collapse: collapse; border: none; mso-border-alt: solid #BFBFBF .5pt; mso-border-insideh: .5pt solid #BFBFBF; mso-border-insidev: .5pt solid #BFBFBF; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-pattern: solid #F2F2F2; mso-shading: windowtext; mso-yfti-tbllook: 1184;"><tbody>
<tr style="mso-yfti-firstrow: yes; mso-yfti-irow: 0; mso-yfti-lastrow: yes;"> <td style="border: solid #BFBFBF 1.0pt; mso-border-alt: solid #BFBFBF .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 6.65in;" valign="top" width="638"><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-family: 'Courier New', Courier, monospace; font-size: x-small;">/* <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace; font-size: x-small;"><br />
</span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-family: 'Courier New', Courier, monospace; font-size: x-small;">This code takes in the input from the rangefinder's analog pin. The pin <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-family: 'Courier New', Courier, monospace; font-size: x-small;">returns distance (in inches) from the sensor to the closest object in <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-family: 'Courier New', Courier, monospace; font-size: x-small;">front of it. To avoid jitters, we take an average of 50 input samples <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-family: 'Courier New', Courier, monospace; font-size: x-small;">before printing out the measured distance. If the measured distance is <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-family: 'Courier New', Courier, monospace; font-size: x-small;">less than 30 inches, the LED on pin 13 is turned on.<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace; font-size: x-small;"><br />
</span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-family: 'Courier New', Courier, monospace; font-size: x-small;">To avoid jitters, we take an average of 50 input samples <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-family: 'Courier New', Courier, monospace; font-size: x-small;">before printing out the measured distance. If the measured distance is <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-family: 'Courier New', Courier, monospace; font-size: x-small;">less than 30 inches, the LED on pin 13 is turned on.<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace; font-size: x-small;"><br />
</span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-family: 'Courier New', Courier, monospace; font-size: x-small;">Setup:<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-family: 'Courier New', Courier, monospace; font-size: x-small;">Connect the analog pin (AX/pin3) of the rangefinder to the Arduino <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-family: 'Courier New', Courier, monospace; font-size: x-small;">Board's Analog input pin0. Connect the ground and v++ on the <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-family: 'Courier New', Courier, monospace; font-size: x-small;">rangefinder to a GND and 5V on the Arduino respectively. <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace; font-size: x-small;"><br />
</span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-family: 'Courier New', Courier, monospace; font-size: x-small;">By Naureen Mahmood<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace; font-size: x-small;"><br />
</span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-family: 'Courier New', Courier, monospace; font-size: x-small;">*/<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace; font-size: x-small;"><br />
</span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-family: 'Courier New', Courier, monospace; font-size: x-small;">#define THRESHOLD 40 // threshold distance in inches<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-family: 'Courier New', Courier, monospace; font-size: x-small;">#define LED_PIN 13 // LED output pin<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-family: 'Courier New', Courier, monospace; font-size: x-small;">#define RF_PIN 0 // Range Finder input pin<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace; font-size: x-small;"><br />
</span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-family: 'Courier New', Courier, monospace; font-size: x-small;">int sampleSize = 50; // n readings 0 .. (n - 1)<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-family: 'Courier New', Courier, monospace; font-size: x-small;">int sampleCount = 0; // to count how many samples taken so far<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-family: 'Courier New', Courier, monospace; font-size: x-small;">int distance = 0;<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace; font-size: x-small;"><br />
</span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-family: 'Courier New', Courier, monospace; font-size: x-small;">void setup()<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-family: 'Courier New', Courier, monospace; font-size: x-small;">{<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-family: 'Courier New', Courier, monospace; font-size: x-small;"> Serial.begin(9600);<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-family: 'Courier New', Courier, monospace; font-size: x-small;"> pinMode(RF_PIN, INPUT); <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-family: 'Courier New', Courier, monospace; font-size: x-small;"> pinMode(LED_PIN, OUTPUT); <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-family: 'Courier New', Courier, monospace; font-size: x-small;">}<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace; font-size: x-small;"><br />
</span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-family: 'Courier New', Courier, monospace; font-size: x-small;">void loop() <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-family: 'Courier New', Courier, monospace; font-size: x-small;">{<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-family: 'Courier New', Courier, monospace; font-size: x-small;"> // sampleCount starts life at 0, then loops through sampleSize<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-family: 'Courier New', Courier, monospace; font-size: x-small;"> // at each iteration of this main loop<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-family: 'Courier New', Courier, monospace; font-size: x-small;"> <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-family: 'Courier New', Courier, monospace; font-size: x-small;"> int avgDist;<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace; font-size: x-small;"><br />
</span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-family: 'Courier New', Courier, monospace; font-size: x-small;"> distance += analogRead(RF_PIN);<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-family: 'Courier New', Courier, monospace; font-size: x-small;"> sampleCount++;<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-family: 'Courier New', Courier, monospace; font-size: x-small;"> if (sampleCount == sampleSize) <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-family: 'Courier New', Courier, monospace; font-size: x-small;"> {<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-family: 'Courier New', Courier, monospace; font-size: x-small;"> avgDist = distance/sampleSize;<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-family: 'Courier New', Courier, monospace; font-size: x-small;"> Serial.println(avgDist); //Print average of all measured values<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-family: 'Courier New', Courier, monospace; font-size: x-small;"> sampleCount=0; <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-family: 'Courier New', Courier, monospace; font-size: x-small;"> distance = 0;<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-family: 'Courier New', Courier, monospace; font-size: x-small;"> }<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-family: 'Courier New', Courier, monospace; font-size: x-small;"> <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-family: 'Courier New', Courier, monospace; font-size: x-small;"> // if an object is closer than threshold distance, turn on the LED<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-family: 'Courier New', Courier, monospace; font-size: x-small;"> if (avgDist < THRESHOLD)<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-family: 'Courier New', Courier, monospace; font-size: x-small;"> digitalWrite(LED_PIN, HIGH);<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-family: 'Courier New', Courier, monospace; font-size: x-small;"> else <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-family: 'Courier New', Courier, monospace; font-size: x-small;"> digitalWrite(LED_PIN, LOW);<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace; font-size: x-small;"><span class="Apple-style-span" style="color: #666666;">}</span><o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;"><span class="Apple-style-span" style="font-family: inherit;"><br />
</span></div></td> </tr>
</tbody></table>NMhttp://www.blogger.com/profile/03556991654093947404noreply@blogger.com3tag:blogger.com,1999:blog-8410140457122624973.post-22656495296593243302011-03-16T08:14:00.011-05:002011-05-22T21:44:43.805-05:00DIY Touch Sensor (Capacitive Sensor)<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;"><span class="Apple-style-span" style="font-family: inherit;">Capacitive Sensors is a technology which detects proximity or touch (by a hand/skin, or any conductive object). The sensor measures the capacitance between the input and output nodes to detect a touch. The sensor detects anything that is conductive, so these sensors can be used to replace any normal switches to make them touch sensitive or even be utilized in making touch screens for monitors, touch-pads and touch sensitive buttons in phones, laptops or other devices. </span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;"><span class="Apple-style-span" style="font-family: inherit;"><br />
</span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;"><b style="mso-bidi-font-weight: normal;"><span class="Apple-style-span" style="font-family: inherit;">About the Touch Sensor:<o:p></o:p></span></b></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;"><span class="Apple-style-span" style="font-family: inherit;">The sensor setup in the example below is a simple DIY setup without using a commercial sensor chip. <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;"><span class="Apple-style-span" style="font-family: inherit;"><br />
</span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;"><b style="mso-bidi-font-weight: normal;"><i style="mso-bidi-font-style: normal;"><span class="Apple-style-span" style="font-family: inherit;">Setup:<o:p></o:p></span></i></b></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: justify;"><span class="Apple-style-span" style="font-family: inherit;">Attach a high value resistor (1-10M Ohm) between an input and an output pin. Also connect a short bare copper or aluminum wire/foil to the input pin. If the wire is to be a longer one, make sure it isn't touching any other wires along the way, or just use a covered wire with a small uncovered area at its tip. This will be the touch sensor for the capacitive sensor (i.e. activates at touch).<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: justify;"><span class="Apple-style-span" style="font-family: inherit;"><br />
</span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: justify;"><span class="Apple-style-span" style="font-family: inherit;">An LED is also connected to a separate output pin and GND. This LED turns on when someone touches the sensor with a conductive object (e.g. capacitive sensors are most commonly used to sense touch with skin/fingers etc.) <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: justify;"><span class="Apple-style-span" style="font-family: inherit;"><br />
</span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: justify;"><span class="Apple-style-span" style="font-family: inherit;">It is also possible to vary the capacitance reading of this setup to detect even when one's hand is 3 to 4 inches from the sensor, or make it activate just on absolute touch. One can use lower values of R (e.g. 1 M Ohm or less) for absolute touch to activate the sensor. With a 10 M resistor the sensor should start to respond 1-2 inches away. <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;"><span class="Apple-style-span" style="font-family: inherit;"><br />
</span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;"><b style="mso-bidi-font-weight: normal;"><i style="mso-bidi-font-style: normal;"><span class="Apple-style-span" style="font-family: inherit;">Code:<o:p></o:p></span></i></b></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: justify;"><span class="Apple-style-span" style="font-family: inherit;">When the value at the output pin is changed from LOW to HIGH, it changes the state of input pin to LOW(or 0) for a very short time interval. This time interval is defined by:<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: justify;"><span class="Apple-style-span" style="font-family: inherit;"><br />
</span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: justify;"><i style="mso-bidi-font-style: normal;"><span class="Apple-style-span" style="font-family: inherit;">T = R x C, <o:p></o:p></span></i></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: justify;"><span class="Apple-style-span" style="font-family: inherit;"><br />
</span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: justify;"><span class="Apple-style-span" style="font-family: inherit;">where<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: justify;"><i style="mso-bidi-font-style: normal;"><span class="Apple-style-span" style="font-family: inherit;">T = time interval, <o:p></o:p></span></i></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: justify;"><i style="mso-bidi-font-style: normal;"><span class="Apple-style-span" style="font-family: inherit;">R = resistance, <o:p></o:p></span></i></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: justify;"><i style="mso-bidi-font-style: normal;"><span class="Apple-style-span" style="font-family: inherit;">C = capacitance of the sensor + capacitance of any conductive object in contact with the sensor pin<o:p></o:p></span></i></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: justify;"><span class="Apple-style-span" style="font-family: inherit;"><br />
</span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: justify;"><span class="Apple-style-span" style="font-family: inherit;">So, this time interval increases if the sensor on input pin (the bare copper/aluminum wire) is touched with a conductive object. And the interval reduces again when the conductive <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: justify;"><span class="Apple-style-span" style="font-family: inherit;">object is removed from the sensor. So, we measure the length of the time interval to get a measure of capacitance on the touch sensor.<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;"><span class="Apple-style-span" style="font-family: inherit;"><br />
</span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;"><b style="mso-bidi-font-weight: normal;"><i style="mso-bidi-font-style: normal;"><span class="Apple-style-span" style="font-family: inherit;">Threshold:<o:p></o:p></span></i></b></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: justify;"><span class="Apple-style-span" style="font-family: inherit;">The value of the threshold here depends on how sensitive the user wants the sensor to be. The lower bound of the threshold would be the value of <i style="mso-bidi-font-style: normal;">R </i>(the resistance) itself, since that remains constant in when measuring <i style="mso-bidi-font-style: normal;">T = R x C. </i>But, the upper bound can be changed depending on the requirements of the system. <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;"><span class="Apple-style-span" style="font-family: inherit;"><br />
</span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;"><b style="mso-bidi-font-weight: normal;"><i style="mso-bidi-font-style: normal;"><span class="Apple-style-span" style="font-family: inherit;">Smoothing:<o:p></o:p></span></i></b></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: justify;"><span class="Apple-style-span" style="font-family: inherit;">However, there might be a lot of jitter as well as environmental conditions that might make the <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: justify;"><span class="Apple-style-span" style="font-family: inherit;">capacitance value jump around a lot. This can be overcome by using a smoothing function. For example, this can be done by reading the capacitance measure for a number of times and then averaging the values overall. <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;"><span class="Apple-style-span" style="font-family: inherit;"><br />
</span></div><div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"><span class="Apple-style-span" style="font-family: inherit;"><b style="mso-bidi-font-weight: normal;"><u>Circuit:</u></b><b style="mso-bidi-font-weight: normal;"><u> <o:p></o:p></u></b></span></div><div class="separator" style="clear: both; text-align: center;"></div><div class="separator" style="clear: both; text-align: center;"><span class="Apple-style-span" style="clear: left; float: left; font-family: inherit; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="299" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiaNnUvyVqjkwtjuMR9XbKXGroTJU1Iyjq0RRmZi28KPsir3yktSjyYUOfvlQY5SZLsgiwgrB-zBUjogMvGFf66weBxR45OOLQiYC7jOdh3gGDb52fAW-O7g806ZWZEps8_QRYmEhwHmLs/s400/circuit.png" width="400" /></span></div><div class="separator" style="clear: both; text-align: center;"><span class="Apple-style-span" style="font-family: inherit;"><br />
</span></div><div align="center" class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; text-align: center;"><div style="text-align: left;"><b style="mso-bidi-font-weight: normal;"><u><span class="Apple-style-span" style="font-family: inherit;">Schematic:</span></u></b></div></div><div class="separator" style="clear: both; text-align: center;"><span class="Apple-style-span" style="clear: left; float: left; font-family: inherit; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="378" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgJ1z8lOr8eZI3fGtn8K5sURDDoOx2gx85O6aQW-OBo51j0tXJquWrBajyVBmK3iRPVDqYnW5Sie8e2BiLq5WufCW4y2UhnxN113uCJpCZLQlctg60lJvzNw4lkf30f-FfEtOTi6jQzaD4/s400/schematic.png" width="400" /></span></div><div class="separator" style="clear: both; text-align: left;"><b style="mso-bidi-font-weight: normal;"><u><span class="Apple-style-span" style="font-family: inherit;">Sample Arduino Program:</span></u></b></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;"><b style="mso-bidi-font-weight: normal;"><i style="mso-bidi-font-style: normal;"><span class="Apple-style-span" style="font-family: inherit;">About this Code:<o:p></o:p></span></i></b></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: justify;"><span class="Apple-style-span" style="font-family: inherit;">When the output at pin4 transitions from LOW to HIGH, it changes the state of input pin5 to LOW(or 0) for a very short time interval. This time interval increases if the sensor on input pin5 is touched with a conductive object and vice versa.<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: justify;"><span class="Apple-style-span" style="font-family: inherit;"><br />
</span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: justify;"><span class="Apple-style-span" style="font-family: inherit;">At the start of each main loop cycle in this program, we set the value of a variable 'capX' to 0. Then for the time interval the value at input pin5 returns LOW, we increment 'capX'. This results in 'capX' being barely incremented if the sensor is not in contact with a conductive object. But, as soon as someone holds/touches the sensor the value of capX quickly increments because of the longer time interval. So, if the capX value is bigger than a given threshold, it means the sensor just detected a touch.<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: justify;"><span class="Apple-style-span" style="font-family: inherit;"><br />
</span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: justify;"><span class="Apple-style-span" style="font-family: inherit;">The value of the threshold here depends on how sensitive the user wants the sensor to be and/or the environmental affect the initial value at the sensor itself.</span><o:p></o:p></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;"><br />
</div><table border="1" cellpadding="0" cellspacing="0" class="MsoNormalTable" style="background: #F2F2F2; border-collapse: collapse; border: none; mso-border-alt: solid black .5pt; mso-border-insideh: .5pt solid black; mso-border-insidev: .5pt solid black; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-pattern: solid #F2F2F2; mso-shading: windowtext; mso-yfti-tbllook: 1184;"><tbody>
<tr style="mso-yfti-firstrow: yes; mso-yfti-irow: 0; mso-yfti-lastrow: yes;"> <td style="border: solid black 1.0pt; mso-border-alt: solid black .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 6.65in;" valign="top" width="638"><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="color: #666666; font-family: 'Courier New'; font-size: x-small;">/* <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-size: x-small;"><br />
</span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="color: #666666; font-family: 'Courier New'; font-size: x-small;">This code turns the LED on while the sensor is in contact <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="color: #666666; font-family: 'Courier New'; font-size: x-small;">with a conductive material (e.g. when someone touches it <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="color: #666666; font-family: 'Courier New'; font-size: x-small;">with their bare skin/fingers)<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-size: x-small;"><br />
</span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="color: #666666; font-family: 'Courier New'; font-size: x-small;">Setup:<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="color: #666666; font-family: 'Courier New'; font-size: x-small;">Attach a high value resistor (1-10M Ohm) between an output <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="color: #666666; font-family: 'Courier New'; font-size: x-small;">pin 4 and input pin 5. Also connect a short bare copper or <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="color: #666666; font-family: 'Courier New'; font-size: x-small;">aluminum wire/foil to the input pin5. Connect an LED to <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="color: #666666; font-family: 'Courier New'; font-size: x-small;">output pin13 and GND.<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-size: x-small;"><br />
</span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="color: #666666; font-family: 'Courier New'; font-size: x-small;">By: Naureen Mahmood.<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-size: x-small;"><br />
</span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="color: #666666; font-family: 'Courier New'; font-size: x-small;">*/<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-size: x-small;"><br />
</span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="color: #666666; font-family: 'Courier New'; font-size: x-small;">#define LED 13<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="color: #666666; font-family: 'Courier New'; font-size: x-small;">#define THRESHOLD 5<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-size: x-small;"><br />
</span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="color: #666666; font-family: 'Courier New'; font-size: x-small;">int capI; // interval when sensor pin 5 returns LOW<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-size: x-small;"><br />
</span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="color: #666666; font-family: 'Courier New'; font-size: x-small;">void setup() <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="color: #666666; font-family: 'Courier New'; font-size: x-small;">{<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="color: #666666; font-family: 'Courier New'; font-size: x-small;"> Serial.begin(9600);<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="color: #666666; font-family: 'Courier New'; font-size: x-small;"> pinMode(LED, OUTPUT);<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="color: #666666; font-family: 'Courier New'; font-size: x-small;"> pinMode(4, OUTPUT); // output pin<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="color: #666666; font-family: 'Courier New'; font-size: x-small;"> pinMode(5, INPUT); // input pin<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="color: #666666; font-family: 'Courier New'; font-size: x-small;">}<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-size: x-small;"><br />
</span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="color: #666666; font-family: 'Courier New'; font-size: x-small;">void loop() <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="color: #666666; font-family: 'Courier New'; font-size: x-small;">{<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="color: #666666; font-family: 'Courier New'; font-size: x-small;"> capI = 0; // clear out capacitance measure at each loop <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-size: x-small;"><br />
</span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="color: #666666; font-family: 'Courier New'; font-size: x-small;"> // transition output pin4 LOW-to-HIGH to 'activate' sensor pin5<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="color: #666666; font-family: 'Courier New'; font-size: x-small;"> digitalWrite(4, HIGH); <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-size: x-small;"><br />
</span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="color: #666666; font-family: 'Courier New'; font-size: x-small;"> // On activation, value of pin 5 stays LOW for a time interval T = R*C. <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="color: #666666; font-family: 'Courier New'; font-size: x-small;"> // C is big if the sensor is touched with a conductive object.<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="color: #666666; font-family: 'Courier New'; font-size: x-small;"> // Increment capI for the interval while pin5 is LOW<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="color: #666666; font-family: 'Courier New'; font-size: x-small;"> int val = digitalRead(5); // read the input to be checked<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="color: #666666; font-family: 'Courier New'; font-size: x-small;"> while (val != HIGH){ <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="color: #666666; font-family: 'Courier New'; font-size: x-small;"> capI++; <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="color: #666666; font-family: 'Courier New'; font-size: x-small;"> val = digitalRead(5); // re-read the input to be checked <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="color: #666666; font-family: 'Courier New'; font-size: x-small;"> }<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="color: #666666; font-family: 'Courier New'; font-size: x-small;"> delay(1);<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="color: #666666; font-family: 'Courier New'; font-size: x-small;"> <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="color: #666666; font-family: 'Courier New'; font-size: x-small;"> // transition output pin4 HIGH-to-LOW to 'deactivate' sensor pin5<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="color: #666666; font-family: 'Courier New'; font-size: x-small;"> digitalWrite(4, LOW); <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="color: #666666; font-family: 'Courier New'; font-size: x-small;"> Serial.println(capI, DEC); // print out interval <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-size: x-small;"><br />
</span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="color: #666666; font-family: 'Courier New'; font-size: x-small;"> if (capI > THRESHOLD) // Turn LED on if capI is above threshold<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="color: #666666; font-family: 'Courier New'; font-size: x-small;"> digitalWrite(LED, HIGH);<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="color: #666666; font-family: 'Courier New'; font-size: x-small;"> else <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="color: #666666; font-family: 'Courier New'; font-size: x-small;"> digitalWrite(LED, LOW);<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="font-family: 'Courier New'; font-size: x-small;"><span class="Apple-style-span" style="color: #666666;">}</span><o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;"><br />
</div></td> </tr>
</tbody></table><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;"><br />
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;"><b style="mso-bidi-font-weight: normal;"><u><span style="font-family: inherit;">Sample Arduino Code (with smoothing filter):<o:p></o:p></span></u></b></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;"><span class="Apple-style-span" style="font-family: inherit;"><br />
</span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;"><b style="mso-bidi-font-weight: normal;"><i style="mso-bidi-font-style: normal;"><span style="font-family: inherit;">About this Code:<o:p></o:p></span></i></b></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: justify;"><span style="font-family: inherit;"> This code uses the same technique for measuring capacitance as the earlier one. But, this one also uses a smoothing filter to remove any jitter along the measured values by averaging 4 consecutive values from the input pin. Then at each iteration of that 4-time loop, after transitioning the output pin 4 from low to hi, we measure the duration for which the value at input pin 5 remains low (and save it in variable <b style="mso-bidi-font-weight: normal;">capLo</b>). Then we transition the output pin 4 back to low, and measure the duration for which the input pin 5 is high (and save it in variable <b style="mso-bidi-font-weight: normal;">capHi</b>). We won't be using the capHi variable for the filter but, this helps read out any noise at the input pin before the next iteration. <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: justify;"><span class="Apple-style-span" style="font-family: inherit;"><br />
</span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: justify;"><span style="font-family: inherit;">After this loop, the smoothing filter is applied to the measured <b style="mso-bidi-font-weight: normal;">capLo</b> value. We use the current <b style="mso-bidi-font-weight: normal;">capLo</b> value and previous filtered value, called <b style="mso-bidi-font-weight: normal;">prevCapI</b>, from the last iteration of the loop function (not the for-loop), and multiply them by <b style="mso-bidi-font-weight: normal;">f_val</b> and <b style="mso-bidi-font-weight: normal;">(1 - f_val)</b> respectively. Here <b style="mso-bidi-font-weight: normal;">f_val</b> is the amount of filtering to be applied to the measured capacitance values. This value can be between 1 (no filter) and 0.001 (max filter). This makes sure both the current and previous values of the measured capacitance are included in the final filtered value, and the value f_val determines what proportion of each is to be included in the final value. Therefore, even the sudden changes in the capacitance are smoothed out based on previous input.<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: justify;"><span class="Apple-style-span" style="font-family: inherit;"><br />
</span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: justify;"><span class="Apple-style-span" style="font-family: inherit;">So, then the LED brightens or dims smoothly based on these filtered values from the touch sensor.</span><o:p></o:p></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;"><br />
</div><table border="1" cellpadding="0" cellspacing="0" class="MsoNormalTable" style="background: #F2F2F2; border-collapse: collapse; border: none; mso-border-alt: solid black .5pt; mso-border-insideh: .5pt solid black; mso-border-insidev: .5pt solid black; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-pattern: solid #F2F2F2; mso-shading: windowtext; mso-yfti-tbllook: 1184;"><tbody>
<tr style="mso-yfti-firstrow: yes; mso-yfti-irow: 0; mso-yfti-lastrow: yes;"> <td style="border: solid black 1.0pt; mso-border-alt: solid black .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 6.65in;" valign="top" width="638"><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="color: #666666; font-size: x-small;"><span style="font-family: 'Courier New';">/* </span><span style="font-family: 'Courier New';"><o:p></o:p></span></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="font-size: x-small;"><br />
</span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="font-family: 'Courier New';"><span class="Apple-style-span" style="color: #666666; font-size: x-small;"> This code makes the LED intensity go from dim to bright <o:p></o:p></span></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="font-family: 'Courier New';"><span class="Apple-style-span" style="color: #666666; font-size: x-small;"> smoothly when someone touches the sensor with a bare <o:p></o:p></span></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="font-family: 'Courier New';"><span class="Apple-style-span" style="color: #666666; font-size: x-small;"> finger, and then smoothly dims down to turn off after <o:p></o:p></span></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="font-family: 'Courier New';"><span class="Apple-style-span" style="color: #666666; font-size: x-small;"> the person lets go of the sensor.<o:p></o:p></span></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="font-size: x-small;"><br />
</span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="font-family: 'Courier New';"><span class="Apple-style-span" style="color: #666666; font-size: x-small;"> Setup:<o:p></o:p></span></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="font-family: 'Courier New';"><span class="Apple-style-span" style="color: #666666; font-size: x-small;"> Attach a high value resistor (1-10M Ohm) between output <o:p></o:p></span></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="font-family: 'Courier New';"><span class="Apple-style-span" style="color: #666666; font-size: x-small;"> pin 4 and input pin 5. Also connect a short bare copper or <o:p></o:p></span></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="font-family: 'Courier New';"><span class="Apple-style-span" style="color: #666666; font-size: x-small;"> aluminum wire/foil to the input pin5. Connect an LED to <o:p></o:p></span></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="font-family: 'Courier New';"><span class="Apple-style-span" style="color: #666666; font-size: x-small;"> output pin 11 (or any PWM pin) and GND.<o:p></o:p></span></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="font-size: x-small;"><br />
</span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="font-family: 'Courier New';"><span class="Apple-style-span" style="color: #666666; font-size: x-small;"> [ Smoothing filter based on code by Paul Badger found at:<o:p></o:p></span></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="font-family: 'Courier New';"><span class="Apple-style-span" style="color: #666666; font-size: x-small;"> http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1171076259 ]<o:p></o:p></span></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="font-size: x-small;"><br />
</span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="font-family: 'Courier New';"><span class="Apple-style-span" style="color: #666666; font-size: x-small;"> By: Naureen Mahmood<o:p></o:p></span></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="font-family: 'Courier New';"><span class="Apple-style-span" style="color: #666666; font-size: x-small;"> */<o:p></o:p></span></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="font-size: x-small;"><br />
</span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="font-family: 'Courier New';"><span class="Apple-style-span" style="color: #666666; font-size: x-small;">// You can change the bounding values for the capacitive/touch<o:p></o:p></span></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="font-family: 'Courier New';"><span class="Apple-style-span" style="color: #666666; font-size: x-small;">// sensor depending on what values work best for your setup<o:p></o:p></span></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="font-family: 'Courier New';"><span class="Apple-style-span" style="color: #666666; font-size: x-small;">// + environmental factors<o:p></o:p></span></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="font-family: 'Courier New';"><span class="Apple-style-span" style="color: #666666; font-size: x-small;">#define LOW_T 10 // lower bound for touch sensor<o:p></o:p></span></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="font-family: 'Courier New';"><span class="Apple-style-span" style="color: #666666; font-size: x-small;">#define HIGH_T 60 // upper bound for touch sensor<o:p></o:p></span></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="font-family: 'Courier New';"><span class="Apple-style-span" style="color: #666666; font-size: x-small;">#define LED 11 // LED output pin<o:p></o:p></span></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="font-size: x-small;"><br />
</span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="font-family: 'Courier New';"><span class="Apple-style-span" style="color: #666666; font-size: x-small;">// These are variables for the low-pass (smoothing) filter.<o:p></o:p></span></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="font-family: 'Courier New';"><span class="Apple-style-span" style="color: #666666; font-size: x-small;">float prev_capI; // previous capacitance interval<o:p></o:p></span></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="font-family: 'Courier New';"><span class="Apple-style-span" style="color: #666666; font-size: x-small;">float filt_capI; // filtered capacitance interval<o:p></o:p></span></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="font-family: 'Courier New';"><span class="Apple-style-span" style="color: #666666; font-size: x-small;">float f_val = .07; // 1 = no filter, 0.001 = max filter<o:p></o:p></span></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="font-family: 'Courier New';"><span class="Apple-style-span" style="color: #666666; font-size: x-small;">unsigned int capLo; // duration when sensor reads LOW<o:p></o:p></span></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="font-family: 'Courier New';"><span class="Apple-style-span" style="color: #666666; font-size: x-small;">unsigned int capHi; // duration when sensor reads HIGH<o:p></o:p></span></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="font-size: x-small;"><br />
</span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="font-family: 'Courier New';"><span class="Apple-style-span" style="color: #666666; font-size: x-small;">void setup() <o:p></o:p></span></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="font-family: 'Courier New';"><span class="Apple-style-span" style="color: #666666; font-size: x-small;">{<o:p></o:p></span></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="font-family: 'Courier New';"><span class="Apple-style-span" style="color: #666666; font-size: x-small;"> Serial.begin(9600);<o:p></o:p></span></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="font-size: x-small;"><br />
</span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="font-family: 'Courier New';"><span class="Apple-style-span" style="color: #666666; font-size: x-small;"> pinMode(LED, OUTPUT);<o:p></o:p></span></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="font-family: 'Courier New';"><span class="Apple-style-span" style="color: #666666; font-size: x-small;"> pinMode(4, OUTPUT); // output pin<o:p></o:p></span></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="font-family: 'Courier New';"><span class="Apple-style-span" style="color: #666666; font-size: x-small;"> pinMode(5, INPUT); // input pin<o:p></o:p></span></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="font-family: 'Courier New';"><span class="Apple-style-span" style="color: #666666; font-size: x-small;">}<o:p></o:p></span></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="font-size: x-small;"><br />
</span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="font-family: 'Courier New';"><span class="Apple-style-span" style="color: #666666; font-size: x-small;">void loop() <o:p></o:p></span></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="font-family: 'Courier New';"><span class="Apple-style-span" style="color: #666666; font-size: x-small;">{ <o:p></o:p></span></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="font-family: 'Courier New';"><span class="Apple-style-span" style="color: #666666; font-size: x-small;"> // clear out the capacitance time interval measures at start <o:p></o:p></span></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="font-family: 'Courier New';"><span class="Apple-style-span" style="color: #666666; font-size: x-small;"> // of each loop iteration<o:p></o:p></span></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="font-family: 'Courier New';"><span class="Apple-style-span" style="color: #666666; font-size: x-small;"> capHi = 0;<o:p></o:p></span></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="font-family: 'Courier New';"><span class="Apple-style-span" style="color: #666666; font-size: x-small;"> capLo = 0;<o:p></o:p></span></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="font-size: x-small;"><br />
</span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="font-family: 'Courier New';"><span class="Apple-style-span" style="color: #666666; font-size: x-small;"> // average over 4 times to remove jitter<o:p></o:p></span></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="font-family: 'Courier New';"><span class="Apple-style-span" style="color: #666666; font-size: x-small;"> for (int i=0; i < 4 ; i++ )<o:p></o:p></span></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="font-family: 'Courier New';"><span class="Apple-style-span" style="color: #666666; font-size: x-small;"> { <o:p></o:p></span></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="font-family: 'Courier New';"><span class="Apple-style-span" style="color: #666666; font-size: x-small;"> // LOW-to-HIGH transition<o:p></o:p></span></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="font-family: 'Courier New';"><span class="Apple-style-span" style="color: #666666; font-size: x-small;"> digitalWrite(4, HIGH); <o:p></o:p></span></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="font-size: x-small;"><br />
</span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="font-family: 'Courier New';"><span class="Apple-style-span" style="color: #666666; font-size: x-small;"> // measure duration while the sense pin is not high<o:p></o:p></span></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="font-family: 'Courier New';"><span class="Apple-style-span" style="color: #666666; font-size: x-small;"> while (digitalRead(5) != 1)<o:p></o:p></span></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="font-family: 'Courier New';"><span class="Apple-style-span" style="color: #666666; font-size: x-small;"> capLo++;<o:p></o:p></span></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="font-family: 'Courier New';"><span class="Apple-style-span" style="color: #666666; font-size: x-small;"> delay(1);<o:p></o:p></span></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="font-size: x-small;"><br />
</span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="font-family: 'Courier New';"><span class="Apple-style-span" style="color: #666666; font-size: x-small;"> // HIGH-to-LOW transition<o:p></o:p></span></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="font-family: 'Courier New';"><span class="Apple-style-span" style="color: #666666; font-size: x-small;"> digitalWrite(4, LOW); <o:p></o:p></span></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="font-size: x-small;"><br />
</span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="font-family: 'Courier New';"><span class="Apple-style-span" style="color: #666666; font-size: x-small;"> // measure duration while the sense pin is high<o:p></o:p></span></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="font-family: 'Courier New';"><span class="Apple-style-span" style="color: #666666; font-size: x-small;"> while(digitalRead(5) != 0 ) <o:p></o:p></span></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="font-family: 'Courier New';"><span class="Apple-style-span" style="color: #666666; font-size: x-small;"> capHi++; <o:p></o:p></span></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="font-family: 'Courier New';"><span class="Apple-style-span" style="color: #666666; font-size: x-small;"> delay(1);<o:p></o:p></span></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="font-family: 'Courier New';"><span class="Apple-style-span" style="color: #666666; font-size: x-small;"> }<o:p></o:p></span></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="font-size: x-small;"><br />
</span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="font-family: 'Courier New';"><span class="Apple-style-span" style="color: #666666; font-size: x-small;"> // Easy smoothing filter "f_val" determines amount of new data <o:p></o:p></span></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="font-family: 'Courier New';"><span class="Apple-style-span" style="color: #666666; font-size: x-small;"> // in filt_capI<o:p></o:p></span></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="font-family: 'Courier New';"><span class="Apple-style-span" style="color: #666666; font-size: x-small;"> filt_capI = (f_val * (float)capLo) + ((1-f_val) * prev_capI); <o:p></o:p></span></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="font-family: 'Courier New';"><span class="Apple-style-span" style="color: #666666; font-size: x-small;"> prev_capI = filt_capI; <o:p></o:p></span></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="font-size: x-small;"><br />
</span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="font-family: 'Courier New';"><span class="Apple-style-span" style="color: #666666; font-size: x-small;"> Serial.println( filt_capI ); // Smoothed Low to High<o:p></o:p></span></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="font-size: x-small;"><br />
</span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="font-family: 'Courier New';"><span class="Apple-style-span" style="color: #666666; font-size: x-small;"> // Map the capacitance value range to LED brightness (0-255)<o:p></o:p></span></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="font-family: 'Courier New';"><span class="Apple-style-span" style="color: #666666; font-size: x-small;"> int ledVal = map (filt_capI, LOW_T, HIGH_T, 0, 255);<o:p></o:p></span></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span class="Apple-style-span" style="font-size: x-small;"><br />
</span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="font-family: 'Courier New';"><span class="Apple-style-span" style="color: #666666; font-size: x-small;"> if (filt_capI > LOW_T)<o:p></o:p></span></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="font-family: 'Courier New';"><span class="Apple-style-span" style="color: #666666; font-size: x-small;"> analogWrite(LED, ledVal);<o:p></o:p></span></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="font-family: 'Courier New';"><span class="Apple-style-span" style="color: #666666; font-size: x-small;"> else<o:p></o:p></span></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="font-family: 'Courier New';"><span class="Apple-style-span" style="color: #666666; font-size: x-small;"> analogWrite(LED, 0);<o:p></o:p></span></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><span style="font-family: 'Courier New';"><span class="Apple-style-span" style="color: #666666; font-size: x-small;">}</span></span><span style="font-family: 'Courier New';"><o:p></o:p></span></div></td> </tr>
</tbody></table><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;"><br />
</div></div>NMhttp://www.blogger.com/profile/03556991654093947404noreply@blogger.com2tag:blogger.com,1999:blog-8410140457122624973.post-71274063188577286652010-05-07T17:37:00.006-05:002012-01-19T18:07:48.353-06:00Heidi<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgoTKzL2I9ZkZn-Xup4AYTrn3BJT1oOKeWKnQwj_5IadMmzuFjOj-YlQQuY4ym3zpeAIHwSC4V9PQkYkyddUMr94APGvM9pGjIWlyVunwqIBC19ZgiI3od9pq1ULZKRKfRpBxb0Fomw0tg/s1600/Heidi4_sm.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="213" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgoTKzL2I9ZkZn-Xup4AYTrn3BJT1oOKeWKnQwj_5IadMmzuFjOj-YlQQuY4ym3zpeAIHwSC4V9PQkYkyddUMr94APGvM9pGjIWlyVunwqIBC19ZgiI3od9pq1ULZKRKfRpBxb0Fomw0tg/s320/Heidi4_sm.jpg" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
The final version of the robot is the same as the earlier design of squarish-looking robot. But the colors are much brighter now. The robot has the following characteristics:<br />
<br />
1. Range-finder detects if someone has come within 30 cm of the robot and if so, the robot abruptly wakes up, moving its head up and eyes lighting up. The robot's neck pulls up using a servo motor and its eyes have LED's which light up to show it's awake and ready to play.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9X5n95lrh1RM7DGuzfKnKz9kOn1mq1XeMqWwGeS_MFYg_K8Z-j4a3NjowKXAkqoCBlCP9Vp9JO2QsYcilMlIZpW_QLa0cTzkrsclo38WXMz1bjNVID9DGjj8XSn99zSdRneMAgx12hZw/s1600/IMG_2550.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="150" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9X5n95lrh1RM7DGuzfKnKz9kOn1mq1XeMqWwGeS_MFYg_K8Z-j4a3NjowKXAkqoCBlCP9Vp9JO2QsYcilMlIZpW_QLa0cTzkrsclo38WXMz1bjNVID9DGjj8XSn99zSdRneMAgx12hZw/s200/IMG_2550.JPG" width="200" /></a><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgbNP9CQK6VOSY_Jw5yLNeLavQ_aH3tZ8SOrdrvkZtzZi0kF-nOxGjyUgfZVj7Lc8CNBq58tj7Sm-Z2c040F8ZzdDxRuy6wCKR_RPHlJEvQidFz0i0JE4knVxaq8kFfc0ACmYv5CrTVXlY/s1600/IMG_2373.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="150" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgbNP9CQK6VOSY_Jw5yLNeLavQ_aH3tZ8SOrdrvkZtzZi0kF-nOxGjyUgfZVj7Lc8CNBq58tj7Sm-Z2c040F8ZzdDxRuy6wCKR_RPHlJEvQidFz0i0JE4knVxaq8kFfc0ACmYv5CrTVXlY/s200/IMG_2373.JPG" width="200" /></a><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj2PLGAXKJMN-eEye-jk7KRgdKOBni4AQCZ2p-eT5MzAFon3nhynztnr8E6biUqiEiwe3BbOtuyOo5F47G7-iiknuY_HAsvlXenMXAO_F28gEctZwgNv73k97UWiDT_ZmFAkMNu4gKI8Jo/s1600/IMG_2557.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="150" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj2PLGAXKJMN-eEye-jk7KRgdKOBni4AQCZ2p-eT5MzAFon3nhynztnr8E6biUqiEiwe3BbOtuyOo5F47G7-iiknuY_HAsvlXenMXAO_F28gEctZwgNv73k97UWiDT_ZmFAkMNu4gKI8Jo/s200/IMG_2557.JPG" width="200" /></a></div>
<br />
2. Force Sensitive Resistors in the ears detect the slightest rub and if someone scratches one of its ears, the robot giggles (bobs its head and blinks eyes).<br />
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEixqN3_OzU43qROHewW-DHWGOjF-7-20cq1BiDjNiaT0NK40ea9lOuOmhg_wxT40hJWsxxfGm1WyFryBURqy8KizTHhnlJWojYT8XWupOHtHJyojLmCz5Bmp9gkvzchcXeNfjUlmYS04BA/s1600/IMG_2558.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="150" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEixqN3_OzU43qROHewW-DHWGOjF-7-20cq1BiDjNiaT0NK40ea9lOuOmhg_wxT40hJWsxxfGm1WyFryBURqy8KizTHhnlJWojYT8XWupOHtHJyojLmCz5Bmp9gkvzchcXeNfjUlmYS04BA/s200/IMG_2558.JPG" width="200" /></a></div>
<br />
<br />
3. Capacitive Sensor in the nose detects if anyone touches the nose. If so, the robot pulls its head back down. <br />
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhRVipZyFPuIWU3GvNLMht1h2H0gCfpUu9kW1LI9lu6OzGyMXS7vwtlmq-uoH2h5fXXrI5IGyAilVSBxR4jOBrvIVeeQGjw-jKgYMOPmtgUcxTeoGu2fMTajQVMzeHjn1fhH4QbfIQa9hQ/s1600/IMG_2559.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="150" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhRVipZyFPuIWU3GvNLMht1h2H0gCfpUu9kW1LI9lu6OzGyMXS7vwtlmq-uoH2h5fXXrI5IGyAilVSBxR4jOBrvIVeeQGjw-jKgYMOPmtgUcxTeoGu2fMTajQVMzeHjn1fhH4QbfIQa9hQ/s200/IMG_2559.JPG" width="200" /></a></div>
<br />
4. Wheels activate if a person messes with the robot's nose too much. The robot moves it's head down and then suddenly rolls away to a side (moves to left or right alternately).<br />
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh2GduNBbJLIA4iCVzwRSj84r36pmG722FeVYAhyphenhyphenmjjNue1o6TNBjBHqVPHrRSgSsrYYNlbamGf12lPf_YaYuCluu626He28FAY3NZUcdISDSFyYM0b7XRwe38-e2frlpZjBiqyo9cL5u0/s1600/IMG_2547.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="150" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh2GduNBbJLIA4iCVzwRSj84r36pmG722FeVYAhyphenhyphenmjjNue1o6TNBjBHqVPHrRSgSsrYYNlbamGf12lPf_YaYuCluu626He28FAY3NZUcdISDSFyYM0b7XRwe38-e2frlpZjBiqyo9cL5u0/s200/IMG_2547.JPG" width="200" /></a><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSvwXx1ECYVZIWmWL43wp6ik3dUPB1cQN39PwzoSXcXw7hkyNu2dw3r22Th-Kgqmqq3k6YclFbAC44D0Of3VJ7G4T9leDlcQphtq8UIfcs5uX4ZxFiBmV4garEO10JIvIk5z8fos4H8kI/s1600/IMG_2549.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="150" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSvwXx1ECYVZIWmWL43wp6ik3dUPB1cQN39PwzoSXcXw7hkyNu2dw3r22Th-Kgqmqq3k6YclFbAC44D0Of3VJ7G4T9leDlcQphtq8UIfcs5uX4ZxFiBmV4garEO10JIvIk5z8fos4H8kI/s200/IMG_2549.JPG" width="200" /></a></div>
<br />
<br />
The final breadboard looked somewhat like this: (there are still a few connections missing - which I can't take a picture of since the breadboard is inserted into the robot-body to connect to those).<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEirPBIbQcR0zFgkHzEO8y7xOwUnyskhz28Y8zWTdTaTzuGpcjY2U9x1Yz0OTQ7ezRBTUXH6QAj_VQlh5nNbq3Zs4J3l3s5r-JEOpDYUm0KXjp8iFyvZDOoZWL4YX9WBn40VPSd2iNTtxuA/s1600/IMG_2443.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="150" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEirPBIbQcR0zFgkHzEO8y7xOwUnyskhz28Y8zWTdTaTzuGpcjY2U9x1Yz0OTQ7ezRBTUXH6QAj_VQlh5nNbq3Zs4J3l3s5r-JEOpDYUm0KXjp8iFyvZDOoZWL4YX9WBn40VPSd2iNTtxuA/s200/IMG_2443.JPG" width="200" /></a><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjr1G8MZNxrJJIRlwEW011ER3SqXfkr9RINkdHv6RIR7CP7dwP-iHtLGWPB6G9b25S0Y-n6_OENsszHaiNYdwwx4Xmr9gpF9KZtxw43NURP29kEL_cl47qJAeU8wf8HzX9ziwJh5WYbdQM/s1600/IMG_2440.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="150" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjr1G8MZNxrJJIRlwEW011ER3SqXfkr9RINkdHv6RIR7CP7dwP-iHtLGWPB6G9b25S0Y-n6_OENsszHaiNYdwwx4Xmr9gpF9KZtxw43NURP29kEL_cl47qJAeU8wf8HzX9ziwJh5WYbdQM/s200/IMG_2440.JPG" width="200" /></a></div>
<br />
<br />
<div style="text-align: center;">
<object height="300" width="400"><param name="allowfullscreen" value="true" />
<param name="allowscriptaccess" value="always" />
<param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=11565768&server=vimeo.com&show_title=1&show_byline=1&show_portrait=0&color=&fullscreen=1" />
<embed src="http://vimeo.com/moogaloop.swf?clip_id=11565768&server=vimeo.com&show_title=1&show_byline=1&show_portrait=0&color=&fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="400" height="300"></embed></object></div>
<div style="text-align: center;">
<a href="http://vimeo.com/11565768">Runaway Robot</a> from <a href="http://vimeo.com/user2369176">naureenm</a> on <a href="http://vimeo.com/">Vimeo</a>.</div>
<br />
<br />
<div class="separator" style="clear: both; text-align: left;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEir6jqb813oZvzwvDLIH4J1h8WPnoqQX_Ec2ja_kHQE_2tG7FAOLP6SN7sK6da-ShMLMZQg5a_IWA8Avc8CklKCGRTCIbbllV_qkWMVFHW05VdjadduQ71a5HLw5F9L4gtiJ0ljHSlOwLg/s1600/IMG_2468.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em; text-align: center;"><img border="0" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEir6jqb813oZvzwvDLIH4J1h8WPnoqQX_Ec2ja_kHQE_2tG7FAOLP6SN7sK6da-ShMLMZQg5a_IWA8Avc8CklKCGRTCIbbllV_qkWMVFHW05VdjadduQ71a5HLw5F9L4gtiJ0ljHSlOwLg/s320/IMG_2468.JPG" width="320" /></a> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjgv6aZXzvmsyowPeBtiAEU7nRyxKXRK0rhbe0hyWurM4b0eSdjbdrT99xCvwUf_IXho67HG0Oq2IgrVTmRFlHcqWUMCLMR7IJlmrOM3BrXBfX6eqTDZs7H6fw3oyz52Les6tyMtvIK6ps/s1600/IMG_2469.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em; text-align: center;"><img border="0" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjgv6aZXzvmsyowPeBtiAEU7nRyxKXRK0rhbe0hyWurM4b0eSdjbdrT99xCvwUf_IXho67HG0Oq2IgrVTmRFlHcqWUMCLMR7IJlmrOM3BrXBfX6eqTDZs7H6fw3oyz52Les6tyMtvIK6ps/s320/IMG_2469.JPG" width="320" /></a> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhIgE0LlQQvU8XU3Smpt0wol_TdhdctVin0pos84ap6CmNiNmEUbzepxmA8_mrdPhCd0uSu8QovbHpQjdAuu01ryLL53COstCDucK1xOryDCb5TiSaUpFwpfLure5MadGNuR8lyPYw3uMs/s1600/IMG_2471.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em; text-align: center;"><img border="0" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhIgE0LlQQvU8XU3Smpt0wol_TdhdctVin0pos84ap6CmNiNmEUbzepxmA8_mrdPhCd0uSu8QovbHpQjdAuu01ryLL53COstCDucK1xOryDCb5TiSaUpFwpfLure5MadGNuR8lyPYw3uMs/s320/IMG_2471.JPG" width="320" /></a> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiLBl73TrAup825mzNRey3YRlroEAkYBcwcJGuPF616Bi_iXwj4owCF6Jo5Me_vMjOsTHurM8GAgBbufCc9A1TKCebaIqkFmGEwm3_OCDIL4Q_dAtWcm3XuFC_9bB2nsJPfLa0Zx9K99Sc/s1600/IMG_2514.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em; text-align: center;"><img border="0" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiLBl73TrAup825mzNRey3YRlroEAkYBcwcJGuPF616Bi_iXwj4owCF6Jo5Me_vMjOsTHurM8GAgBbufCc9A1TKCebaIqkFmGEwm3_OCDIL4Q_dAtWcm3XuFC_9bB2nsJPfLa0Zx9K99Sc/s320/IMG_2514.JPG" width="320" /></a> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhi3_bSAbBR8fYRWc8PGN4_wRZXTqynB0_RsuAPHmiHZhwggFKJRgxKPk0x9W_OpgZmL3yjyAxr9Nn_nhyphenhyphened3rNwjCDtP80_zwsI6CyZwQJW8OFVtZRgvaar7leQhVWOHS8J6vf5mqALps/s1600/IMG_2516.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em; text-align: center;"><img border="0" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhi3_bSAbBR8fYRWc8PGN4_wRZXTqynB0_RsuAPHmiHZhwggFKJRgxKPk0x9W_OpgZmL3yjyAxr9Nn_nhyphenhyphened3rNwjCDtP80_zwsI6CyZwQJW8OFVtZRgvaar7leQhVWOHS8J6vf5mqALps/s320/IMG_2516.JPG" width="320" /></a> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj4GKguuMisEOkKo0bcNQFXyMf043BLU0_2xZiwdDEp1mkxzVXNAEVBuUFeYVcOGp1C1Yu1zzVPFZfnOM0yKvZVk2UaIl_bt4tSSjBMdo-3TW4R-_jcr240jUjs9Ow6gmivzRnpqk-oV5o/s1600/IMG_2466.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj4GKguuMisEOkKo0bcNQFXyMf043BLU0_2xZiwdDEp1mkxzVXNAEVBuUFeYVcOGp1C1Yu1zzVPFZfnOM0yKvZVk2UaIl_bt4tSSjBMdo-3TW4R-_jcr240jUjs9Ow6gmivzRnpqk-oV5o/s320/IMG_2466.JPG" width="320" /></a> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgikTLr_Xwo8h4Y6MiCCyPtuN_Xy2iucSEFxwxdh_nN-s3mhfZ5XdWQjid344Gy2WclHhyhRr1BOEk0wGdMW8PoqJWjA2SO90qBgV5mMT7dblg7Npzlh-VSIyzR2bAQk0CqQCoGdo0f8Dc/s1600/IMG_2533.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgikTLr_Xwo8h4Y6MiCCyPtuN_Xy2iucSEFxwxdh_nN-s3mhfZ5XdWQjid344Gy2WclHhyhRr1BOEk0wGdMW8PoqJWjA2SO90qBgV5mMT7dblg7Npzlh-VSIyzR2bAQk0CqQCoGdo0f8Dc/s320/IMG_2533.JPG" width="320" /></a> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgfgIrz4-xnjR1X5vD0admBTm7tHBUXEtjZbuUbOy0U51oxMvibm4ZDNQ-LaR4fmocTk8bBkDk9HIQnpFlU0ev5hBI69KS40O8Utv45ya3DnOR8LiyhqP4ni1Bf9VnGWSQM5gFEmlJycqE/s1600/IMG_2465.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em; text-align: center;"><img border="0" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgfgIrz4-xnjR1X5vD0admBTm7tHBUXEtjZbuUbOy0U51oxMvibm4ZDNQ-LaR4fmocTk8bBkDk9HIQnpFlU0ev5hBI69KS40O8Utv45ya3DnOR8LiyhqP4ni1Bf9VnGWSQM5gFEmlJycqE/s320/IMG_2465.JPG" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjGRBfvJ4hfi8PhgU1d7f1K_3nC9Jm1cHwDGQUJ15ah3p5pZQMhQ6ndg_Wvq57b4aRE10JR-xNOaCYyaFQQSWzuYpBu5ANRCwSm4kYm8E4yyCO4Tuk_QSnwGJfbSpja42J3GWGskAVn2os/s1600/Heidi3_sm.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="212" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjGRBfvJ4hfi8PhgU1d7f1K_3nC9Jm1cHwDGQUJ15ah3p5pZQMhQ6ndg_Wvq57b4aRE10JR-xNOaCYyaFQQSWzuYpBu5ANRCwSm4kYm8E4yyCO4Tuk_QSnwGJfbSpja42J3GWGskAVn2os/s320/Heidi3_sm.jpg" width="320" /></a>
</div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<br />
<br />
<span style="font-size: large;"><b>==========================================</b></span><br />
<br />
<span style="font-size: large;"><b>Arduino Code:</b></span><br />
<br />
<div style="font-family: "Courier New",Courier,monospace;">
#include [servo.h]<br />
<br />
#define EYES_OPEN 255<br />
#define EYES_SHUT 0<br />
#define EYES_DIM 30<br />
<br />
#define HEAD_HI 10<br />
#define HEAD_LO 100<br />
<br />
#define RANGE_NEAR 35<br />
#define RANGE_NEARER 20<br />
#define RANGE_FAR 100<br />
#define R_SAMPLES 20<br />
#define INTERVAL 10000<br />
#define WHEEL_INTERVAL 1000<br />
<br />
#define TOUCH_HI 60<br />
#define FSR_HI 30<br />
<br />
int HEAD = HEAD_LO;<br />
int EYES = EYES_SHUT;<br />
<br />
unsigned long currMillis;<br />
long prevMillis = 0;<br />
long prevWheelMillis = 0;<br />
boolean dir = true;<br />
boolean running = false;<br />
<br />
// ##################<br />
// ## Analog Pins: ##<br />
// ##################<br />
<br />
// RANGEFINDER VARs<br />
int rangeSum=0; //Create sum variable<br />
int rangeCount = 0;<br />
int rangePrev = RANGE_NEAR;<br />
int rangeCurr = RANGE_FAR;<br />
<br />
// FSR VARs<br />
int FSRval1;<br />
int FSRval2; <br />
<br />
// ###################<br />
// ## Digital Pins: ##<br />
// ###################<br />
<br />
// CAPACITATIVE SENSOR VARs<br />
unsigned int touchX, touchY;<br />
float touchSum, touchOut, touchVal = .07; // these are variables for a simple low-pass (smoothing) filter - touchVal of 1 = no filter - .001 = max filter<br />
<br />
// SERVO VARs<br />
Servo myservo; // create servo object to control a servo <br />
<br />
int pinTest = 3;<br />
int pinFSR1 = 0;<br />
int pinFSR2 = 1;<br />
int pinRange = 2; // select the input pin for the ultrasonic sensor<br />
<br />
const int pinTouchOut = 2;<br />
const int pinTouchIn = 3;<br />
const int pinTouchGrd = 4;<br />
const int pinServo = 5;<br />
const int pinEyes = 6;<br />
<br />
const int motor1Pin = 9; // H-bridge leg 1 (pin 2, 1A)<br />
const int motor2Pin = 8; // H-bridge leg 2 (pin 7, 2A)<br />
const int motor3Pin = 11; // H-bridge leg 1 (pin 2, 1A)<br />
const int motor4Pin = 12; // H-bridge leg 2 (pin 7, 2A)<br />
const int enablePin = 10; // H-bridge enable <br />
<br />
int runRangeFinder();<br />
int runTouchSensor();<br />
int runFSR();<br />
<br />
int noseCount = 0;<br />
<br />
void setup() <br />
{<br />
Serial.begin(9600);<br />
<br />
pinMode(pinTest, OUTPUT); // TEST LED<br />
pinMode(pinRange, INPUT); // RANGEFINDER<br />
pinMode(pinFSR1, INPUT); // FSR<br />
pinMode(pinFSR2, INPUT); // FSR<br />
<br />
pinMode(pinEyes, OUTPUT); // EYES' LEDs<br />
pinMode(pinTouchOut, OUTPUT); // output pin<br />
pinMode(pinTouchIn, INPUT); // input pin<br />
pinMode(pinTouchGrd, OUTPUT); // guard pin<br />
digitalWrite(pinTouchGrd, LOW); // could also be HIGH - don't use this pin for changing output though<br />
myservo.attach(pinServo); // SERVO:<br />
<br />
// set all the other pins you're using as outputs:<br />
pinMode(motor1Pin, OUTPUT); <br />
pinMode(motor2Pin, OUTPUT); <br />
pinMode(motor3Pin, OUTPUT); <br />
pinMode(motor4Pin, OUTPUT); <br />
pinMode(enablePin, OUTPUT);<br />
}<br />
<br />
void loop() <br />
{ <br />
currMillis = millis(); <br />
<br />
randomSeed(analogRead(pinTouchGrd)); // setting the seed to data from unconnected pin<br />
runRangeFinder();<br />
runTouchSensor(); <br />
runFSR();<br />
runWheels();<br />
<br />
// when normal --> return to Normal Position<br />
myservo.write(HEAD); <br />
analogWrite (pinEyes, EYES);<br />
/*<br />
Serial.print("\t Touch: ");<br />
Serial.print( (long)touchOut, DEC); // Smoothed Low to High<br />
Serial.print("\t FSR: ");<br />
Serial.print( FSRval);<br />
Serial.println();<br />
*/<br />
delay(10); <br />
}<br />
<br />
<br />
//==================<br />
// RANGE FINDER<br />
//==================<br />
int runRangeFinder()<br />
{<br />
unsigned long currRangeMillis = millis();<br />
// sampleCount starts life at 0, then loops through sampleSize<br />
rangeSum += analogRead(pinRange);<br />
rangeCount++;<br />
if (rangeCount == R_SAMPLES) <br />
{<br />
rangeCurr= rangeSum/R_SAMPLES;<br />
<br />
Serial.print("Range: ");<br />
Serial.print(rangeCurr);<br />
Serial.println();<br />
rangeCount = 0; rangeSum = 0;<br />
if (rangeCurr <= RANGE_NEAR)<br />
rangePrev = RANGE_NEAR;<br />
if (currRangeMillis - prevMillis > INTERVAL )<br />
{<br />
prevMillis = currRangeMillis;<br />
if (rangeCurr >= RANGE_FAR)<br />
rangePrev = rangeCurr;<br />
Serial.print(" Interval - Curr: ");<br />
Serial.print(rangeCurr);<br />
Serial.print(" Prev: ");<br />
Serial.print(rangePrev);<br />
Serial.println();<br />
}<br />
}<br />
<br />
if (rangeCurr < RANGE_NEAR)<br />
{<br />
Serial.println("Hi there!");<br />
// talk();<br />
HEAD = ( HEAD > HEAD_HI ? HEAD-=10 : HEAD_HI);<br />
EYES = ( EYES < EYES_OPEN ? EYES+=10 : EYES_OPEN);<br />
}<br />
else if(rangePrev >= RANGE_FAR && rangeCurr >= RANGE_FAR)<br />
{<br />
HEAD = HEAD_LO;<br />
EYES = EYES_SHUT;<br />
}<br />
<br />
return 0;<br />
}<br />
<br />
//==================<br />
// TOUCH SENSOR: <br />
//==================<br />
int runTouchSensor()<br />
{ <br />
touchX = 0; // clear out variables<br />
touchY = 0;<br />
<br />
for (int i=0; i < 4 ; i++ )<br />
{ // do it four times to build up an average - not really neccessary but takes out some jitter<br />
<br />
digitalWrite(pinTouchOut, HIGH); // LOW-to-HIGH transition<br />
while (digitalRead(pinTouchIn) != 1) touchX++;// while the sense pin is not high<br />
delay(1);<br />
digitalWrite(pinTouchOut, LOW); // HIGH-to-LOW transition<br />
while(digitalRead(pinTouchIn) != 0 ) touchY++; <br />
delay(1);<br />
}<br />
<br />
touchOut = (touchVal * (float)touchX) + ((1-touchVal) * touchSum); // Easy smoothing filter "touchVal" determines amount of new data in touchOut<br />
touchSum = touchOut;<br />
<br />
// Serial.print(touchOut);<br />
// Serial.println(touchOut);<br />
<br />
// when nose touched --> hide<br />
if (touchOut >= TOUCH_HI)<br />
{<br />
Serial.println ("You touched my Nose! :(");<br />
// EYES = EYES_DIM;<br />
// HEAD = HEAD_LO; <br />
<br />
myservo.write(HEAD_LO); <br />
analogWrite (pinEyes, EYES_DIM);<br />
noseCount += 1;<br />
Serial.print(" NoseCount: ");<br />
Serial.println(noseCount);<br />
delay (1000);<br />
}<br />
return 0;<br />
}<br />
<br />
//==================<br />
// FORCE SENSOR: <br />
//==================<br />
int runFSR()<br />
{<br />
FSRval1 = analogRead(pinFSR1);<br />
FSRval2 = analogRead(pinFSR2);<br />
<br />
// when ear rubbed --> laugh<br />
if (FSRval1 >= FSR_HI || FSRval2 >= FSR_HI)<br />
{<br />
Serial.println("Hehehe :D");<br />
for (int i = 0; i < random(2,5); i++)<br />
{<br />
myservo.write(HEAD_HI); <br />
analogWrite (pinEyes, EYES_OPEN);<br />
delay(100);<br />
<br />
myservo.write(HEAD_LO); <br />
analogWrite (pinEyes, EYES_DIM);<br />
delay(130); <br />
}<br />
} <br />
// Serial.print(", FSR1: ");<br />
// Serial.print( FSRval1);<br />
// Serial.print(", FSR2: ");<br />
// Serial.println( FSRval2);<br />
<br />
// delay (500);<br />
return 0;<br />
}<br />
<br />
int runWheels()<br />
{<br />
if (noseCount == 3 || running)<br />
{ <br />
if (currMillis - prevWheelMillis > WHEEL_INTERVAL )<br />
{<br />
prevWheelMillis = millis();<br />
if (!running)<br />
{<br />
digitalWrite(enablePin, HIGH); <br />
Serial.println("go!");<br />
running = !running;<br />
}<br />
else<br />
{<br />
Serial.println("stop!");<br />
digitalWrite(enablePin, LOW); <br />
noseCount = 0;<br />
running = !running;<br />
return 1;<br />
}<br />
<br />
if (dir)<br />
{<br />
Serial.println("dir1!");<br />
digitalWrite(motor1Pin, LOW); // set leg 1 of the H-bridge low<br />
digitalWrite(motor2Pin, HIGH); // set leg 2 of the H-bridge high<br />
<br />
digitalWrite(motor3Pin, LOW); // set leg 1 of the H-bridge low<br />
digitalWrite(motor4Pin, HIGH); // set leg 2 of the H-bridge high<br />
<br />
dir = !dir;<br />
}<br />
else<br />
{<br />
Serial.println("dir2!");<br />
digitalWrite(motor1Pin, HIGH); // set leg 1 of the H-bridge low<br />
digitalWrite(motor2Pin, LOW); // set leg 2 of the H-bridge high<br />
<br />
digitalWrite(motor3Pin, HIGH); // set leg 1 of the H-bridge low<br />
digitalWrite(motor4Pin, LOW); // set leg 2 of the H-bridge high<br />
<br />
dir = !dir;<br />
}<br />
}<br />
} <br />
return 0;<br />
}</div>NMhttp://www.blogger.com/profile/03556991654093947404noreply@blogger.com0tag:blogger.com,1999:blog-8410140457122624973.post-61318354596435363452010-04-27T17:34:00.000-05:002010-04-27T17:34:44.998-05:00So far: <br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSmDszX43NKY3gDA-RJn5xaHDbjzXWR76wZUw2q5fA7vS-sEG3wsbLsIxbG53FdU-U3hwyTqCbbgct8Y9QeqZ7SdBljBJzuY_tgTREYLlBZze7nhT4SNZITRWpJGd6iZJRwWnjgbpSOPI/s1600/IMG_2369_small.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="150" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSmDszX43NKY3gDA-RJn5xaHDbjzXWR76wZUw2q5fA7vS-sEG3wsbLsIxbG53FdU-U3hwyTqCbbgct8Y9QeqZ7SdBljBJzuY_tgTREYLlBZze7nhT4SNZITRWpJGd6iZJRwWnjgbpSOPI/s200/IMG_2369_small.jpg" width="200" /></a><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjKExgYyVzXPHUmd13X2Fwj8KLYmbr0JZ7T_pEHxtIoI2gZKKWyxOdHTuUbBqcWysNraWkHT5xLdw1szIf3yi8czj5xVZDxpvXF9ytqubVPXdlGgKrS2oI3_odF-IMcwPFLdjQDn7Lvowk/s1600/IMG_2371_small.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="150" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjKExgYyVzXPHUmd13X2Fwj8KLYmbr0JZ7T_pEHxtIoI2gZKKWyxOdHTuUbBqcWysNraWkHT5xLdw1szIf3yi8czj5xVZDxpvXF9ytqubVPXdlGgKrS2oI3_odF-IMcwPFLdjQDn7Lvowk/s200/IMG_2371_small.jpg" width="200" /></a><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhINL_p92UXUQXb475HxCT75lygViAKjwowaLWgs-G6RJSOZZ2keY4I1ye5MB4Ib5c6FWGC2QLCb2LjjMOymDN3ZlWtBJkGr1L94gnW7I6zHGB1pKnMxSmr-adIG0wCYCBbW7lQIGdgenA/s1600/IMG_2370_small.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="150" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhINL_p92UXUQXb475HxCT75lygViAKjwowaLWgs-G6RJSOZZ2keY4I1ye5MB4Ib5c6FWGC2QLCb2LjjMOymDN3ZlWtBJkGr1L94gnW7I6zHGB1pKnMxSmr-adIG0wCYCBbW7lQIGdgenA/s200/IMG_2370_small.jpg" width="200" /></a><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhBoidn-8Se2AgSXI27_Rpeuv-DtC5JJAgotZU5kaZ-h5VhpuUxXtqvOm2U5JD8RdQlK2WJa0GgsQb-rjOfMTqtjvvulByBqoJQnSa3YCxtUqn2k-Fj-sFeqtztSgFQ14GmVPYiZbwvbMU/s1600/IMG_2373_small.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="150" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhBoidn-8Se2AgSXI27_Rpeuv-DtC5JJAgotZU5kaZ-h5VhpuUxXtqvOm2U5JD8RdQlK2WJa0GgsQb-rjOfMTqtjvvulByBqoJQnSa3YCxtUqn2k-Fj-sFeqtztSgFQ14GmVPYiZbwvbMU/s200/IMG_2373_small.jpg" width="200" /></a></div><br />
<br />
Wheels also move and eyes light up - still need to solder the wires so it can work when the body is mounted on top. The wheels' movement is dependent on signal from the range-sensor. It's still kinda iffy. <br />
<br />
The nose has a home-made capacitive sensor, made with a high resistor to accumulate and respond to current (the real capacitive sensor i got from the Prof. Galanter was too big, bulky to be able to fit it easily inside the robot's head. The robot doesn't like it's nose being touched. hides away when nose is touched.<br />
<br />
Head bobs and eyes blink if the ears are rubbed (FSR's inside the ears).NMhttp://www.blogger.com/profile/03556991654093947404noreply@blogger.com0tag:blogger.com,1999:blog-8410140457122624973.post-62934057467431245462010-04-03T01:28:00.009-05:002010-04-03T02:17:24.547-05:00Proj 3: BugProjects using 3 sensors & two motors:<br />
<br />
The object is a small mechanical flying insect called 'Bug'. The bug follows any motion detected in the dark. It either goes around following the motion quietly or, if a certain pressure sensor hasn't been pressed, bug follows the motion while sounding off an alarm. So it can serve as an intruder detector or, in the motion is not caused by an intruder, the insect simply follows the person moving about, casting light on them, knocking into them and hence, 'bugging' them.. =)<br />
<br />
It has three sensors:<br />
<ul><li>Light sensor</li>
<li>A direction sensing motion detector</li>
<li>Pressure sensor</li>
</ul><br />
And two motors are: <br />
<ul><li>DC motor</li>
<li>Servo</li>
</ul><br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg19U2cDHlO650Sdzc-Mty_7o5J_Lgkp6syI57AZA246hzM5fjvHG8RTsdLT98OyTNbWSX6fJxzppgFaKVYeeieHa_MDPSEcauw72C9JetlnffQjs2MeqPRhWheRMWWSrMpdYGNY8ktUfc/s1600/IMG_1948.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg19U2cDHlO650Sdzc-Mty_7o5J_Lgkp6syI57AZA246hzM5fjvHG8RTsdLT98OyTNbWSX6fJxzppgFaKVYeeieHa_MDPSEcauw72C9JetlnffQjs2MeqPRhWheRMWWSrMpdYGNY8ktUfc/s320/IMG_1948.JPG" width="320" /></a><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjzRSO7_tLW7hu2tJzpJ-eJzgJyK8iVRPCOAPhi8dzijgD57GhEDjakp5wrY3DyjcW3U99y6k-Uv88_W_ZJEcUhukuktxjE4e9N9mRGWOl9oH7Y8Quu1w7RV5N6IxByE015hM9BxmBVkAQ/s1600/IMG_1945.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjzRSO7_tLW7hu2tJzpJ-eJzgJyK8iVRPCOAPhi8dzijgD57GhEDjakp5wrY3DyjcW3U99y6k-Uv88_W_ZJEcUhukuktxjE4e9N9mRGWOl9oH7Y8Quu1w7RV5N6IxByE015hM9BxmBVkAQ/s320/IMG_1945.JPG" width="240" /></a></div><br />
<br />
<span style="font-size: large;"><b>Model:</b></span><br />
The bug has a set of propellers at the front, which are controlled by the DC motor. And it has a flap at the back which can swing 180 degrees using the servo, to allow the insect to turn while in flight. <br />
<br />
The insect becomes active only in the dark. As soon as the insect detects any motion in the dark, it starts flying towards it while sounding off a low alarm. The alarm sound can be turned off by pressing onto a hidden pressure sensor on the bug or else it would keep increasing in intensity with each passing minute. <br />
<br />
<span style="font-size: large;"><b>Mechanism:</b></span><br />
The bug remains inactive until the light sensor detects there isn't enough light in the room / surroundings. It's green LED lights turn up to indicate that it is 'awake' and detecting motion around it.<br />
<br />
As soon as the motion detector detects any motion, the bug starts flight. The DC motor turns on to lift the insect off the ground and the direction sensing motion detector can relay which direction the tail-flap should turn. At the same time the alarm sounds off as well. <br />
<br />
When someone pushes onto the pressure sensor, the alarm sounds off but, the bug continues flying and following the motion direction. If the motion sensors stop receiving input for over 30 seconds, the bug circles around it's surroundings for another 30 seconds. If no further motion is detected and the alarm is off, the bug slowly settles down and returns to its initial 'awake' position, waiting for another input from the motion sensors.<br />
<br />
<br />
<span style="font-size: large;"><b>Concept Design:</b></span><br />
The initial concept design I had in mind for this project was something I had made with just .. junk .. from around my apartment some time ago. Here's what that rather not-so-good-looking bug looked like:<br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSFr4OaRrhJwnRu-L4B1v6vREymJMnJRcWC6ELzwlHGeVlj5s2R9qwtmDXm_1PnFvU92mD1uJ2gL8SM7YY4O8kXaUF4YQHvrzIbm5juVA-aO1tNm-8rX4MEIe3Il2rt-Rk1P5L5LSAT8s/s1600/IMG_2347.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="150" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSFr4OaRrhJwnRu-L4B1v6vREymJMnJRcWC6ELzwlHGeVlj5s2R9qwtmDXm_1PnFvU92mD1uJ2gL8SM7YY4O8kXaUF4YQHvrzIbm5juVA-aO1tNm-8rX4MEIe3Il2rt-Rk1P5L5LSAT8s/s200/IMG_2347.JPG" width="200" /></a><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiEil47AlySEowf2RgZom6vZkdz6FVy0zLop7t_WQ3eP5uaBR4hMhi1U3-hzAtADvhw0exhBCnDcLm477fH2FD1dfYFI9UkpJnGKK3dzG8L0NeGnt5qDRTpNPgnTY403iyqx6qUgKwc5pA/s1600/IMG_2349.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="150" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiEil47AlySEowf2RgZom6vZkdz6FVy0zLop7t_WQ3eP5uaBR4hMhi1U3-hzAtADvhw0exhBCnDcLm477fH2FD1dfYFI9UkpJnGKK3dzG8L0NeGnt5qDRTpNPgnTY403iyqx6qUgKwc5pA/s200/IMG_2349.JPG" width="200" /></a></div><span id="goog_918396410"></span><span id="goog_918396411"></span><br />
<br />
So, the idea for this project is mainly a flying bug - that looks somewhat like the dragonfly above. Possibly, even made to be not-so-pretty-looking 'on purpose' (to make it look like it was actually made out of junk found lying around). Just add a propeller on the front, and a servo with a flap at the back :) <br />
<br />
<span style="font-size: large;"><b>Simulation:</b></span><br />
Here's a test simulation I worked on. The servo and the DC motor are connected together. The DC-motor has a couple of lego blocks attached to it as wings. The rest of the things, sensors, LED and buzzer are attached on the breadboard. Also, since we didn't have any direction sensing motion detectors, I have used a potentiometer to tell the servo which direction to move, assuming the moment the servo is first activated, is when motion is first detected. Moreover, the DC-motor already fried my earlier Arduino board because I forgot to attach it through a transistor - so, for now I have just left it off of the Arduino and connected it to an external power without any connection to the Arduino at all, ..just to be on the safe side! :\<br />
<br />
<br />
<br />
<object height="300" width="400"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=10648109&server=vimeo.com&show_title=1&show_byline=1&show_portrait=0&color=&fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=10648109&server=vimeo.com&show_title=1&show_byline=1&show_portrait=0&color=&fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="400" height="300"></embed></object><br />
<br />
<br />
p.s. the lego fan *did* really fly away at the end of that clip! :\NMhttp://www.blogger.com/profile/03556991654093947404noreply@blogger.com3tag:blogger.com,1999:blog-8410140457122624973.post-8026977337240822242010-03-10T10:08:00.020-06:002010-04-01T18:20:48.379-05:00Proj 2: Accelerometer + Potentiometer driven Animation2D motion of an animated dragonfly is controlled on screen by using input from an accelerometer. <br />
<br />
<br />
The potentiometer knob can be used to turn up the opacity of a small radius around the dragonfly to display a hidden image underneath. Only the small area of the hidden image surrounding the dragonfly is visible at a time. You can move the dragonfly around with the accelerometer to explore different areas of the image.<br />
<br />
p.s. (the potentiometer is actually meant to be a pressure sensor but, the potentiometer worked better for testing purposes)<br />
<br />
<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjZnZHeye2h8hTE5Q58VCCm7iC9rDRWdVjM32rGblKWBB3sB7MAFZOMns714fmqg-1dxQzZEaMDhQ1SP_P2L4iBECgASdmcSoZAT1ba4-kru0IwEw_ITCwOb8yVPmLDXdjZgLAbM7-v1xo/s1600-h/IMG_1919.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="150" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjZnZHeye2h8hTE5Q58VCCm7iC9rDRWdVjM32rGblKWBB3sB7MAFZOMns714fmqg-1dxQzZEaMDhQ1SP_P2L4iBECgASdmcSoZAT1ba4-kru0IwEw_ITCwOb8yVPmLDXdjZgLAbM7-v1xo/s200/IMG_1919.JPG" width="200" /></a> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg6H6DcrY4NvxRHse9zaYbjEDa3C_70rjNhauRslzFZa3VS9fHrjEO26s6d2ZApGFgip7GcQ1Khg_0c6F5R2Y1XaJpMc0JemjfVEHvTBtAswpwCVzde0akNQ4cmT2lhqL5Jipqs0uXhX1M/s1600-h/IMG_1921.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="150" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg6H6DcrY4NvxRHse9zaYbjEDa3C_70rjNhauRslzFZa3VS9fHrjEO26s6d2ZApGFgip7GcQ1Khg_0c6F5R2Y1XaJpMc0JemjfVEHvTBtAswpwCVzde0akNQ4cmT2lhqL5Jipqs0uXhX1M/s200/IMG_1921.JPG" width="200" /></a><br />
<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiFETFrsUeR6lDtMpJo07vMQyGYqgLSDWjGn_WqTaLllWIkAXrqq_w0j7Usxw5OBrcRXkd2e-H_oDO8hBI0FF9BYhrf87hdZCuoqrZgKh5Qnwu9BqaTlT75aD5OMjMWyNjKETsNaxIPXT0/s1600-h/IMG_1924.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="150" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiFETFrsUeR6lDtMpJo07vMQyGYqgLSDWjGn_WqTaLllWIkAXrqq_w0j7Usxw5OBrcRXkd2e-H_oDO8hBI0FF9BYhrf87hdZCuoqrZgKh5Qnwu9BqaTlT75aD5OMjMWyNjKETsNaxIPXT0/s200/IMG_1924.JPG" width="200" /></a><br />
<br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEigh7H_7ADyH4DZnI0hMXW4hps-UTxhOObpAt5wjjDEMnBH305SqnaGXaaTvU2X-sKcixtPFOtVmmZuua3qii5Tlmdi0VeJqo4W0iK1HvWraVkrKHHLgXAG7iKWT67jiUJHwj4enmBEtqg/s1600-h/img_000.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="200" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEigh7H_7ADyH4DZnI0hMXW4hps-UTxhOObpAt5wjjDEMnBH305SqnaGXaaTvU2X-sKcixtPFOtVmmZuua3qii5Tlmdi0VeJqo4W0iK1HvWraVkrKHHLgXAG7iKWT67jiUJHwj4enmBEtqg/s200/img_000.jpg" width="190" /></a><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhCi6ej7yOAspZFPaARKzidaEZ6ycmEG-XpFVF-WyffSeZhpcMby3G03FBlmHmg3AutawF_Vq-m7kohkB_3HN2S8rI55jb5KQfBZ3KppNz3VXWmDxL7rCVL5846MAcfF0T9yqP5yqvtMFY/s1600-h/img_001.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="200" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhCi6ej7yOAspZFPaARKzidaEZ6ycmEG-XpFVF-WyffSeZhpcMby3G03FBlmHmg3AutawF_Vq-m7kohkB_3HN2S8rI55jb5KQfBZ3KppNz3VXWmDxL7rCVL5846MAcfF0T9yqP5yqvtMFY/s200/img_001.jpg" width="190" /></a></div><br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSeKR_VL61a_31qL4iYKMW_N7AkbnjwME2NGiTYqZmX8vxHuXDBH3wbt1kc7uXTtDn8v4CJd5tHBdSKsLGuzTp0f9cbo15hvsoCKXec2Fb-PQNf3yPYUF4QO0fZrsBZJuRzLCihrmFWrQ/s1600-h/img_002.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="200" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSeKR_VL61a_31qL4iYKMW_N7AkbnjwME2NGiTYqZmX8vxHuXDBH3wbt1kc7uXTtDn8v4CJd5tHBdSKsLGuzTp0f9cbo15hvsoCKXec2Fb-PQNf3yPYUF4QO0fZrsBZJuRzLCihrmFWrQ/s200/img_002.jpg" width="190" /></a><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi7dWR2rrq2-qlQu8_X-hds0GsK60-nOsoV2Me5yMN9mgovi_-Tf4oXyC4HMRoNrqEwyX1bpG9NBPDi5J2wlQOjNUQv7nJna2WCISabc1aTDJYGuioUx3s33k7KXN51TbUPRR6qiUc8BKU/s1600-h/img_003.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="200" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi7dWR2rrq2-qlQu8_X-hds0GsK60-nOsoV2Me5yMN9mgovi_-Tf4oXyC4HMRoNrqEwyX1bpG9NBPDi5J2wlQOjNUQv7nJna2WCISabc1aTDJYGuioUx3s33k7KXN51TbUPRR6qiUc8BKU/s200/img_003.jpg" width="190" /></a></div><br />
<br />
<br />
<object height="300" width="400"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=10063929&server=vimeo.com&show_title=1&show_byline=1&show_portrait=0&color=&fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=10063929&server=vimeo.com&show_title=1&show_byline=1&show_portrait=0&color=&fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="400" height="300"></embed></object><br />
<a href="http://vimeo.com/10063929"></a><br />
<br />
<span style="font-size: large;"><i><b>** My Arduino Code **</b></i></span><br />
<div style="font-family: "Courier New",Courier,monospace;"><span style="color: #d0e0e3; font-size: x-small;"><br />
/*<br />
Reading Accelerometer & Pressure Sensor<br />
Language: Arduino/Wiring<br />
<br />
Reads 3 inputs attached to analog input pins 0 - 3 of the Arduino.<br />
The first two can be the accelerometer X & Y, and the third a <br />
potentiometer, or a pressure sensor.<br />
<br />
*/<br />
<br />
int accl_x = 0;<br />
int accl_y = 1;<br />
int sensor = 2;<br />
<br />
void setup() <br />
{ <br />
Serial.begin(9600); // initialize the serial port:<br />
}<br />
<br />
void loop() <br />
{<br />
int sensorReading;<br />
<br />
// read accelerometer X value<br />
sensorReading = analogRead(accl_x); <br />
sensorReading *= 10;<br />
Serial.print(sensorReading, DEC); // print its value out as an ASCII numeric string<br />
<br />
// print a comma after the last sensor<br />
Serial.print(",");<br />
<br />
// read accelerometer Y value<br />
sensorReading = analogRead(accl_y); <br />
sensorReading *= 10;<br />
Serial.print(sensorReading, DEC); // print its value out as an ASCII numeric string<br />
<br />
// print a comma after the last sensor<br />
Serial.print(",");<br />
<br />
// read sensor<br />
sensorReading = analogRead(sensor); <br />
Serial.print(sensorReading, DEC); // print its value out as an ASCII numeric string<br />
<br />
<br />
// after all the sensors have been read, <br />
// print a newline and carriage return<br />
Serial.println();<br />
delay (100);<br />
}</span></div><br />
<span style="font-size: large;"><i><b>** My Processing Code **</b></i></span><br />
<div style="font-family: "Courier New",Courier,monospace;"><span style="color: #d0e0e3; font-size: x-small;">/*<br />
Accelerometer <br />
Language: Processing<br />
<br />
This sketch takes ASCII values from the serial port <br />
at 9600 bps and maps them to screen coordinates.<br />
The values should be comma-delimited, with a newline <br />
at the end of every set of values.<br />
The expected range of the values is between 0 and 1023.<br />
<br />
Created 08 March 2010<br />
*/<br />
<br />
import processing.serial.*;<br />
Serial myPort; // The serial port<br />
<br />
PImage bg_img, mask_img;<br />
<br />
Animation animation;<br />
float xpos, ypos, oldx, oldy;<br />
float sensor;<br />
float drag = 30.0;<br />
<br />
int maxNumberOfSensors = 3;<br />
<br />
void setup () <br />
{<br />
// set up the window, background, framerate, and #of frames<br />
size(500, 500); <br />
background(0, 0, 20);<br />
bg_img = loadImage("background.png"); // Loading background image <br />
mask_img = loadImage("mask.png"); // Loading background image <br />
animation = new Animation("dragonfly_", 16);<br />
frameRate(24);<br />
<br />
// List all the available serial ports:<br />
println(Serial.list());<br />
// Opening port 8 (my COM port talking to the arduino)<br />
String portName = Serial.list()[1];<br />
myPort = new Serial(this, portName, 9600);<br />
myPort.clear();<br />
// don't generate a serialEvent() until you get a newline (\n) byte:<br />
myPort.bufferUntil('\n');<br />
<br />
xpos = oldx = width/2;<br />
ypos = oldy = height/2;<br />
}<br />
<br />
void draw () <br />
{<br />
// Display the sprite at the position xpos, ypos<br />
tint (sensor, 255); // setting the opacity of background<br />
image(bg_img, 0, 0);<br />
image(mask_img, xpos-(animation.getWidth()*4)+35, ypos-(animation.getHeight()*4)-70);<br />
<br />
tint (255, 255); // opacity of sprite always FULL<br />
animation.display(xpos-animation.getWidth()/2, ypos);<br />
}<br />
<br />
void serialEvent (Serial myPort) <br />
{ <br />
// get the ASCII string:<br />
String inString = myPort.readStringUntil('\n');<br />
<br />
// if it's not empty:<br />
if (inString != null) <br />
{<br />
// trim off any whitespace:<br />
inString = trim(inString);<br />
<br />
// convert to an array of ints:<br />
int incomingValues[] = int(split(inString, ","));<br />
<br />
if (incomingValues.length <= maxNumberOfSensors && incomingValues.length > 0) <br />
{<br />
{<br />
oldx = xpos;<br />
oldy = ypos;<br />
<br />
xpos = incomingValues[0]; // Accelerometer X<br />
ypos = incomingValues[1]; // Accelerometer Y<br />
sensor = incomingValues[2]; // Potentiometer Values<br />
<br />
// Setting coords range between incoming values<br />
xpos = (xpos > 5500 ? 5500 : xpos < 1500 ? 1500 : xpos);<br />
ypos = (ypos > 5500 ? 5500 : ypos < 1500 ? 1500 : ypos);<br />
<br />
// mapping incoming values to edges of screen<br />
xpos = map(xpos, 1500, 5500, 65, width-65);<br />
ypos = map(ypos, 1500, 5500, height-94, 0);<br />
// mapping incoming sensor values for tint() function<br />
sensor = map (sensor, 0, 480, 0, 255);<br />
}<br />
}<br />
<br />
// print out the values<br />
println(xpos + ", " + ypos + " ," + sensor);<br />
}<br />
}<br />
<br />
// Class for animating a sequence of PNG's<br />
class Animation <br />
{<br />
PImage[] images;<br />
int imageCount;<br />
int frame;<br />
<br />
Animation(String imagePrefix, int count) <br />
{<br />
imageCount = count;<br />
images = new PImage[imageCount];<br />
<br />
for (int i = 0; i < imageCount; i++) <br />
{<br />
// Use nf() to number format 'i' into 3 digits<br />
String filename = imagePrefix + nf(i, 3) + ".png";<br />
images[i] = loadImage(filename);<br />
}<br />
}<br />
<br />
void display(float xpos, float ypos) <br />
{<br />
frame = (frame+1) % imageCount;<br />
image(images[frame], xpos, ypos);<br />
}<br />
<br />
int getWidth() {<br />
return images[0].width; }<br />
int getHeight() {<br />
return images[0].height; }<br />
}<br />
</span></div>NMhttp://www.blogger.com/profile/03556991654093947404noreply@blogger.com2tag:blogger.com,1999:blog-8410140457122624973.post-74326415593530904772010-02-28T21:51:00.002-06:002016-02-13T18:08:16.693-06:00Ex: Temperature SensorThis circuit works like a thermostat. As soon as the temperature goes higher than the 'hi-threshold', the led lights up to let you know it's too hot.<br />
<br />
I tried using the alert bit to control the led at first. It didn't work too well, and very unpredictably. I doubt it even was working through the alert bit at all. So, for now it's just a brute force led turning up when the temperature goes higher than the value stored in the T_high register.<br />
<br />
<iframe src="https://player.vimeo.com/video/9820139" width="500" height="375" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe> <p><a href="https://vimeo.com/9820139">Ex: Temperature Sensor</a> from <a href="https://vimeo.com/user2369176">naureenm</a> on <a href="https://vimeo.com">Vimeo</a>.</p>
<a href="https://vimeo.com/9820139"></a><br />
<br />
<span style="color: #d0e0e3; font-size: small;"><span style="font-family: "courier new" , "courier" , monospace;">// ARDUINO CODE<br />
<br />
#include "wire.h" // (where " "=angled brackets)<br />
<br />
int led = 2;<br />
<br />
int ptrTemp = 0b00000000; // TMP102 register pointers<br />
int ptrConf = 0b00000001;<br />
int ptrTLow = 0b00000010;<br />
int ptrTHigh = 0b00000011;<br />
int i2cAddr; // used to set address on the chip <br />
<br />
void setup()<br />
{<br />
pinMode(led,OUTPUT);<br />
Serial.begin(9600);<br />
Wire.begin(); // join i2c bus (address optional for master)<br />
i2cAddr = 0b1001001; // ADD0 pin connection selects one of four possible addresses<br />
}<br />
<br />
void loop()<br />
{ <br />
// REQUESTING TEMPERATURES<br />
/* TEMPERATURE REGISTER <br />
*/<br />
Wire.beginTransmission(i2cAddr); // select temperature register<br />
Wire.send(ptrTemp); // (if only temperature is needed this can<br />
Wire.endTransmission(); // be done once in setup() )<br />
<br />
Wire.requestFrom(i2cAddr, 2); // request temperature<br />
byte byte1 = Wire.receive();<br />
byte byte2 = Wire.receive(); <br />
<br />
/* T_LOW REGISTER <br />
*/<br />
Wire.beginTransmission(i2cAddr); // select temperature register<br />
Wire.send(ptrTLow);<br />
Wire.send(24); // (if only temperature is needed this can<br />
Wire.endTransmission(); // be done once in setup() )<br />
<br />
Wire.requestFrom(i2cAddr, 2); // request temperature<br />
byte lowbyte1 = Wire.receive();<br />
byte lowbyte2 = Wire.receive(); <br />
<br />
/* T_High REGISTER <br />
*/<br />
Wire.beginTransmission(i2cAddr); // select temperature register<br />
Wire.send(ptrTHigh); <br />
Wire.send(28); // (if only temperature is needed this can<br />
Wire.endTransmission(); // be done once in setup() )<br />
<br />
Wire.requestFrom(i2cAddr, 2); // request temperature<br />
byte hibyte1 = Wire.receive();<br />
byte hibyte2 = Wire.receive(); <br />
<br />
// CALCULATING TEMPERATURES<br />
int tempint = byte1 << 8; // shift first byte to high byte in an int<br />
tempint = tempint | byte2; // or the second byte into the int<br />
tempint = tempint >> 4; // right shift the int 4 bits per chip doc<br />
float tempflt = float( tempint ) * .0625; // calculate actual temperature per chip doc<br />
<br />
// Low_temp <br />
int lowtempint = lowbyte1 << 8; // shift first byte to high byte in an int<br />
lowtempint = lowtempint | lowbyte2; // or the second byte into the int<br />
lowtempint = lowtempint >> 4; // right shift the int 4 bits per chip doc<br />
float lowtempflt = float( lowtempint ) * .0625; // calculate actual temperature per chip doc<br />
<br />
// Hi_temp<br />
int hitempint = hibyte1 << 8; // shift first byte to high byte in an int<br />
hitempint = hitempint | hibyte2; // or the second byte into the int<br />
hitempint = hitempint >> 4; // right shift the int 4 bits per chip doc<br />
float hitempflt = float( hitempint ) * .0625; // calculate actual temperature per chip doc<br />
<br />
<br />
// PRINTING TEMPERATURES<br />
Serial.print( "Temp: C = ");<br />
Serial.print( int( tempflt ) );<br />
int tempF = (tempflt * 9/5) + 32;<br />
Serial.print( " F = ");<br />
Serial.print( int( tempF ) );<br />
<br />
Serial.print( " Low: C = ");<br />
Serial.print( int( lowtempflt ) );<br />
int lowF = (lowtempflt * 9/5) + 32;<br />
Serial.print( " F = ");<br />
Serial.print( int( lowF ) );<br />
<br />
Serial.print( " Hi: C = ");<br />
Serial.print( int( hitempflt ) );<br />
int hiF = (hitempflt * 9/5) + 32;<br />
Serial.print( " F = ");<br />
Serial.println( int( hiF ) );<br />
<br />
<br />
// LIGHTING UP THE LED IF TOO HOT<br />
if ( tempflt > hitempflt )<br />
digitalWrite(led,HIGH);<br />
else<br />
digitalWrite(led,LOW);<br />
<br />
delay(500);<br />
}<br />
</span></span>NMhttp://www.blogger.com/profile/03556991654093947404noreply@blogger.com2tag:blogger.com,1999:blog-8410140457122624973.post-60041862557967845872010-02-19T21:08:00.000-06:002010-02-23T05:05:06.506-06:00Ex: Rock_Paper_Scissor w/ Arduinos ConnectedArduinos connected through serial connections. Using RGB in place of rock, paper and scissor.<br />
<br />
R beats G<br />
G beats B<br />
B beats R<br />
<br />
-------- ARDUINO CODE -------------<br />
<br />
<span style="font-size: small;"><div style="color: #d0e0e3; font-family: "Courier New",Courier,monospace;"> int RxPin = 0;<br />
int TxPin = 1;<br />
<br />
int button1Pin = 2; // select the input pin for the potentiometer<br />
int button2Pin = 4;<br />
<br />
int p1color = -1;<br />
int b1currState = 0;<br />
int b1prevState = 0;<br />
<br />
int b2count = 0;<br />
int b2currState = 0;<br />
int b2prevState = 0;<br />
<br />
int ledPin1 = 11;<br />
int ledPin2 = 10;<br />
int ledPin3 = 9;<br />
<br />
int ledWinPin = 5;<br />
int ledLosPin = 6; <br />
<br />
boolean hold = true;<br />
int checkbit = 0;<br />
int p2color = -1;<br />
<br />
void setup() { <br />
pinMode(button1Pin, INPUT);<br />
pinMode(button2Pin, INPUT);<br />
<br />
pinMode(ledPin1, OUTPUT);<br />
pinMode(ledPin2, OUTPUT);<br />
pinMode(ledPin3, OUTPUT);<br />
<br />
pinMode(ledWinPin, OUTPUT);<br />
pinMode(ledLosPin, OUTPUT);<br />
<br />
// pinMode(RxPin, INPUT);<br />
// pinMode(TxPin, OUTPUT);<br />
<br />
Serial.begin(9600);<br />
}<br />
<br />
<br />
void loop() <br />
{<br />
b1currState = digitalRead(button1Pin);<br />
b2currState = digitalRead(button2Pin);<br />
<br />
/* STEP 1: CHOOSING WHICH COLOR<br />
0 = nothing - cannot send when LED is in this state<br />
1 = R<br />
2 = G<br />
3 = B <br />
*/<br />
// getting input from the RGB LED button<br />
// to learn which LED is chosen <br />
// and saaving the chosen color in p1color<br />
<br />
if (b1currState != b1prevState) <br />
{<br />
if (b1currState == HIGH) <br />
{<br />
if (p1color == 2) p1color = 0;<br />
else p1color++;<br />
Serial.print("RGB LED state: ");<br />
Serial.println(p1color, DEC);<br />
}<br />
b1prevState = b1currState; <br />
delay (100); <br />
} <br />
<br />
if (p1color == 0)<br />
{<br />
digitalWrite(ledPin1, LOW);<br />
digitalWrite(ledPin2, LOW);<br />
digitalWrite(ledPin3, HIGH);<br />
} else <br />
if (p1color == 1) <br />
{<br />
digitalWrite(ledPin1, LOW);<br />
digitalWrite(ledPin2, HIGH);<br />
digitalWrite(ledPin3, LOW);<br />
} else <br />
if (p1color == 2) <br />
{<br />
digitalWrite(ledPin1, HIGH); <br />
digitalWrite(ledPin2, LOW);<br />
digitalWrite(ledPin3, LOW);<br />
}else<br />
{<br />
digitalWrite(ledPin1, LOW); <br />
digitalWrite(ledPin2, LOW);<br />
digitalWrite(ledPin3, LOW);<br />
}<br />
<br />
/* STEP 2: SENDING CHOSEN COLOR TO OTHER PLAYER<br />
*/<br />
if (b2currState != b2prevState) <br />
{<br />
if (b2currState == HIGH) <br />
{<br />
Serial.print("Sending state = "); Serial.print(p1color, DEC);<br />
Serial.println(" to other player's Arduino...");<br />
<br />
// digitalWrite(TxPin, 3);<br />
// digitalWrite(TxPin, p1color);<br />
<br />
Serial.write(255);<br />
Serial.write(p1color);<br />
}<br />
b2prevState = b2currState; <br />
delay(100); <br />
} <br />
<br />
<br />
/* STEP 3: HOLDING UNTIL COLOR RECEIVED <br />
FROM OTHER PLAYER<br />
*/<br />
if (Serial.available())<br />
{<br />
// p2color = digitalRead(RxPin); //Serial.read();<br />
p2color = Serial.read();<br />
<br />
if (!hold)<br />
{ <br />
if ( (p1color == 0 && p2color == 1) <br />
||(p1color == 1 && p2color == 2) <br />
||(p1color == 2 && p2color == 0) )<br />
{<br />
digitalWrite(ledWinPin,HIGH);<br />
digitalWrite(ledLosPin,LOW);<br />
}<br />
else <br />
if (p2color == p1color)<br />
{<br />
digitalWrite(ledWinPin,HIGH);<br />
digitalWrite(ledLosPin,HIGH);<br />
}<br />
else<br />
{<br />
digitalWrite(ledWinPin,LOW);<br />
digitalWrite(ledLosPin,HIGH);<br />
}<br />
<br />
delay (20000);<br />
<br />
// resetting after some time<br />
hold = true; <br />
p2color = -1;<br />
digitalWrite(ledWinPin,LOW);<br />
digitalWrite(ledLosPin,LOW);<br />
}<br />
<br />
if (p2color == 255) //255<br />
hold = false; <br />
}<br />
}<br />
</div></span><br />
<br />
<br />
<br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh9dFhuTvsCX3dC1hL96AX6gZ8mwLaVZ_4c9ivwnXONs4mSCqzul9dNEylePGLhHoPb7CaEaQGO_myxuVxbvxwtNswc8AKCpkjB3_UJX9ROoltm7fS-weQYRyXD-umHBOej9Bc7S6OjAkE/s1600-h/IMG_1753.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh9dFhuTvsCX3dC1hL96AX6gZ8mwLaVZ_4c9ivwnXONs4mSCqzul9dNEylePGLhHoPb7CaEaQGO_myxuVxbvxwtNswc8AKCpkjB3_UJX9ROoltm7fS-weQYRyXD-umHBOej9Bc7S6OjAkE/s320/IMG_1753.JPG" /></a><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjMhPUrrJwGKUnruJLKMn8YOX_pHmiQzYM5LDzakQV-hljnAZZNvVAVWwzAh9-DuYFfTjqDjFSIdC28vlh4cW6xeiZEtUIk_perCQz1X7Hy6SPCWwCUz8Pt7UQvAZwquTCj34U5DC7LO3I/s1600-h/IMG_1757.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjMhPUrrJwGKUnruJLKMn8YOX_pHmiQzYM5LDzakQV-hljnAZZNvVAVWwzAh9-DuYFfTjqDjFSIdC28vlh4cW6xeiZEtUIk_perCQz1X7Hy6SPCWwCUz8Pt7UQvAZwquTCj34U5DC7LO3I/s320/IMG_1757.JPG" /></a><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgtW9LcwAQazTYCsr8mtbsHj5HWyCzVpycsmeEsxg0dbsN6oLMxQOEpJLXgkcZVWHiHH6KYxWVI3cfNQlPF-Dd0dpBaxHY0y43t2iB9Ad8gMWSh5U7ZH7SCTpNGDZa_NHf0j9dor6keLGE/s1600-h/IMG_1756.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgtW9LcwAQazTYCsr8mtbsHj5HWyCzVpycsmeEsxg0dbsN6oLMxQOEpJLXgkcZVWHiHH6KYxWVI3cfNQlPF-Dd0dpBaxHY0y43t2iB9Ad8gMWSh5U7ZH7SCTpNGDZa_NHf0j9dor6keLGE/s320/IMG_1756.JPG" /></a></div><br />
<br />
<br />
<object height="300" width="400"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=9571936&server=vimeo.com&show_title=1&show_byline=1&show_portrait=0&color=&fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=9571936&server=vimeo.com&show_title=1&show_byline=1&show_portrait=0&color=&fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="400" height="300"></embed></object><br />
<a href="http://vimeo.com/9571936"></a><br />
<a href="http://vimeo.com/9571936"></a>NMhttp://www.blogger.com/profile/03556991654093947404noreply@blogger.com0tag:blogger.com,1999:blog-8410140457122624973.post-28598240238251226812010-02-18T14:46:00.000-06:002010-02-18T22:29:54.328-06:00Ex: Blinker / Dimmer in Serial Connection<div class="separator" style="clear: both; text-align: center;"></div><div class="separator" style="clear: both; text-align: center;"></div><div class="separator" style="clear: both; text-align: center;"></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiNBZ2xpZxEjM4e50N-mxiZIC6Gw6z2jvehxozbrsfRvEVMQyrnEFjjPpcEYHEoLoU2kkG01xbgvtGIISt3H-m4R7r5Zgqep469UUJCZ_s9RRYQH1rSpBRoekxMpiLLbHjzxXSuk3bXkOI/s1600-h/IMG_1752.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiNBZ2xpZxEjM4e50N-mxiZIC6Gw6z2jvehxozbrsfRvEVMQyrnEFjjPpcEYHEoLoU2kkG01xbgvtGIISt3H-m4R7r5Zgqep469UUJCZ_s9RRYQH1rSpBRoekxMpiLLbHjzxXSuk3bXkOI/s320/IMG_1752.JPG" /></a></div><br />
<object height="300" width="400"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=9563318&server=vimeo.com&show_title=1&show_byline=1&show_portrait=0&color=&fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=9563318&server=vimeo.com&show_title=1&show_byline=1&show_portrait=0&color=&fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="400" height="300"></embed></object><br />
<br />
<br />
<span style="font-size: large;"><b>The Arduino Code:</b></span><br />
<div style="font-family: "Courier New",Courier,monospace;"><br />
<span style="font-size: small;"><br />
<span style="color: #d0e0e3;"> const int ledPin = 9; // pin that the LED is attached to<br style="color: #d0e0e3;" /> byte brightness = 0;<br />
byte blink_rate = 0;<br />
byte checkbit = 0;<br />
<br />
int state = 0;<br />
<br />
int ledState = LOW; // to store LED states<br />
long previousMillis = 0; // to store last time LED was updated<br />
<br />
<br />
void setup()<br />
{<br />
// initialize the serial communication:<br />
Serial.begin(9600);<br />
// initialize the ledPin as an output:<br />
pinMode(ledPin, OUTPUT);<br />
}<br />
<br />
void loop() <br />
{<br />
unsigned long currentMillis = millis();<br />
<br />
// check if data has been sent from the computer:<br />
if (Serial.available()) <br />
{<br />
// read the most recent byte (from 0 to 255):<br />
checkbit = Serial.read();<br />
if (state == 2)<br />
{<br />
blink_rate = checkbit;<br />
state = 3;<br />
}<br />
if (state == 1)<br />
{<br />
brightness = checkbit; <br />
state = 2;<br />
}<br />
if (checkbit == 255) <br />
{<br />
state = 1;<br />
}<br />
} <br />
<br />
<br />
if(currentMillis - previousMillis > blink_rate)<br />
{<br />
// save the last time you blinked the LED <br />
previousMillis = currentMillis; <br />
// if the LED is off turn it on and vice-versa:<br />
if (ledState == LOW)<br />
{<br />
ledState = HIGH;<br />
analogWrite(ledPin, brightness);<br />
}<br />
else<br />
{<br />
ledState = LOW;<br />
analogWrite(ledPin, 0);<br />
}<br />
}<br />
}</span></span></div><br />
........................................................................................<br />
<span style="font-size: large;"><b>Processing code:</b></span><br />
<br />
<span style="font-size: small;"><br />
</span><br />
<div style="font-family: "Courier New",Courier,monospace;"><span style="font-size: small;"> import processing.serial.*;</span><br />
<span style="font-size: small;"> Serial port;</span><br />
<span style="font-size: small;">// byte start;</span><br />
<span style="font-size: small;"> </span><br />
<span style="font-size: small;"> void setup()</span><br />
<span style="font-size: small;"> {</span><br />
<span style="font-size: small;"> size(254, 150);</span><br />
<span style="font-size: small;"> </span><br />
<span style="font-size: small;"> println("Available serial ports:");</span><br />
<span style="font-size: small;"> println(Serial.list());</span><br />
<span style="font-size: small;"> </span><br />
<span style="font-size: small;"> // Uses the second port in this list (number 1). </span><br />
<span style="font-size: small;"> port = new Serial(this, Serial.list()[1], 9600); </span><br />
<span style="font-size: small;"> }</span><br />
<span style="font-size: small;"> </span><br />
<span style="font-size: small;"> void draw()</span><br />
<span style="font-size: small;"> {</span><br />
<span style="font-size: small;"> // draw a gradient from black to white</span><br />
<span style="font-size: small;"> for (int i = 0; i < 254; i++) {</span><br />
<span style="font-size: small;"> stroke(i);</span><br />
<span style="font-size: small;"> line(i, 0, i, 150);</span><br />
<span style="font-size: small;"> }</span><br />
<span style="font-size: small;"> </span><br />
<span style="font-size: small;"> // write the current X & Y-position of the mouse to the</span><br />
<span style="font-size: small;"> // serial port as a single byte</span><br />
<span style="font-size: small;"><br />
</span><br />
<span style="font-size: small;"><br />
</span><br />
<span style="font-size: small;"> port.write(255); </span><br />
<span style="font-size: small;"> port.write(mouseX); println("X: " + mouseX); </span><br />
<span style="font-size: small;"> port.write(mouseY); println("Y: " + mouseY);</span><br />
<span style="font-size: small;"> }</span><br />
<span style="font-size: small;"> </span></div><span style="font-size: small;"></span>NMhttp://www.blogger.com/profile/03556991654093947404noreply@blogger.com0tag:blogger.com,1999:blog-8410140457122624973.post-91930469343354252742010-02-12T11:43:00.000-06:002010-02-18T22:29:16.050-06:00Ex: Sensor / Actuator WalkI took these images walking around between the Computer Science, Architecture and Visualization buildings:<br />
<br />
Tap / Swipe Credit card to pay. The machine recognizes certain credit cards which can be tappedinstead of swiped to make payments. <br />
<br />
<div class="separator" style="clear: both; text-align: center;"></div><div class="separator" style="clear: both; text-align: center;"></div><div class="separator" style="clear: both; text-align: center;"></div><br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEicohjoQY3YNMyofvUFTf9mohVamNWSW3997dbnfCAnijIsNkIG4ozsjpwRtLaGdajHTOtkrjtkdr2jYzgdf-4gBdZMXfiuZF9S4R9yfWTG9VL-s14Iafmp9bIPW-mbliGebfv6ESctFys/s1600-h/image009.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEicohjoQY3YNMyofvUFTf9mohVamNWSW3997dbnfCAnijIsNkIG4ozsjpwRtLaGdajHTOtkrjtkdr2jYzgdf-4gBdZMXfiuZF9S4R9yfWTG9VL-s14Iafmp9bIPW-mbliGebfv6ESctFys/s320/image009.jpg" /></a></div><br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj1kqqbNWjXKmoyZ4OEEduHqUAVz5YG85IkC4O9J4eVGLLBAJcPshR4RvY_LZPWfG0q2m4sjH6XCAceigp1aB-HpnXdTow2mumk5FK_0fXsEMipi4HclZ5Rql2M5ffcnz635kWjTPNh638/s1600-h/image010.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj1kqqbNWjXKmoyZ4OEEduHqUAVz5YG85IkC4O9J4eVGLLBAJcPshR4RvY_LZPWfG0q2m4sjH6XCAceigp1aB-HpnXdTow2mumk5FK_0fXsEMipi4HclZ5Rql2M5ffcnz635kWjTPNh638/s320/image010.jpg" /></a></div><br />
Automatic-Doors (Motion sensors):<br />
<div class="separator" style="clear: both; text-align: center;"></div><br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgD3fBXuW8E9vokoUU_19QW761gY-k2chv-Z5ULPdJ89QENwWicwIt0FTYRws3CL8JYNMle2A2cS7UG-s7KmG_5w-GJfLmtbldrPnUHHaUnyNy2yOpl-6hJRIXLtypWCjJmIf8M86JkIA0/s1600-h/image008.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgD3fBXuW8E9vokoUU_19QW761gY-k2chv-Z5ULPdJ89QENwWicwIt0FTYRws3CL8JYNMle2A2cS7UG-s7KmG_5w-GJfLmtbldrPnUHHaUnyNy2yOpl-6hJRIXLtypWCjJmIf8M86JkIA0/s320/image008.jpg" /></a></div><div class="separator" style="clear: both; text-align: center;"></div><div class="separator" style="clear: both; text-align: center;"></div><div class="separator" style="clear: both; text-align: center;"></div><div class="separator" style="clear: both; text-align: center;"></div><div class="separator" style="clear: both; text-align: center;"></div><div class="separator" style="clear: both; text-align: center;"></div><div class="separator" style="clear: both; text-align: center;"></div><br />
<br />
Card-Reader with a timed-unlock mechanism, and a button to automatically open the door (also timed):<br />
<div><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi1QGad8eQ0QR0E4vaTtjlt9I_5J570BeZ2YkrYXR8sFmReWVlTgG400MSxKGOx8eXFB5B8m1EAWAWvtkzMfveV0ZUM6GrVI14V0pIsj7QiW_UbRhaaAIrxsx7C1AnGqYCr261RxL8b5KU/s1600-h/image005.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi1QGad8eQ0QR0E4vaTtjlt9I_5J570BeZ2YkrYXR8sFmReWVlTgG400MSxKGOx8eXFB5B8m1EAWAWvtkzMfveV0ZUM6GrVI14V0pIsj7QiW_UbRhaaAIrxsx7C1AnGqYCr261RxL8b5KU/s320/image005.jpg" /></a><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiP8U86RMzMSga3IgqOsKDqPJaYm2LrPHb9A620zLw3fwI3tyZdGClsE406eofkbvIDTd6dDAtu-OAdm8XVArP2rE_s_bFMqD35LufthfnZiq8ah7i38P55qO7LpLSBAAQ5ZjDFJ97hQXY/s1600-h/image004.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiP8U86RMzMSga3IgqOsKDqPJaYm2LrPHb9A620zLw3fwI3tyZdGClsE406eofkbvIDTd6dDAtu-OAdm8XVArP2rE_s_bFMqD35LufthfnZiq8ah7i38P55qO7LpLSBAAQ5ZjDFJ97hQXY/s320/image004.jpg" /></a></div><br />
<br />
<div><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhcJULqkrWUX7iCG5MhK4FYiKQfESRLpgZKH_ElonYZJmupLKjsvbCMPB-mXu5W2e6R-brNbG-9eYwyeGdzGOCnsp2ABYTS3F4HNw3-_aKelcNNf57IEswl_4fDUxpJqYeVJpvNI8BNjUM/s1600-h/image006.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhcJULqkrWUX7iCG5MhK4FYiKQfESRLpgZKH_ElonYZJmupLKjsvbCMPB-mXu5W2e6R-brNbG-9eYwyeGdzGOCnsp2ABYTS3F4HNw3-_aKelcNNf57IEswl_4fDUxpJqYeVJpvNI8BNjUM/s320/image006.jpg" /> </a><br />
<br />
Bill-reader, starts pulling a bill inside if it senses the right amount of a dollar bill being slipped into the reader.<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj8qcLipaALBQLSswRoI-jGa1FxbQIXRYwJq3XxQsKPf8_hBfl6l56v8yyvY6ecbthcEKh0BEJWVJ-PpjiNM4iBinXEeLbEwYe-jvuY7Cm9Sqaieh_Y8jfIxtrH2PqEqNVzT78TA_SVqDA/s1600-h/image001.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj8qcLipaALBQLSswRoI-jGa1FxbQIXRYwJq3XxQsKPf8_hBfl6l56v8yyvY6ecbthcEKh0BEJWVJ-PpjiNM4iBinXEeLbEwYe-jvuY7Cm9Sqaieh_Y8jfIxtrH2PqEqNVzT78TA_SVqDA/s320/image001.jpg" /></a></div><br />
Motion-sensor Automatic Dispensers: <br />
<div><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhu9_Uq3yU8EklkM08UFKoU-vBQPQLP6UGsozzLdaBNi-0Unyh-O1vs8OJsykDAe_b0KGuMKTS15hgIDMkWnL3BUjWnRIZ4a-ivS4GPUEl1gxeYfznAyLWztV9groNdiLIo71qrc_OlpQw/s1600-h/image002.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhu9_Uq3yU8EklkM08UFKoU-vBQPQLP6UGsozzLdaBNi-0Unyh-O1vs8OJsykDAe_b0KGuMKTS15hgIDMkWnL3BUjWnRIZ4a-ivS4GPUEl1gxeYfznAyLWztV9groNdiLIo71qrc_OlpQw/s320/image002.jpg" /></a><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhY7Qh-CgEmsEHoMjFKXv54DhK4oxTYvzTpkZCVrvtni_AUUFqq_TKQTG64eBHQgN7V87ffdMW4id_TgJ4532CspFrjJa1rHUQhRJgc3vnY-OFixkVhW1dIR-ufQ1QK4tpx_t_pnfD22nA/s1600-h/image007.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhY7Qh-CgEmsEHoMjFKXv54DhK4oxTYvzTpkZCVrvtni_AUUFqq_TKQTG64eBHQgN7V87ffdMW4id_TgJ4532CspFrjJa1rHUQhRJgc3vnY-OFixkVhW1dIR-ufQ1QK4tpx_t_pnfD22nA/s320/image007.jpg" /></a></div><br />
<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgAWpZUr84MHq3qbzSAf01kI_gMqPntBBo79mxli6fxcdgz4uxvIcyb37Tr11Mw4Qcdx97cYrFrKurc0VWOMFLkQcvBSMTRpVOIfjHgDDLChjhItsvu8sZgKeWs5Bo3dnzQeOamToeVDAQ/s1600-h/image003.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgAWpZUr84MHq3qbzSAf01kI_gMqPntBBo79mxli6fxcdgz4uxvIcyb37Tr11Mw4Qcdx97cYrFrKurc0VWOMFLkQcvBSMTRpVOIfjHgDDLChjhItsvu8sZgKeWs5Bo3dnzQeOamToeVDAQ/s320/image003.jpg" /></a>NMhttp://www.blogger.com/profile/03556991654093947404noreply@blogger.com0tag:blogger.com,1999:blog-8410140457122624973.post-92066682256982277912010-02-09T16:12:00.000-06:002010-02-18T22:29:31.470-06:00Ex: Push-button LED statesI kept having a problem with the push-buttons while working on the exercise. The circuit was pretty simple/fast to set up but, the coding didn't seem to be perfect for quite some time. The button pushes were being recognized and read properly by the program but, they weren't corresponding to the events assigned to them. I realized that was probably due to the button bouncing.<br />
<br />
De-bouncing: I added/edited/re-edited and then finally removed the de-bouncing code in attempts to fix the problem. Adding the de-bouncing code just made the system become much slower (it wouldn't start recognizing button-pushes until several minutes after the code had finished uploading).<br />
Eventually, I just added a 'delay(100)' at the end of the code.Which appeared to work very good as a de-bouncer, at least for this program! ..it might not be the best way to go about it but, it's working for me for now.<br />
<br />
Then I also went ahead and added additional effects to the states of each button-push-event:<br />
0 pushes: no lights<br />
1 push: green light with slow blinking<br />
2 pushes: blue light with faster blinks<br />
3 pushes: red light blinking very fast<br />
<br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQJnd6FoC6hvytAi0gKz0V5oxMVeRdWwOc73uws1yD2MpNBG7dy8ouqmXdv3AoXFFCCeF6Q627_U_r1FPxYxfhF0AyfvWahUzoCJhDVCAlQwAS31MVUjbGhK0yhEhj_FusG1eQDKZBPg4/s1600-h/image002.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQJnd6FoC6hvytAi0gKz0V5oxMVeRdWwOc73uws1yD2MpNBG7dy8ouqmXdv3AoXFFCCeF6Q627_U_r1FPxYxfhF0AyfvWahUzoCJhDVCAlQwAS31MVUjbGhK0yhEhj_FusG1eQDKZBPg4/s320/image002.jpg" /></a><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikD5bz-JfYKC0oz0mA3n9DcSBx7FP8Uko4gnBLkKg7oqEzoTiJRcKnkQz4mDUVGcRmE_Ivoy-bG7aJvaH13wmN3dTJgxRL3glXni_9ET9sRpst1hlbIxC6E0oX0lCrmrskodnmUWNXq7U/s1600-h/image003.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikD5bz-JfYKC0oz0mA3n9DcSBx7FP8Uko4gnBLkKg7oqEzoTiJRcKnkQz4mDUVGcRmE_Ivoy-bG7aJvaH13wmN3dTJgxRL3glXni_9ET9sRpst1hlbIxC6E0oX0lCrmrskodnmUWNXq7U/s320/image003.jpg" /></a></div><br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhf1DbWTGGvBdr25ClYhD5xX-J2e-57-Ki4AY71BGZhUZ1_9jKeYebisvvnIlciYOjMWKEVNBnAFBDdJayqJdoS5apOYXqiI1qd2bcL1A0-V4VERBy1BBtV8dNJQDMXC04xrTvadQI9mdg/s1600-h/image001.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhf1DbWTGGvBdr25ClYhD5xX-J2e-57-Ki4AY71BGZhUZ1_9jKeYebisvvnIlciYOjMWKEVNBnAFBDdJayqJdoS5apOYXqiI1qd2bcL1A0-V4VERBy1BBtV8dNJQDMXC04xrTvadQI9mdg/s320/image001.jpg" /></a></div><br />
<object width="400" height="300"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=9563633&server=vimeo.com&show_title=1&show_byline=1&show_portrait=0&color=&fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=9563633&server=vimeo.com&show_title=1&show_byline=1&show_portrait=0&color=&fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="400" height="300"></embed></object><br />
<br />
MAIN LOOP AREA PRINTED BELOW:<br />
------------------------------<br />
<br />
<span style="color: #76a5af; font-size: small;"><span style="font-family: "Courier New",Courier,monospace;"><br />
void loop() <br />
{<br />
currState = digitalRead(buttonPin);<br />
<br />
// compare the currState to its previous state<br />
if (currState != prevState) <br />
{<br />
if (currState == HIGH) <br />
{<br />
if (count == 3) count = 0;<br />
else count++;<br />
Serial.print("number of button pushes: ");<br />
Serial.println(count, DEC);<br />
}<br />
prevState = currState; <br />
} <br />
<br />
if (count == 1) <br />
{<br />
digitalWrite(ledPin1, LOW);<br />
digitalWrite(ledPin2, LOW);<br />
digitalWrite(ledPin3, 50);<br />
delay(100); // wait for a second<br />
digitalWrite(ledPin3, LOW); // set the LED off<br />
delay(100); // wait for a second<br />
} else <br />
if (count == 2) <br />
{<br />
digitalWrite(ledPin1, LOW);<br />
digitalWrite(ledPin3, LOW);<br />
digitalWrite(ledPin2, 50);<br />
delay(50); // wait for a second<br />
digitalWrite(ledPin2, LOW); // set the LED off<br />
delay(50);<br />
} else <br />
if (count == 3) <br />
{<br />
digitalWrite(ledPin2, LOW);<br />
digitalWrite(ledPin3, LOW);<br />
digitalWrite(ledPin1, 50);<br />
delay(10); // wait for a second<br />
digitalWrite(ledPin1, LOW); // set the LED off<br />
delay(10); <br />
<br />
} else <br />
{<br />
digitalWrite(ledPin1, LOW);<br />
digitalWrite(ledPin2, LOW);<br />
digitalWrite(ledPin3, LOW); <br />
}<br />
<br />
delay (100);<br />
}<br />
</span></span>NMhttp://www.blogger.com/profile/03556991654093947404noreply@blogger.com0tag:blogger.com,1999:blog-8410140457122624973.post-74721607700604543312010-02-09T05:40:00.000-06:002010-02-09T05:40:41.981-06:00Proj 1: (Updated) The Weather ManThe idea is to have a painting of an animated character on an LCD digital frame (like the ones used as picture frames for displaying digital picture slide-shows). This picture frame is to be hung inside a house as art. The animations of the character are controlled and changed depending on input received from a few wireless sensors outside the house.<br />
<br />
<br />
Input will be received from a temperature sensor, humidity / precipitation sensor, and a wind pressure sensor:<br />
<ol><li>Temperature would affect the character's mood (happy at moderate temperatures, sad or very sad at extreme cold or hot temperatures), his clothes (suiting the weather outside) and actions (fanning self when it's too hot, or shivering in extreme cold). </li>
<li>Precipitation or humidity will result in the character pulling out an umbrella on a rainy day.</li>
<li>Wind pressure would show the character trying not to blow away in a heavy wind when there is high winds outdoors.</li>
</ol>The piece will be meant solely for weather information that can be always available to anyone within a room in the form of an interesting looking art animated piece of art on the wall. The animation will continue changing throughout the day depending on the temperature. And when the temperature becomes stable for some time, the animation will be limited to the character just blinking and shifting on his feet or looking around at the corners of the frame.NMhttp://www.blogger.com/profile/03556991654093947404noreply@blogger.com0tag:blogger.com,1999:blog-8410140457122624973.post-89443108671007857672010-02-02T16:00:00.000-06:002010-02-02T16:00:41.196-06:00Proj 1: Temperature/Light Controlled Animated PaintingThe basic idea is to have a simple image of a field/landscape displayed in a frame on a wall. The frame is connected to a couple of sensors outdoors that gauge the temperature and the light intensity outdoors.<br />
<br />
<u>Temperature Sensor:</u><br />
Depending on what the temperature is like outside, the landscape will transform into something like a desert (at hi temperatures), or becomes very green with plants and trees to depicts spring (at mi-range temperatures), or transforms into a cold / snow-filled landscape (at very low temperatures). <br />
<br />
<u>Light Sensor:</u><br />
The painting also depicts day and night depending on whether there's any light outside or not. I don't know if it can accurately measure differences in light-intensity if the sky is overcast etc. but, if so, that would be a welcome addition too.<br />
<br />
<b><br />
</b><br />
<b>More sensors that can be added: </b><br />
<u>Humidity:</u><br />
With a sensor for humidity added to the system, there can be an additional animation of rain or snow (depending on the temperature) in the painting.<br />
<br />
<u>Air pressure:</u><br />
With a sensor for air pressure added, the system could also display something like a storm, windy day etc. NMhttp://www.blogger.com/profile/03556991654093947404noreply@blogger.com0tag:blogger.com,1999:blog-8410140457122624973.post-18083378577728793692010-01-26T03:12:00.000-06:002010-01-26T03:32:41.712-06:00Hello WorldI am a graduate student in the Visualization Department. I am interested in working on game design/development as well as visual effects. I had been a computer science student in my undergrad and am more interested in the programming/scripting aspect of visualization and especially in interactive systems.<br />
<br />
For my thesis I am currently working on creating a game design framework for specific learning needs in educational games / interactive programs etc. For the same reason, I am also interested in physical systems that can be used to form a mode of basic learning through interaction between humans and the machine.<br />
<br />
<br />
A few links I like:<br />
1. <a href="http://web.media.mit.edu/%7Ecynthiab/outreach/outreach.html">http://web.media.mit.edu/~cynthiab/outreach/outreach.html</a><br />
The main page of Cynthia Brezeal, the creator of first emotion-exhibiting robot, 'Kismet' (<a href="http://www.ai.mit.edu/projects/humanoid-robotics-group/kismet/">http://www.ai.mit.edu/projects/humanoid-robotics-group/kismet/</a>). All her projects and work by the department on this page are very interesting to keep up with.<br />
<br />
2. <a href="http://beatbots.net/">http://beatbots.net/</a><br />
How a simple interactive robot design can become a tool for helping children's social development.<br />
<br />
3. <a href="http://www.xbox.com/en-US/live/projectnatal/">http://www.xbox.com/en-US/live/projectnatal/</a><br />
I'm really interested in finding out more about Xbox's Project Natal - how it will work and when they'll be releasing the new console with all the features mentioned on this site. <br />
<br />
4. <a href="http://faculty.css.edu/tgibbons/Gamemaker_Tutorials/Gamemaker_Tutorials.html">http://faculty.css.edu/tgibbons/Gamemaker_Tutorials/Gamemaker_Tutorials.html</a> / <a href="http://www.udk.com/download">http://www.udk.com/download</a><br />
These are both free game developing tools; the first, a very basic start-up game development program, and the second, a complex game engine which recently became available for free download, and has been used for several RPG's, MMO's as well as stealth games till now.<br />
<br />
5. <a href="http://projecteuler.net/">http://projecteuler.net/</a><br />
I try a problem or two every now and then from this site.NMhttp://www.blogger.com/profile/03556991654093947404noreply@blogger.com0