Shop OBEX P1 Docs P2 Docs Learn Events
How do I use the IR sensors to detect specific colors? — Parallax Forums

How do I use the IR sensors to detect specific colors?

Khiem NguyenKhiem Nguyen Posts: 4
edited 2006-03-18 13:48 in Learn with BlocklyProp
I need help and fast, since I have a competition in 3 weeks at John Hopkins University, I'm suppose to build a boebot that can detect dark spots on a 3x3 (feet) cardboard box. Dark spots has a radius of two inches. Only problem is thus far I've been using the wrong sensor trying to detect it. I basically used photo resistors trying to detect these dark spots, since my friend suggested me to use them, but after I read about the photo resistors I found out it can only detect various intensity of shadows, so I'm back to square two (I already figured out movements!). My teacher bought my group this package.

http://www.parallax.com/detail.asp?product_id=28132
http://www.parallax.com/images/prod_jpg/28132.jpg

My last option is to use the infrared sensor to detect a specific color on the ground, if it detects that specific color, the Boebot would light up an LED but I'm not quite sure how get the infrared to search for a specify color. I know infrared sensor detect certain wavelengths to detect colors, 400nm is purple, so I guess I need a lower wavelength to detect darkspots on the ground, but how am I suppose to do that?

If you guys know an easier method please tell me? I want to at least build a robot that can detect darkspots and lose, then detect nothing at all.

Comments

  • Martin HebelMartin Hebel Posts: 1,239
    edited 2006-03-14 02:50
    Are you sure it's black spots on brown cardboard? That would be very difficult. I think your best bet in that case would to go back to the photoresistors, but put on some bright white LED's to illuminate the area (sensors and LEDs very close to ground). This will allow you to measure shades, but will reduce some of the problems associated with shadows.

    I don't see how IR LEDs will help, since they are typically used with sensing high contrast - such as black on white. no reflection or reflection. If it's dark spots on white background (or reflective at least) IR's are the best choice.

    Anyone have other thoughts?

    -Martin

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Martin Hebel
    Perform an Employer's Survey of Electronic Technologies Graduates· - Click here!
    Personal Links with plenty of BASIC Stamp info
    and SelmaWare Solutions - StampPlot - Graphical Data Acquisition and Control
  • Khiem NguyenKhiem Nguyen Posts: 4
    edited 2006-03-14 03:19
    Oh I meant posterboard (white), sorry, so its black spots on white posterboard!! Again my mistake!
  • Martin HebelMartin Hebel Posts: 1,239
    edited 2006-03-14 03:30
    Then IR's are definately the way to go. OK, let me back up here. With the Boe-Bot parts is an IR emitter and IR TV receiver - it looks for 38KHz.

    What you want to do is FREQOUT to the IR emitter at 38KHz, and immediately read the IR receiver pin to see if it's low (saw signal) or high (no signal).

    The back dots should absord the IR, so no reflection, input = 1
    The cardboard (white I hope?) will reflect the IR, input = 0.

    Read through the Boe-Bot texts, there's many good examples and explainations in there on using IR eyes.

    PS: You can generally run down Radio shack and buy IR LEDs and the IR Tv Receiver modules.

    Good luck!
    -Martin

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Martin Hebel
    Perform an Employer's Survey of Electronic Technologies Graduates· - Click here!
    Personal Links with plenty of BASIC Stamp info
    and SelmaWare Solutions - StampPlot - Graphical Data Acquisition and Control
  • Khiem NguyenKhiem Nguyen Posts: 4
    edited 2006-03-14 03:40
    Thanks man!! I'll look through the book tonight, and mess around with it tomorrow. I guess I'll post up my progress and anymore problems that pops up on this thread. Will it be alright if I PM you if I require more assistance or just incase everyone forgot about this thread?
  • Martin HebelMartin Hebel Posts: 1,239
    edited 2006-03-14 05:15
    Sure, you're welcome to PM me, but I many of us watch the Stamps In Class forum closely.

    -Martin

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Martin Hebel
    Perform an Employer's Survey of Electronic Technologies Graduates· - Click here!
    Personal Links with plenty of BASIC Stamp info
    and SelmaWare Solutions - StampPlot - Graphical Data Acquisition and Control
  • Khiem NguyenKhiem Nguyen Posts: 4
    edited 2006-03-17 04:08
    I found a sample code that can distinquish black and white paper apart in the boebot book using photoresistors, but any shadow would be consider a black (paper), so its really sensative. I think this is my alternative choice because the wrong light setting can screw the robot's sensor up.

    I took your advice using the IR sensor to distinguish between black and white colors, though I'm not sure if I coded what you told me to right. The IR kept detecting objects instead of colors..... well here's my code:
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}


    irDetectLeft VAR Bit
    irDetectRight VAR Bit
    counter VAR Word

    DEBUG "Testing piezospeaker.."
    FREQOUT 4, 2000, 3000

    DEBUG CLS,
    "IR DETECTORS", CR,
    "Left Right", CR,
    "

    "

    DO
    FREQOUT 8, 1, 30000
    irDetectLeft = IN9

    FREQOUT 2, 1, 30000
    irDetectRight = IN0
    'If irDetect = 1, IR detect Black
    'If irDetect = 0, IR detect White
    IF (irDetectLeft = 1) THEN
    HIGH 10
    ELSE
    LOW 10
    ENDIF

    IF (irDetectRight = 1) THEN
    HIGH 1
    ELSE
    LOW 1
    ENDIF

    DEBUG CRSRXY, 2, 3, BIN1 irDetectLeft,
    CRSRXY, 9, 3, BIN1 irDetectRight

    PAUSE 100

    LOOP


  • Martin HebelMartin Hebel Posts: 1,239
    edited 2006-03-18 13:48
    Hi Khiem,
    The IR's are made for object detection, but they can also be used for line following and such.· Make sure the dark spots you use are not reflective - like a flat (not glossy) black ink or paper.

    Also, you can increase the size of the resistor to the irLED to reduce its output to cut down on the reflection.· It takes a little playing around to find a combination that of resistors and distance from the floor that works well.

    -Martin
    ·
Sign In or Register to comment.