Site Tools


pub:line_finder

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
pub:line_finder [2019/01/07 11:24]
Adeept created
pub:line_finder [2019/01/09 13:56] (current)
Adeept
Line 1: Line 1:
 =====Line_finder===== =====Line_finder=====
 +
 +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.\\
 +
 +{{:​pub:​line_finder:​line-find.jpg?​400|}}
 +
 +|    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.\\
 +
 +
 +{{:​pub:​line_finder:​23.png?​600|}}\\
 +
 +
 +
 +----
 +===== Microbit =====
 +
 +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:\\
 +
 +{{:​pub:​line_finder:​2019-01-08_155624.png?​400|}}\\
 +
 +MU Python:\\
 +<code 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)
 +</​code>​
 +
 +
 +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:\\
 +
 +{{:​pub:​line_finder:​1m.jpg?​600|}}
 +
 +----
 +===== Arduino =====
 +
 +Components\\
 +- 1 * Adeept Arduino UNO R3 Board\\
 +- 1 * Line Finder Module\\
 +- 1 * USB Cable\\
 +- 1 * 3-Pin Wires\\
 +
 +Build the circuit\\
 +
 +{{:​pub:​line_finder:​linefindermoduleaa.png?​600|}}\\
 +
 +|    Adeept UNO R3 Board    |    Line Finder Module ​   |
 +|    D8    |    S    |
 +|    5V    |    +    |
 +|    GND    |    -    |
 +
 +Code:\\
 +<code c>
 +  /​***********************************************************
 +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
 +}
 +
 +</​code>​
 +
 +Compile and download the sketch to the UNO R3 board.
 +
 +
 +{{:​pub:​line_finder:​1a.png?​600|}}\\
 +{{:​pub:​2.png?​600|}}\\
 +
 +
 +
 +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.
 +
 +{{:​pub:​line_finder:​linefindermodulea.jpg?​600|}}\\
 +
 +
 +----
 +===== Raspberry pi =====
 +
 +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\\
 +
 +{{:​pub:​line_finder:​18.jpg?​400|}}\\
 +
 +Code:
 +C code:
 +<code c>
 +  #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;
 +}
 +
 +</​code>​
 +
 +Python code:
 +<code python>
 +  #​!/​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()
 +
 +
 +</​code>​
 +
 +For C language users:\\
 +\\
 +Step 2: Edit and save the code with vim or nano.\\
 +<code c>
 +(code path: /​home/​Adeept_Sensor_Kit_for_RPi_C_Code/​18_tracking/​tracking.c)\\
 +</​code>​
 +Step 3: Compile$ sudo gcc tracking.c -o tracking -lwiringPi\\
 +\\
 +Step 4: Run\\
 +<code c>
 +$ sudo ./tracking
 +</​code>​
 +For Python users:\\
 +\\
 +Step 2: Edit and save the code with vim or nano.\\
 +<code c>
 +(code path: /​home/​Adeept_Sensor_Kit_for_RPi_Python_Code/​18_ tracking.py)
 +</​code>​
 +Step 3: Run\\
 +<code c>
 +$ sudo python 18_tracking.py
 +</​code>​
 +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.\\
 +
 +
 +{{:​pub:​line_finder:​18r.jpg?​600|}}\\
 +
 +
 +
 +Reference material:http://​www.adeept.com/​learn/​ \\
 +Video:http://​www.adeept.com/​video/​ \\
 +
pub/line_finder.1546831477.txt.gz · Last modified: 2019/01/07 11:24 by Adeept