Step 1: The Original Plan: PIR Sensor
Step 2: Plan B: Makeshift Motion Sensor
I realized I could use this to make a makeshift motion sensor out of a photocell. Casting a shadow over the sensor could serve as my touch-free button, and my wet hands would go nowhere near my computer.
Step 3: Materials
- Any OS that can run Arduino should work, but I used a Mac, and my instructions will be written for Macs
- I used a Duemilanove
• Photocell Light Sensor
• 10K Resistor
• Jumper Wire, Breadboard
Step 4: Assemble the Circuit
I had a rather complicated R & D period for this project; I had many issues throughout the process. Originally, I worried about using the circuit in varying light environments. My solution was to have a setup period built into the code, allowing the user to calibrate the sensor to the environment before they actually use it. This calibration process was built into the code, and ended up being far too complicated for my meager coding skills to handle. So I realized I had to scale back my plans to a far simpler model.
Step 5: Software - Arduino Code
Step by Step Process:
1. Upload the code to the Arduino. Open the serial monitor.
2. The photocell should be printing values to the serial monitor. If you hover a shadow over the photocell, you'll notice a decrease in these printed values.
3. Replace the values for the shadow and noshadow variables. Use a number 5-10 units less than the observed high light condition values for the noshadow variable (i.e. if you observed values of 160, use 150 or so). Use a number 5-10 units greater than the observed low light condition for the shadow variable (i.e. if you observed values of 40, use 50 or so). This should ensure that you avoid false positives and that every shadow is registered as such.
5. Comment out the Serial.println(amblightlvl) line, as it is only there to help the user set up their code.
4. Reupload the code.
Step 6: Software - Computer Code
There are several options to give the Arduino the ability to interact with computer applications. I've chosen the most basic, although more advanced methods are covered on other Instructables. In my method, the Arduino communicates with a C-based program running on the terminal, which in turn runs an Applescript that will perform the desired action in the application. It's a roundabout method, but it utilizes preexisting software architectures in the operating system and thus requires the least coding effort on my part.
The first step to making this work is to download the C code to give the Arduino access to the computer's terminal program. It was written by Tod Kurt, and is available off this website. However, after much experimentation, I realized that my coding skills weren't up to par with modifying the code to fit my needs (I needed the serial communications to cause the applescript to run). Luckily, another instructable user has done work in this area. User aymans wrote code in his foot switch instructable that modifies Tod Kurt's code to allow serial communications from the arduino to execute applescripts. This turned out to be exactly what I needed, so I modified my current arduino code and files to fit his code. To download his code, visit his instructable
You will also need to download or write your own Applescript to switch the track in iTunes. I've included one attached to this step, but you can always write your own and use it for whatever application and action you'd like. If you write your own, make sure to name it "1.app" and save it in the same folder as the rest of your files to make it work with the other code.
Now that you have all the files, we can try it out. Make sure iTunes is on and that your set-up arduino code is uploaded to your device. Then execute the arduino-serial program (after its been compiled of course) with the command "./arduino-serial -b 9600 -p [your arduino serial port] -R". Replace the brackets with your arduino's serial port, which can be found in the Arduino IDE under the Tools menu. Once this is done, everything should work. Test it out, feel the power of controlling your computer without even touching it. Sure it's a lot of work for a glorified button, but over engineering is always fun.