Site Tools


pub:line_finder

Differences

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

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
pub:line_finder [2019/01/08 15:42]
Adeept
pub:line_finder [2019/01/09 13:56] (current)
Adeept
Line 11: Line 11:
 reflected infrared rays or not. Based on this, the module is usually used in reflected infrared rays or not. Based on this, the module is usually used in
 line finding on a smart car.\\ line finding on a smart car.\\
- 
  
 {{:​pub:​line_finder:​line-find.jpg?​400|}} {{:​pub:​line_finder:​line-find.jpg?​400|}}
Line 37: Line 36:
 1 * white paper stick with black tape.\\ 1 * white paper stick with black tape.\\
 - Several Jumper wires\\ - Several Jumper wires\\
 +
 +
  
 Code:\\ Code:\\
 Makecode:\\ Makecode:\\
  
 +{{:​pub:​line_finder:​2019-01-08_155624.png?​400|}}\\
  
 MU Python:\\ MU Python:\\
 <code 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>​ </​code>​
  
Line 53: Line 71:
 Effect Picture:\\ Effect Picture:\\
  
-添加图片+{{:​pub:​line_finder:​1m.jpg?​600|}}
  
 ---- ----
Line 66: Line 84:
 Build the circuit\\ Build the circuit\\
  
-图片+{{:​pub:​line_finder:​linefindermoduleaa.png?​600|}}\\
  
 |    Adeept UNO R3 Board    |    Line Finder Module ​   | |    Adeept UNO R3 Board    |    Line Finder Module ​   |
Line 75: Line 93:
 Code:\\ Code:\\
 <code c> <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>​ </​code>​
Line 81: Line 122:
  
  
-图片 +{{:​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 Open the Serial Monitor in Arduino IDE. Place the sensor module over a piece of white
Line 88: Line 131:
 adjust the blue potentiometer on the module to change the sensitivity. adjust the blue potentiometer on the module to change the sensitivity.
  
-图片+{{:​pub:​line_finder:​linefindermodulea.jpg?​600|}}\\
  
  
Line 104: Line 147:
 Build the circuit\\ 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:\\ For C language users:\\
 \\ \\
 Step 2: Edit and save the code with vim or nano.\\ 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 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 3: Compile$ sudo gcc tracking.c -o tracking -lwiringPi\\
 \\ \\
Line 133: Line 240:
  
  
 +{{:​pub:​line_finder:​18r.jpg?​600|}}\\
 +
 +
 +
 +Reference material:http://​www.adeept.com/​learn/​ \\
 +Video:http://​www.adeept.com/​video/​ \\
  
pub/line_finder.1546933352.txt.gz · Last modified: 2019/01/08 15:42 by Adeept