Connect with us

math problem

Discussion in 'Electronic Basics' started by Beowulf, Feb 9, 2004.

Scroll to continue with content
  1. Beowulf

    Beowulf Guest

    I need help with a math puzzler related to an electronics project. I built
    the BASIC Stamp microcontroller and have a project (photoresistor) that
    measures light and reports the data values. The problem is in almost total
    darkness the values range around 30000 to 40000 and with room light the
    values drop to around 200. I want to use the gizmo to run in a dark room
    and then monitor for light changes, so I would like high values to
    indicate light not dark. So somehow I need to reverse the way the values
    are reported. The problem is compounded by the simply math available to me
    by way of the PBASIC command language of the Stamp: only +, -, /, *
    available, no fancy operators like square root or anything. Ideas?
     
  2. Can you give us some idea of how the photo resistor is connected to
    the Stamp? It may be easier to change the connection than to alter
    the math. But if the math is floating point, then just divide a
    constant by the measured value or subtract the measured value from a
    constant.
     
  3. Beowulf

    Beowulf Guest

    P2 from Stamp sends current to a 220ohm resistor, that then sends
    (splits) the current to a photoresistor and a 0.01uF capacitator, both of
    which then go to the Vss (ground). I know little about the photoresistor
    specs other than it is from Parallax and is part no. 350-00009


    P2---------/\/\/---------*----------------
    220 Ohm | |
    | |
    PHOTOR. _____ 0.01uF
    | ---
    | |
    *-----------------
    |
    |
    ____
    ---- Vss
    --







    I also substituted a thermistor for the photoresistor to get temperature
    data and that works great too.
     
  4. I suspect that the program charges the cap up to about as positive as
    it will go, then changes P2 to an input and times how long it takes
    the input to read as a logic low, based on the time constant of the
    photo resistor with the capacitor. Lower light level raises the
    resistance of the photo resistor, making it take longer (more counts
    of time) to make the transition. I think dividing something like
    100,000 by the count would be a good way to roughly invert the sense
    of the light measurement. If that math includes the fractional part
    of that division, it will have a lot more resolution. If not, you may
    have to divide a bigger number like 500,000 to get enough dim light
    resolution.
     
  5. CFoley1064

    CFoley1064 Guest

    Subject: Re: math problem
    Hi again Beowulf. How's the ectoplasm treating you?

    First, if you're using the Basic Stamp 2, you're going to want to use the
    RCTIME statement, which means you'll want to have a layout like this (view in
    fixed font or use M$ Notepad):


    VCC
    +
    |
    |
    ---
    --- 0.1uF
    220 ohm |
    BS2 ___ |
    Pin o-|___|----o
    |
    |
    |
    .-.
    | | Photoresistor
    | |
    '-'
    |
    |
    ===
    GND

    Since the BS2 has naught but integer math, you have to be creative about
    invering -- 1/X won't cut it. To start out with, figure out what the highest
    tiime reading you'll get is going to be (total darkness). Add a few thousand,
    then just subtract your reading from that number. That will give you a very
    high number for light, and a very low number for dark. It's a hack, totally
    non-linear, but it's quick&dirty, and it might get the job done.

    If you want to explore the intricacies of the arcane art of ASCII scematics,
    try Andy's ASCII circuit v.1.24 -- program available at:

    http://www.tech-chat.de/

    It's "state of the art" -- many people on these newsgroups use it. ;-)

    Good luck
    Chris
     
  6. Olaf

    Olaf Guest

    you gave the solution yourself: 'reverse' and '-'! Use -x instead of x. A
    little tuning will give 'nice' values: when x is the amount of light, then
    let y=40000-x. Now a dark room gives y=0 up to y=10000 and a lit room
    gives y=39800. Or, if you use y=(40000-x)/1000 you end up with nice values
    like y=0 up to y=10 for dark rooms and y=40 (more or less) for a lit room.

    bye, Olaf
     
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-