3 Simple Ways to
Share What You Make

With Instructables you can share what you make with the world — and tap into an ever-growing community of creative experts.

PhotosPhotos

Share one or more photos of a project, recipe, or whatever you've made, quickly and easily.

Step by StepStep-By-Step

Share your step-by-step photos with text instructions of what you made so others can do it too!

VideoVideo

Share your how-to video. You'll need your embed code from a video site such as YouTube.

Control Fluorescent Lights with a Laser Pointer and an Arduino

Step 3Testing 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.

« Previous StepDownload PDFView All StepsNext Step »

Pro

Get More Out of Instructables

Already have an Account?

close

All Steps Viewing
View all steps of an Instructable on the same page when you're a Pro Member.

Upgrade to Pro today!
3
Followers
2
Author:rmd6502