This post will discuss how an array of LEDs can be used as a very low resolution “camera” (20 pixels). There is little practical sense in this, but the experience of using LEDs as photosensors can be useful for someone. The paper uses the Arduino Blinkenlight Shield board, originally intended to demonstrate the 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 [app.Transl .: The author of the article is the developer of the described shield] . This experiment shows how to turn LEDs into light sensors. Since Blinkenlight Shield contains 20 LEDs, it can be used as a 20-pixel “camera”.
First of all, you need to bridge the cathodes of LEDs with +5 V. Do not worry, it will not harm them. If the LEDs go out - great, 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 will be unimportant of them, the photocurrent will be very small. In addition, the number of analog outputs of a controller is usually limited, while digital ones are much more. The fact that digital CMOS inputs have a very high resistance gives us another way of removing the signal from the LEDs, which we will now consider. The idea is to reverse the offset of 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 watch what happens. If the diode is illuminated, a very small photocurrent arises, which will discharge the capacitance. The higher the illumination, the greater the current, and the faster the discharge. At a certain point in time, the input will record the transition from the state "0" to "1". Measuring the time elapsed before this transition will provide an opportunity to determine the illumination.
The setup () function runs through all the findings and sets each to the state "0". The function also initializes arrays for storing time samples. After that, the pins are switched to the input mode. Since before they were displayed "0", pull-up resistors will be disabled [approx.Transl .: In the AVR, the same register PORTn is responsible in output mode for the output value, and in input mode for switching on pull-up resistors] . Now the pins are in the Z-state. Please note that some contacts are excluded, they are used in the Arduino to connect the serial port and the indicator LED. If you can disconnect these pins from the additional load on your board, you can use them. In this case, just make sure that the pin_is_ok () function always returns true. Before disconnecting the serial port, think about how you will transfer data to your computer.
The main program loop performs the following: for each LED, a transition from a low level to a high level is noted. If this happens, 0 V is again applied to the LED, and the time since the last transition is calculated. Then the output is again translated to the Z-state. Here, I explicitly rely on the fact that the pinMode () command is rather slow, which means that the LED will have a few clock cycles on the capacity charge.
After all the LEDs are processed, the result is sent via the serial port. You may wonder about the conversion function. In theory and in practice, it can be omitted. I simply presented the result in the form of an irradiance map in the form of a single line. So I can use the serial 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 is displayed in the reverse order. Nevertheless, the work of photosensors is clearly visible.