6. Case 04: Photodiode#

../../_images/picoed-starterkit-case04-1.png

6.1. Introduction#


A photodiode is a resistor made of a semiconductor material whose conductivity varies with the intensity of light. This property is used to make photodiodes of different shapes and light-receiving areas. The stronger the light is, the lower the resistance will be. Light-controlled switches usually use a photodiode as the core component. Photodiodes are used in a wide range of industries such as toys, lamps and cameras. In this lesson we are going to display different information on Pico:ed according to the intensity of light received by the photodiode.

6.2. Components List#


Hardware#

1 × Pico:ed

1 × USB Cable

1 × Breadboard Adapter

1 × 83×55mm Breadboard

1x Photodiode

1 × 10kΩ Resistors

N* Dupont Cables

6.3. Main Components#


Photodiode#

Photodiodes are special resistors made of semiconductor materials such as CdS or CdSe, whose working principle is based on the internal photoelectric effect. The stronger the light is, the lower the resistance value will be. As the light intensity rises, the resistance value decreases rapidly and the bright resistance value can be as small as 1KΩ or less. Photodiodes are very sensitive to light, and when they are not illuminated, they are highly resistive, with a dark resistance of up to 1.5MΩ in general.

../../_images/picoed-starterkit-case04-2.png

6.4. Steps#


Hardware Connection#

Connect the components as the pictures suggest:

  1. Connect the photodiode with P0.

  2. Connect a 10kΩ resistor in parallel with a photodiode

../../_images/picoed-starterkit-case04-3.png

This is the picture after finishing the connections:

6.5. Programming#


Program Preparation: Prpgramming environment

Sample Code:#

# Import the modules that we need: 
import board
import picoed
import analogio
import time

# Set the pin connected to the photodiode and read the analog voltage as the reference value of the brightness.
light = analogio.AnalogIn(board.P0_A0)
light_value = light.value

# Determine whether the analog voltage value of the real-time photodiode is less than the reference value, and display "Bright" or "Dark" according to the judgment result.
while True:
    light_new = light.value
    if light_new < light_value:
        picoed.display.scroll("Dark")
    else:
        picoed.display.scroll("Bright")

Details of the Code:#

  1. Import the modules that we need. board is the common container, and you can connect the pins you’d like to use through it. picoed module is able to set the LED effect on Pico:ed. The digitaliomodule contains classes to provide access to basic digital IO. time is the module contains the fuction of time setting.

import board
import picoed
import analogio
import time
  1. Set the pin connected to the photodiode and read the analog voltage as the reference value of the brightness.

light = analogio.AnalogIn(board.P0_A0)
light_value = light.value
  1. Determine whether the analog voltage value of the real-time photodiode is less than the reference value, and display “Bright” or “Dark” according to the judgment result.

while True:
    light_new = light.value
    if light_new < light_value:
        picoed.display.scroll("Dark")
    else:
        picoed.display.scroll("Bright")

6.6. Result#


When the lights are on, the LED screen on Pico:ed shows “Bright”, and when the lights are off, “Dark” is displayed on the screen.

6.7. Exploration#


If we want to use a photodiode to control the on and off of an LED, how do we design the circuit and program it

6.8. FAQ#


6.9. For more information, please visit:#


ELECFREAKS WIKI