"Camera" LED
- Transfer
This article will discuss how an array of LEDs can be used as a “camera” of very low resolution (20 pixels). There is little practical sense in this, but the experience of using LEDs as photosensors may be useful to someone. The board uses the Arduino Blinkenlight Shield , originally designed to demonstrate lighting effects.
I mentioned the possibility of connecting the cathodes of all LEDs to the +5 volt bus. Now I will tell you why this opportunity was made [approx. perev .: the author of the article is the developer of the described shield]. This experiment shows how to turn LEDs into light sensors. Since the Blinkenlight Shield contains 20 LEDs, it can be used as a 20-pixel “camera”.
First of all, you need to connect the cathodes of the LEDs with a +5 V jumper. Do not be afraid, this will not harm them in any way. If the LEDs go out - excellent, it should be so. Just do not forget to return the jumper to its original position at the end of the experiment.
Now the LEDs will work as photodiodes. Since they are designed to emit light, the photodetectors from them will turn out to be unimportant, the photocurrent will be very small. In addition, the number of analog pins on the controller is usually limited, while the digital pins are much larger. The fact that the digital CMOS inputs have a very high resistance gives us another way to remove the signal from the LEDs, which we will now consider. The idea is to reverse bias the LED by outputting a logical “0” to the port. In this mode, the LED does not conduct current and behaves like a capacitor. When it is charged, we switch the output to the Z-state, and observe what happens. If the diode is lit, a very small photocurrent occurs, which will discharge the capacitance. The higher the illumination, the greater the current strength, and the faster the discharge. At a certain point in time, the input will lock the transition from state “0” to “1”. Measuring the time elapsed before this transition will make it possible to determine the illumination.
If you want to understand the described phenomena in more detail, you can read this work: www.merl.com/papers/docs/TR2003-35.pdf The
full source code is given here or here .
The setup () function runs through all the pins and sets each to the “0” state. The function also initializes arrays for storing time samples. After that, the outputs switch to input mode. Since “0” was previously displayed on them, the pull-up resistors will be disabled [approx. transl .: in AVR, the same PORTn register is responsible for the output value in the output mode, and for the inclusion of pull-up resistors in the input mode]. Now the findings are in the Z-state. Please note that some contacts are excluded, they are used in Arduino to connect the serial port and the LED indicator. If you can disconnect these pins from the extra load on your board, you can use them. In this case, simply make the pin_is_ok () function always return true. Before disabling the serial port, think about how you will transfer data to the computer.
The main program cycle performs the following: for each LED, a transition from low to high is noted. If this happens, 0 V is applied to the LED again and the time from the moment of the last transition is calculated. Then the output is again transferred to the Z-state. Here I explicitly rely on the fact that the teampinMode () is quite slow, which means that the LED will have several clock cycles per charge capacity.
After all the LEDs are processed, the result is sent through the serial port. You may wonder about the conversion function. In theory and practice, it can be omitted. I just presented the result as a light map in a single line. Therefore, I can use the serial port monitor to visualize the output of this installation.
This video shows the “camera” in action. When writing the firmware, I did not take into account that the Arduino will be located upside down, with a USB port on the left, so the data on the monitor are displayed in the reverse order. However, the operation of the photosensors is clearly visible.