Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to measure light intensity with LED on PYB Nano

Shulou Source: shulou.com Published: 2022-06-01 04:53:33 10月04日 Update

This article introduces how to use LED to measure light intensity on PYB Nano, the content is very detailed, interested friends can refer to, hope to be helpful to you.

A long time ago, TI did a demo when promoting MSP430, measuring ambient light intensity with ordinary LED. Let's also try it on PYB Nano.

The principle of using LED to measure light intensity is that LED is also a diode, the junction capacitance of its PN junction will be affected by light intensity, and there is a certain corresponding relationship between discharge or charging speed and light intensity. Charge / discharge the LED first, delay a few milliseconds and then measure the voltage on the LED. The voltage will change obviously under different light intensity.

To achieve this function, the control GPIO of LED is required with the function of ADC. On PYB Nano, LED uses PA0-PA3, and they all support ADC and can all be tested. The following program demonstrates this function. After entering the program, use test ('A0') to test the first LED,test (' A1') to test the second.

From pyb import Pin, ADCdef test (pin='A0', count=100): pn = Pin (pin, Pin.OUT) for i in range (count): tmp = 0 pn (1) pn = Pin (pin, Pin.IN) Pull=Pin.PULL_NONE) pyb.delay (1) adc = ADC (Pin (pin)) for N1 in range (8): tmp + = adc.read () print (tmp) pn = Pin (pin, Pin.OUT) pn (0) pyb.delay

When 4 LED were tested respectively, the red LED had the worst effect and changed little, while the other LED changed significantly, which indicated that the running effect had a lot to do with LED. Although it can not be used to accurately measure light intensity, it is possible to measure simple ambient light intensity while making indicator lights, such as adjusting LCD backlight, changing LED brightness and so on.

Here are the effects of LED2/LED3 (green and yellow):

On how to use LED light intensity measurement on PYB Nano to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Tags: Test photometry function effect change measurement use content more environment voltage program help different good large obvious obvious ordinary worst Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi Linux OPPO Reno Apple vpn