Index>BBC Micro:bit>BBC Micro:bit Starter Kit>Lesson 28 Light-Controlled Induction Lamp
No related product information!

Lesson 28 Light-Controlled Induction Lamp

1988

    In this lesson, we will carry out an interesting experiment to make a “light controlled induction lamp” by using a photoresistor and LED, which is to control the LED on and off by measuring the light intensity.

28.1 Components to be prepared

image.png


28.2 The introduction of Photoresistor 

28.2.1 Photoresistor

A photoresistor is a light-controlled variable resistor. The resistance of a photoresistor decreases with the increasing incident light intensity; in other words, it exhibits photoconductivity. A photoresistor can be applied in light-sensitive detector circuits.

image.png


Photovaristor (photovaristor), also known as photoresistor, is a kind of resistor made by using the photoelectric effect of semiconductor to change the resistance value with the intensity of incident light;If the incident light is strong, the resistance decreases, and if the incident light is weak, the resistance increases. Photoresistors are generally used for light measurement, light control, and photoelectric conversion (converting changes in light into changes in electricity).

Photoresistors can be widely used in various light control circuits, such as the control and adjustment of lights, and can also be used in light control switches.

In dark, dark conditions, the resistance of the photoresistor is very high. The stronger the light, the smaller the resistance value. By measuring the voltage change value on both sides of the photoresistor, the change of the photoresistor value can be known and the light intensity value can be obtained. In the connection diagram,we can find a voltage divider connected in series with the photoresistor.

image.png 

In the above figure, RL is the photoresistor, R1 is the voltage-dividing resistor in series, Vout=RLR1+RL∗VinVout=RLR1+RL∗Vin, in the dark, the resistance of RL will be very large, so Vout will be very Large, close to 5V. Once the light is irradiated, the value of RL will decrease rapidly, so Vout will decrease accordingly. It can be seen from the above formula that R1 should not be too small, preferably around 1k~10k, otherwise the ratio will not change significantly.


28.2.2 Experimental principle

In this experiment, we first conduct a relatively simple experiment of using a photoresistor. Since the photoresistor is a component that can change the resistance value according to the light intensity, naturally the analog port is also required to read the analog value. In this experiment, the PWM interface experiment can be used to replace the potentiometer with a photoresistor to realize the LED light when the light intensity is different. The brightness will also change accordingly.

A photoresistor is a light-controlled variable resistor. The resistance of a photoresistor decreases with the increasing incident light intensity; in other words, it exhibits photoconductivity. A photoresistor can be applied in light-sensitive detector circuits.

A photoresistor is made of a high resistance semiconductor. In the dark, a photoresistor can have a resistance as high as a few megohms (MΩ), while in the light, a photoresistor can have a resistance as low as a few hundred ohms. If incident light on a photoresistor exceeds a certain frequency, photons absorbed by the semiconductor give bound electrons enough energy to jump into the conduction band. The resulting free electrons (and their hole partners) conduct electricity, thereby lowering resistance. The resistance range and sensitivity of a photoresistor can substantially differ among dissimilar devices. Moreover, unique photoresistors may react substantially differently to photons within certain wavelength bands.

The schematic diagram of this experiment is shown below:

image.png 

With the increase of the light intensity, the resistance of photoresistor will be decreased. The voltage of GPIO port in the above figure will become high.


28.3 Low level and high level


In circuit, the form of binary (0 and 1) is presented as low level and high level.

Low level is generally equal to ground voltage (0V). High level is generally equal to the operating voltage of components.

The low level of Micro:bit is 0V and high level is 3.3V, as shown below. When IO port on Micro:bit outputs high level, low-power components can be directly driven,like LED.

image.png


28.4 Circuit

    

  You need to connect the components according to the following circuit diagram. You can use the “enlarge” function to view the picture.

image.png


28.5 MakeCode programming

Next, we will use the online MakeCode Editor to complete the experiment in this lesson.


28.5.1 Start programming

(1) Log in to the website

1. You need to enter the URL in the address bar of Google Browser:

https://makecode.microbit.org/

2. After the website is successfully opened, the interface as shown below will appear:

image.png



(2) Import a project

1. In the HOME interface, click the "Import" button to import the external ".hex" file:

image.png


In the pop-up dialog box, select the "Import File", as shown in the following figure:

image.png



Click the "Choose File"

image.png


Find the code file for this lesson:

BBC_Microbit_Kit\Code\Lesson_28\BlockCode

Select the file in ".hex" format and click the Open:

image.png


2. Notice whether the file has been loaded into the following window, and then click the "Go ahead!" button, as shown in the following figure:

image.png


3.You can see the following interface when successfully opening the file:

image.png


28.5.2 Run the program

1. After the program is written, connect micro:bit and PC with a Micro USB cable.

2. After micro:bit is connected to the computer, you need to first "Pair device". Click the image.png button on the right of image.png in the lower left corner, and then click the image.png option, as shown in the following figure:

image.png


Then click image.png in the lower right corner

image.png


Then the following dialog box will pop up, select image.png, and then click image.png

image.png


After the device is successfully paired, the image.png button changes to image.png

image.png


3. Start to download the program to Micro:bit, and click the image.png button. Generally, the program will be downloaded directly to the Micro:bit. After the download is completed, your Micro:bit will restart and run the program just downloaded. Observe the LED on the breadboard. You can use your hand or an object to cover the photoresistor and put it in a place where the light is weak, such as in a dark place. You will see that the LED lights up, as shown in the following figure:

image.png


[Note]

  1.If there is no experimental phenomenon after the image.pngis clicked, you need to click the image.png button on the right of the image.png, and then click the image.png , and observe the Micro:bit again, as shown in the following figure:

image.png

2.If there is still no experimental phenomenon, you need to unplug and then plug in the USB cable connected to the Micro:bit, and then download the program again.


3. If the LED does not light up, you can adjust the data in the codes according to your environment: you can make the data larger or smaller by using the image.png.


  If you have problems, please send us an email: support@adeept.com


28.5.3 Learn the code program

Cyclically read the data of the photoresistor connected to the P0 pin (this data is an analog quantity), and then compare the read data with the set reference data 700. When the analog value read is greater than 700, it indicates that the light intensity becomes smaller. Turn on the LED by setting the LED connected to the P1 pin as high level (1 indicates high level); otherwise, the LED will be turned off.

image.png

28.6 Python programming

28.6.1 Run the program

1.Connect micro:bit and PC with a Micro USB cable.

2. Open the Mu Editor installed on the computer, and click the button [Load] in the upper left corner to open the source code program of this lesson:

image.png 


Find the code file for this lesson:

BBC_Microbit_Kit\Code\Lesson_28\PythonCode

Select the file in ".py" format and click the Open:

image.png 


3. Click the [Flash] button to download the program to Micro:bit, as shown in the following figure:

image.png


4.After downloading the program, observe the LED on the breadboard. You can cover the photoresistor with your hand or an object, and make it in a place with weak light, such as a dark place. You will observe that the LED will light up, as shown in the following figure.

image.png


    If you have problems, please send us an email: support@adeept.com


28.6.2 Learn the code program


  Cyclically read the data of the photoresistor connected to the P0 pin (this data is an analog quantity), and then compare the read data with the set reference data 700. When the analog value read is greater than 700, it indicates that the light intensity becomes smaller. Turn on the LED by setting the LED connected to the P1 pin as high level (1 indicates high level); otherwise, the LED will be turned off.

3

4

5

6

7

8

while True:

  value = pin0.read_analog()

  if value >= 700:

      pin1.write_digital(1)

  else:

      pin1.write_digital(0)