First day on the job. I've patched together a functional LED sensing system using an Arduino Duemilanove, some borrowed wires, and a set of 10mm white LEDs. The concept of the device is simple - one LED acts as a light sensor, reading ambient light, while the other LED displays the brightness that the first one read. The sensing LED was connected to Pin 8 (cathode) and 9 (anode), and the status LED was connected in to Pin 7 and fed back to a ground. The code (in .pde form) can be found here:


I started with some code that I found on a forum post on the Arduino website. This was faulty - it did not work with this board, I found, because of a set of internal pullup resistors located on the board itself. This is the code to disable pullup resistors on the board:
_SFR_IO8(0x35) |= 4;
_SFR_IO8(0x35) |= (1<<4);</span>
The rest of the code based its usage on a voltage readout, as opposed to a timing system that I had read about in the article mentioned on the Home page. I figured it was worth a shot. With that code uploaded, the system worked moderately well. I noticed that for this system, the timings between the three LED phases - emission, reverse bias, discharge - had a significant effect on the output of the sensing LED. More disturbing was the lack of sensitivity of the system. I could cover the sensing LED with my entire hand, and it would still read that there was light and remain on.

We eventually discovered that the problem here lay in the digitalRead and digitalWrite functions of the Arduino. These have essentially two settings - HIGH and LOW. There is no "in-between" setting here. It was difficult to make the sensor LED's voltage drop low enough to be considered LOW, even by covering the LED with my hand or a cloth. This can be remedied by swapping the digitalRead and digitalWrite functions for analogRead and analogWrite, as well as swapping pins on the board. More on this tomorrow.