Step 3: Testing the Sketch and Design Notes

In this step I'll talk about some of the trials and tribulations that I encountered on the way, and how I worked through them, in the hope that it will be useful.  Fell free to skip to the next step if Science Content isn't your thing :-)

The first step was deciding whether to use capacitive sensing or resistive sensing.  Resistive sensing is connecting the sensor through a resistor to one of the analog pins and doing analogRead and comparing against a threshold.  This is simplest to implement, but takes lots of calibration.

The theory of capacitive sensing is that when reverse biased (- to the + lead and vice versa), an LED will not allow current to flow, but electrons will collect on one side and leave the other side, effectively charging a capacitor.  Light falling on the LED at the frequency it normally emits will actually cause a smal current to flow, which discharges this capacitor.  

So if we charge the LED 'capacitor' and count how long it takes to discharge through a resistor, we get a rough idea of how much light is falling on the LED. This actually worked out to be more reliable across different devices, and even works for phototransistors!  Since we're not doing a precise lumen measurement, and the laser pointer should appear a lot brighter than ambient, we just look for a thresholded discharge time.

The other important part of this adventure is debugging.  For those familiar with programming non-embedded systems, a popular method is to add print statements at critical points in the code.  This also applies to embedded systems, but when every microsecond counts, the amount of time to Serial.write("x is "); Serial.writeln(x); is actually quite significant, and you may miss a lot of events in the process.  So remember to always put your print statements outside of critical loops, or any time you expect an event.  Sometimes blinking an LED is enough to let you know you got to a certain point in the code.

great! so you need to buy the ballasts?
First time i ever saw wires soldiered on like that, even if they are bare wires they are typical just shoved into the headers. Glad it works for you.
&nbsp;Too bad there is no picture of the florecent lights . A video would be grat .<br /> Very hard to get an impresion of what was done ...<br /> <br />
There are pictures, and an AVI - are they not showing up for you?<br />
Ohh.. .. thanks - didn't see the Avi before .<br /> <br />
I saw the Avi but in fact still dont know what I saw. A light wnet on and then it went off
Yes, we can see them.<br />
any thoughts on being able to rapidly turn on and off the light without making the ballast mad? way to keep the light warm but off or dim?<br />
Nice!&nbsp; I would have made a shield or something instead of soldering the wires straight to the Arduino, but otherwise this is an awesome project!<br />
&nbsp;I have to tell you, I&nbsp;witnessed&nbsp;that soldering job done in&nbsp;literally&nbsp;20 seconds. &nbsp;As they say &quot;Desperate&nbsp;times call for&nbsp;desperate&nbsp;measures&quot; &nbsp;We were fresh out of header pins and this was the best way at the time to get the wires connected (safely). &nbsp;I bet you will see an update soon once we get some header pins in or possibly a&nbsp;shield. &nbsp; Although I think a shield may be too much for this. &nbsp;Good work on this project by the way! &nbsp;And I can't wait to see the serial interface side of this project when it is done too.

About This Instructable




More by rmd6502:Creating a Bluetooth wireless scrollwheel How to make a charlieplexed LED heart How to 3D print a solder stencil! 
Add instructable to: