Shop OBEX P1 Docs P2 Docs Learn Events
I need help! Boebot and home-made color sensor — Parallax Forums

I need help! Boebot and home-made color sensor

EduardEduard Posts: 21
edited 2008-08-25 05:40 in Robotics
Hello!

I've built a home-made color sensor.
This sensor consists of three LEDs and one LDR. The sensor have to recognise three cubes of different color . Depending of the color of the cubes, the light that returns to the LDR is different, then the resistance that the LDR has is different in every colour.
I think that the sensor will work well, but I don't know how to do in order that the boebot admit the resistance that has the LDR and admit what colour it is.

Can anyone help me ?


Sorry if my english is not very good. Regards from Barcelona !

rolleyes.gif

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-07-19 20:26
    The RCTIME statement can be used to measure resistance (or small voltages). Look at www.emesystems.com and click on the "app-notes" link near the bottom of the page. There's a whole section on the RCTIME statement.
  • EduardEduard Posts: 21
    edited 2008-07-20 16:16
    Thank you, but I don't understand the web page very well...

    Where I've to connect the LDR to the boebot ?

    The boebot shows the resistance of the LDR inmediately ?

    It's possible to say to the BoeBot "If the resistance is X say "Blue"" or "If the resistance is Y say "Red"" ??

    Thanks!
  • Mike GreenMike Green Posts: 23,101
    edited 2008-07-20 19:29
    Have you looked in the Parallax Stamp Basic Manual? There's a chapter on the RCTIME statement with schematics and sample code. This includes formulas for calculating the size of the capacitor needed based on the resistance range. The RCTIME statement provides a value proportional to time required to charge or discharge the capacitor through the resistance and that's proportional to the resistance. You'll need to determine the resistance range and thresholds involved through measurement or experimentation and put appropriate decision making (IF THEN) in your program.

    This manual is available in Spanish (www.parallax.com/tabid/535/Default.aspx). Also read the Spanish translation of "What's a Microcontroller?".

    Post Edited (Mike Green) : 7/20/2008 7:35:43 PM GMT
  • EduardEduard Posts: 21
    edited 2008-08-08 21:26
    Sorry for the post delay, but I was on holiday and I couldn't post.

    I've done the RCTIME circuit, and now the BoeBot says the resistance numbers.
    But I don't know how to do the decision making.
    When you want to make a decision, you put "IF condition THEN instruction". What I've to put instead of "condition" ?

    Thanks a lot! smilewinkgrin.gif

    Post Edited (Eduard) : 8/8/2008 9:31:58 PM GMT
  • Mike GreenMike Green Posts: 23,101
    edited 2008-08-08 22:05
    "condition" is also discussed as a Boolean expression. In the case of Stamp Basic, it's any zero or non-zero value. Zero is considered false and any non-zero value is considered true. Numeric comparisons evaluate to zero/non-zero so the expression "A < 5" is true when the variable A is any value less than 5 and false when A is 5 or greater. Read the Manual's section on arithmetic and Boolean operators and expressions for explanations and examples.
  • DgswanerDgswaner Posts: 795
    edited 2008-08-08 22:49
    Eduard, I've done this very thing in the past. and to get accurate and consistent results I used 3 LEDS, Red Blue and Green. I measured the resistance while each separate LED was on. and you using one LED? using 3 LEDs make for some long If statements but it worked quite well when I got it working.

    perhaps it would be easiest to get it working with on LED first and then add them as needed.

    just my .02¢


    added:
    David Cook talks about this project on the link below, but he doesn't use a Stamp.
    http://www.robotroom.com/ColorSensor.html

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "A complex design is the sign of an inferior designer." - Jamie Hyneman, Myth Buster

    DGSwaner

    Post Edited (Dgswaner) : 8/8/2008 10:57:02 PM GMT
  • EduardEduard Posts: 21
    edited 2008-08-09 20:52
    Hi!
    Dgswaner said...
    Eduard, I've done this very thing in the past. and to get accurate and consistent results I used 3 LEDS, Red Blue and Green. I measured the resistance while each separate LED was on. and you using one LED? using 3 LEDs make for some long If statements but it worked quite well when I got it working.

    perhaps it would be easiest to get it working with on LED first and then add them as needed.

    just my .02¢
    Here in the photo you can see my sensor. It consists of 3 LDR (Red, Green and Blue) and in the center, one LDR.
    The program is like this:

    Sensor:
    Led Blue On
    analyze (A)
    Led Blue off
    Led Red On
    analyze (B)
    Led Red Off
    Led Green On
    analyze (C)
    Led Green Off
    IF A>5 , B>10 C<67 THEN yellow
    IF A<7 , B>2 C<13 THEN black
    IF A<5 , B<10 C<12 THEN grey

    dsc0390ce2.jpg dsc0390ce2.85362c0546.jpg

    Mike Green said...
    "condition" is also discussed as a Boolean expression. In the case of Stamp Basic, it's any zero or non-zero value. Zero is considered false and any non-zero value is considered true. Numeric comparisons evaluate to zero/non-zero so the expression "A < 5" is true when the variable A is any value less than 5 and false when A is 5 or greater. Read the Manual's section on arithmetic and Boolean operators and expressions for explanations and examples.

    Sorry, but I'm a begginer with this , and I'm confused confused.gif
    How can I say to the boebot that it has to make a decision with the results of the RCTIME ?

    Thanks a lot !! smile.gif
  • Mike GreenMike Green Posts: 23,101
    edited 2008-08-09 20:59
    What kind of decision do you want to make with the results of the RCTIME? RCTIME produces a numeric value. What do you want to do with that?
  • EduardEduard Posts: 21
    edited 2008-08-09 21:54
    Hi!

    I want to differ three different colours. To differentiate them I use three leds and one LDR that has to make three differents measurements using RCTIME (A, B and C, for example) .
    I want that the boe-bot analyze the A, B and C measurements and depending on the results, recognise the colour of the object.

    Is it possible ?

    Thanks!! [noparse]:)[/noparse]
  • Mike GreenMike Green Posts: 23,101
    edited 2008-08-09 23:16
    You have to write the rules for the analysis. The Stamp only knows how to do 16-bit integer calculations and comparisons. The Stamp can turn the LEDs on and off and it can measure the resistance of the LDR in terms of the time to charge or discharge a capacitor. You'll have to figure out the formula to calculate the actual resistance of the LDR and to correlate that with the intensity of light at different frequencies. The chapter on the RCTIME statement will give you the information to compute the resistance and, hopefully, the LDR datasheet will have graphs of light intensity vs. resistance at different light wavelengths. You may need to do some experiments with different standard color (paint) chips to actually measure the values of the RCTIME results and use that for calibration.
  • EduardEduard Posts: 21
    edited 2008-08-10 11:25
    I've get it! hop.gif

    I can differ between three different colurs : Yellow, Black and Purple.

    But I've done a trap...
    I was having a problem... "Constant exeeds 16 bits". Then, I erased the three last numbers of each result, and now it works perfectly... idea.gif
  • EduardEduard Posts: 21
    edited 2008-08-10 13:55
    Here you can see a little video that i've recorded of this....

    YELLOW in catalan is GROC
    PURPLE in catalan is LILA
    BLACK in catalan is NEGRE



    Thanks! smilewinkgrin.gif
  • TomvnTomvn Posts: 103
    edited 2008-08-25 05:40
    that very nice project..
    how that code work ? could you post the code?
Sign In or Register to comment.