Shop OBEX P1 Docs P2 Docs Learn Events
Trouble Getting Photoresistor Based Navigation To Work — Parallax Forums

Trouble Getting Photoresistor Based Navigation To Work

Jonathan MorrisonJonathan Morrison Posts: 23
edited 2005-07-16 07:07 in Robotics
I am using 2 photoresistors as navigation input for a BOE-BOT in order to have it follow a flashlight. It works great when I precalculate the ambien and direct light values - however,·I want it to detect those values at startup time so that it can run in different light environments. I have a couple of loops that run at startup calculating the ambient light values and then sound a beep for 5 seconds and then rerun the loops expecting the direct light source to now be shining - this is what the tone tells the user to do.

The proble is that in a brighter ambient light environment - the resistance readings are so low that the threshold is way to tight for the BOE-BOT to notice the light. I am using 220 Ohm resistors on the VDD side. Do I need even lower resistance? Or will a higher Ohm resistor give a higher range?

Any help is appreciated. Thanks.

Comments

  • edited 2005-07-16 00:29
    Have you already tried all the activities in Chapter 6: Light Sensitive Navigation with Photoresistors?· The reason I ask is because the answer to your question will have to assume you've finished that chapter.

    Post Edited (Andy Lindsay (Parallax)) : 7/16/2005 12:33:20 AM GMT
  • Jonathan MorrisonJonathan Morrison Posts: 23
    edited 2005-07-16 01:28
    Yes·I have. In fact, that was where I got the idea to lower the resistance on the VDD side. Sorry if this is a dumb question - I am a total noobie. Thanks.
  • edited 2005-07-16 01:39
    No, it's not a dumb question at all, and you appear to be doing quite well. The answer to this question is to make your code self calibrating. To do this, it's best to write values to the BASIC Stamp's EEPROM. I'll post some sample code in a half hour or so.
  • edited 2005-07-16 02:37
    Alright, try the attached program.· It will test to see if you can calibrate for a threshold.

    I don't think changing resistors will help.· Make sure to use the circuit at the beginning of Chapter 6, Activity #4.

    If your conditions are consistently too bright, try replacing the 0.01 uF capacitor with a 0.1 uF capacitor.· It'll have 104 printed on it instead of 103.· Be careful though, in darker conditions, you might end up with too large of a measurement, in which case your RCTIME command will store a 0 in the variable.

    The program does not write to the EEPROM.· It is certainly possible to do it that way, but the program is more self explanatory like this.

    Post Edited (Andy Lindsay (Parallax)) : 7/16/2005 2:42:28 AM GMT
  • Jonathan MorrisonJonathan Morrison Posts: 23
    edited 2005-07-16 05:35
    Cool. Thanks.

    I ran this and it gave the same results as the routine I had written - so I feel good about that. [noparse]:)[/noparse]

    I did notice thought that one of my LDRs has way different readings than the other - an order of magnitude in some cases. Is it possible that I just have a bad LDR? Thanks a lot for the code sample.
  • edited 2005-07-16 05:56
    Yeah, it looks like you've pretty much got the hang of this if you spun some working self calibration code. That's good.

    If the photoresistor still responds to different levels of light, it's probably not broken. The first thing I check if the measurements are off by an order of magnitude is the capacitors. If one capacitor is 10 times the value of the other capacitor, the readings you get will also be off by a factor of 10. Also make sure that the resistors that connect the I/O pins to the parallel RC circuits are both 220 ohm.

    There are some instructions in Appendix F for balancing photoresistors that aren't returning the same measurements. I've used it to bring some pretty seriously mismatched photoresistors into balance. Photoresistors are cheap, and the price of thrift is lack of precision. For precision, photodiodes·are way better. There's a great writeup on the virtues of photodiodes in Applied Sensors.

    Now, back to the dynamic range problem. Did you try the larger capacitors? They should give you high enough resolution in bright light conditions. You can also modify your circuits so that the BASIC Stamp selects between either the larger or smaller capacitors depending on the lighting conditions. Interested?
  • edited 2005-07-16 06:16
    Here is a circuit you can use to make your LDR measurements 10 times larger when the lighting conditions are bright.

    attachment.php?attachmentid=38301
    ·
    The trick to using it is to ground either one or the other capacitors.· When you send a LOW signal to P7 and make P5 an input, you are working with a .01 uF capacitor in parallel with the LDR.· If you instead send a low signal to P5 and make P7 an input, the LDR is now in parallel with a 0.1 uF capacitor, and the RC decay measurements will be 10 times as large.· Here is a piece of sample code (untested) that should switch to the larger capacitor if the initial measurement is less than 25.

    [color=#008000]' SelectCap.bs2[/color]
    [color=#008000]' Select capacitor for lighting conditions[/color]
     
    [color=#008000]' {$STAMP BS2}[/color]
    [color=#008000]' {$PBASIC 2.5}[/color]
     
    [color=#000000]time VAR Word[/color]
     
    [color=#0000ff]LOW[/color][color=#000000] 6[/color]
    [color=#0000ff]LOW[/color][color=#000000] 7[/color]
    [color=#0000ff]INPUT[/color][color=#000000] 5[/color]
     
    [color=#0000ff]HIGH[/color][color=#000000] 6[/color]
    [color=#0000ff]PAUSE[/color][color=#000000] 1[/color]
    [color=#0000ff]RCTIME[/color][color=#000000] 6, 1, time[/color]
     
    [color=#0000ff]DEBUG[/color] [color=#800080]CLS[/color]
     
    [color=#0000ff]IF[/color][color=#000000] time < 25 [/color][color=#0000ff]THEN[/color]
      [color=#0000ff]LOW[/color][color=#000000] 5[/color]
      [color=#0000ff]INPUT[/color][color=#000000] 7[/color]
      [color=#0000ff]DEBUG[/color] [color=#ff0000]"Using larger cap"[/color][color=#000000], [/color][color=#800080]CR[/color]
    [color=#0000ff]ELSE[/color]
      [color=#0000ff]DEBUG[/color] [color=#ff0000]"Using smaller cap"[/color][color=#000000], [/color][color=#800080]CR[/color]
    [color=#0000ff]ENDIF[/color]
     
    [color=#0000ff]DO[/color]
     
      [color=#0000ff]HIGH[/color][color=#000000] 6[/color]
      [color=#0000ff]PAUSE[/color][color=#000000] 1[/color]
      [color=#0000ff]RCTIME[/color][color=#000000] 6, 1, time[/color]
     
      [color=#0000ff]DEBUG[/color] [color=#800080]CRSRX[/color][color=#000000], 0, [/color][color=red]"time = "[/color][color=#000000], [/color][color=#000080]DEC5[/color][color=#000000] time[/color]
      [color=#0000ff]PAUSE[/color][color=#000000] 100[/color]
     
    [color=#0000ff]LOOP[/color]
    
    



    Post Edited (Andy Lindsay (Parallax)) : 7/16/2005 6:29:27 AM GMT
    1123 x 369 - 40K
  • Jonathan MorrisonJonathan Morrison Posts: 23
    edited 2005-07-16 06:37
    You rock!! This is exactly what I needed. I am a C programmer by day and still learning the electronics side of things by night. Any good texts for getting up to speed on the electronic stuff - like the ability to know what stuff to change to get more or less granular readings. I know there are a lot of books out there - I have a bunch but find that they are either too complex or too simple. I was hoping to find the "Applied Electronics for Building Robots" book or something. Thanks again Andy - this is extremely useful stuff.
  • edited 2005-07-16 07:07
    Wow, thanks!

    I don't know of any such book. Here's what I used instead:

    - Parallax .pdf downloads (especially Stamps in Class)
    - Magazines like Servo, Nuts & Volts and Circuit Cellar
    - Interacting with other robotics enthusiasts at robotics club meetings and on these forums
Sign In or Register to comment.