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.
S | Digital output |
+ | 3.3V |
- | GND |
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.
1 * microbit
1 * microbit expansion board
1 * USB cable
1 * line finder module
1 * white paper stick with black tape.
- Several Jumper wires
Code:
Makecode:
MU Python:
#----------------------------------------------------------- # File name : Line_finder.py. # Description : Line_finder module # Author : jason # E-mail : jason@adeept.com # Website : www.adeept.com # Date : 2018/01/08 #----------------------------------------------------------- from microbit import * while True: # define Line_finder pin Line_finder = pin0.read_analog() if Line_finder < 500: display.show(Image.HAPPY) else: display.show(Image.SAD)
Click “flash” and download the code onto the micro:bit.
Now you can see the data read from the infrared line finder module on the
serial port.
Effect Picture:
Components
- 1 * Adeept Arduino UNO R3 Board
- 1 * Line Finder Module
- 1 * USB Cable
- 1 * 3-Pin Wires
Build the circuit
Adeept UNO R3 Board | Line Finder Module |
D8 | S |
5V | + |
GND | - |
Code:
/*********************************************************** File name: _24_LineFinderModule.ino Description: The information of line finder module has been detected by UNO R3,and displayed in the serial monitor Website: www.adeept.com E-mail: support@adeept.com Author: Tom Date: 2017/03/15 ***********************************************************/ int linefinderPin=8; //Set the digital 8 to the S pin void setup() { pinMode( linefinderPin,INPUT); //initialize the line finder S pin as input Serial.begin(9600); //opens serial port, sets data rate to 9600 bps } void loop() { if(digitalRead(linefinderPin)==LOW){ Serial.println("White"); //send data to the serial monitor }else{ Serial.println("Black"); //send data to the serial monitor } delay(200); //delay 0.2s }
Compile and download the sketch to the UNO R3 board.
Open the Serial Monitor in Arduino IDE. Place the sensor module over a piece of white paper and another of black and you will see the data detected on the window. You can adjust the blue potentiometer on the module to change the sensitivity.
Components
- 1 * Raspberry Pi
- 1 * GPIO Extension Board
- 1 * 40-Pin GPIO Cable
- 1 * Breadboard
- 1 * Line Finder Module
- 1 * 3-Pin Wires
Build the circuit
Code: C code:
#include <wiringPi.h> #include <stdio.h> #define TrackSensorPin_S 0 int main(void) { if(wiringPiSetup() == -1){ printf("setup wiringPi failed !\n"); return -1; } pinMode(TrackSensorPin_S, INPUT); while(1){ if(digitalRead(TrackSensorPin_S) == LOW){ printf("White line is detected\n"); delay(100); } else{ printf("...Black line is detected\n"); delay(100); } } return 0; }
Python code:
#!/usr/bin/env python import RPi.GPIO as GPIO TrackSensorPin_S = 11 def setup(): GPIO.setmode(GPIO.BOARD) # Numbers GPIOs by physical location GPIO.setup(TrackSensorPin_S, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Set Pin's mode is input, and pull up to high level(3.3V) def loop(): while True: if GPIO.input(TrackSensorPin_S) == GPIO.LOW: print '...White line is detected !' else: print 'Black line is detected...' def destroy(): GPIO.cleanup() # Release resource if __name__ == '__main__': # Program start from here setup() try: loop() except KeyboardInterrupt: # When 'Ctrl+C' is pressed, the child program destroy() will be executed. destroy()
For C language users:
Step 2: Edit and save the code with vim or nano.
(code path: /home/Adeept_Sensor_Kit_for_RPi_C_Code/18_tracking/tracking.c)\\
Step 3: Compile$ sudo gcc tracking.c -o tracking -lwiringPi
Step 4: Run
$ sudo ./tracking
For Python users:
Step 2: Edit and save the code with vim or nano.
(code path: /home/Adeept_Sensor_Kit_for_RPi_Python_Code/18_ tracking.py)
Step 3: Run
$ sudo python 18_tracking.py
Place the sensor module over a piece of white paper and another of black and you will see
the data detected on the terminal. You can adjust the blue potentiometer on the module
to change the sensitivity.
Reference material:http://www.adeept.com/learn/
Video:http://www.adeept.com/video/