Index>BBC Micro:bit>Adeept Sensor Kit for BBC Micro:bit>Lesson 40 How to Use Line Finder Module
No related product information!

Lesson 40 How to Use Line Finder Module

1937

   In this lesson, we will carry out an interesting experiment on how to read the data of Line Finder module.

40.1 Components to be prepared

image.png

40.2 Line Finder module

40.2.1 Line Finder module

The Line Finder Module applies the principle that infrared rays reflect differently on surfaces of different colors. After electrified, the infrared diode on the module sends out infrared rays constantly. When they encounter a white surface, the diffused reflection happens and the reflected rays are received by the receiver on the module. On the other hand, when they come across a black one, the receiver cannot get any infrared. Thus, the processor can tell whether it is a white or black detected surface by receiving the reflected infrared rays or not. Based on this, the module is usually used in line finding on a smart car.

As can be seen on the picture, the line finder module is divided into anode, cathode and a signal wire. The signal wire needs to be adjusted by a potentiometer when it is connected to a digital port.

【Note】:

The detection distance of the sensor can be adjusted by the potentiometer.

image.png

image.png 

40.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

40.4 Circuit

    You should connect the components according to the following circuit diagram, and view the pictures with the function “Zoom in”: 

image.png



40.5 MakeCode programming

      In the following part, we will make use of the online MakeCode editor to complete the experiment in this lesson.


40.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_Sensor\Code\Lesson_40\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


40.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 the Micro:bit, click the button image.png, and the program will be downloaded directly to the Micro:bit. Then wait for the download completion. When the download is successful, your Micro:bit will restart and run the program you have downloaded before. 


4.Then click the button【Show Console Device】on the left, as shown below:

image.png

 

     5.Then you will see the waveform below. Slide the Line Finder module left and right slowly, and there will be some changes in the waveform. The detected data will change as well. When a black line is detected by the Line Finder module, the analog data becomes larger.When a white line is detected by the Line Finder module, the analog data becomes smaller.

image.png


image.png

[Note]

    1.If no experimental phenomenon has been detected after clicking the button image.png, you need to click the image.png button on the right of the image.png, and then click the image.png ,  as shown in the following figure:

image.png

2. If no experimental phenomenon is observed, you should check whether the USB cable of Micro:bit is successfully connected. If not, please download the program again.


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


40.5.3 Learn the code program

The following instruction blocks will be applied in the program. Please see the description of the function as follows:

image.png 

Read and print out the data of Line Finder module.

image.png

40.6 Python programming

40.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_Sensor\Code\Lesson_40\PythonCode

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


image.png 


3.Click buttonFlash】 to download the program to the Micro:bit. Click the button image.png immediately (click the button image.png when the Micro:bit indicator is flashing), and the output data will be read on the console, as shown below:


image.png


After downloading the program to Micro:bit successfully, click the button image.png, and it will be blank on the console:

image.png


4.Please place the Line Finder module above the black line on the white background (keep it to a proper height and choose the proper height by adjusting the potentiometer of the Line Finder module), the number 1002 represents that a black line has been detected (large value), while 29 represents that a white line has been detected (small value), as shown below:

image.png


Note

1. If no data can be read on the console,click button【Flash】for a second time, and click the button image.pngimmediately. If no data have been output yet, please repeat the above steps or check whether the wiring is connected correctly.

 

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


40.6.2 Learn the code program


The following is an explanation of the course code of this section.

(1)Read the data of Line Finder module and print out the data.

 

11

12

13

14

15

while True:

# define Line_finder pin

  Line_finder = pin0.read_analog()

  print(Line_finder)

  sleep(100)