Shop OBEX P1 Docs P2 Docs Learn Events
contolling a servo with a photoresitor — Parallax Forums

contolling a servo with a photoresitor

hotrodhotrod Posts: 14
edited 2008-11-05 19:01 in BASIC Stamp
Hey, I am just starting in the code writing world. I am building a circuit that uses a photoresitor and servo. I am trying to write the code for the·basic stamp. What I want the program to do is move the servo to two position depending on how much light is being measured by the photoreistor. If anyone out there has any suggestion I would really appreciate your help. I am using a basic stamp 2 on the homework board.

Comments

  • GICU812GICU812 Posts: 289
    edited 2008-11-03 06:48
    You'll need an ADC. Other than that, maybe take your digital value and multiply it by an amount to set servo posisiton.

    Say your min digital was 10 and max was 25, and the timing for your BS meant that servo min and max were 800 and 1600. There is a diffrence in the digital of 15 and the servo of 800 so 800/15 = ehh, 50 is close enough

    Then get the digital and put it into variable x


    do
    gosub getdigi

    y=x*50
    pulsout 0, 20, y
    pause ??
    loop


    You get the idea. BTW, I totally pulled every one of those numbers out of my butt, just so you know, make sure you use valid ones.
  • sylvie369sylvie369 Posts: 1,622
    edited 2008-11-03 09:37
    Pages 152 and 189 of the "What's a Microcontroller" book (downloadable from the Parallax site) will show you the two halves of the project.

    You don't need an ADC if you use the RC time circuit described on page 189. Use that to read the photoresistor into a variable in your BS2. Then use the values of that variable to control the servo, using the kind of scaling that GICU812 described.
  • GICU812GICU812 Posts: 289
    edited 2008-11-03 21:31
    Ah, yes, I forgot about RCTime
  • hotrodhotrod Posts: 14
    edited 2008-11-03 22:08
    thanks!!!! I appreciate the help. I will keep you both posted on how everything is going.
  • hotrodhotrod Posts: 14
    edited 2008-11-05 19:01
    The servo moves!!!!!!!!!!!!!!
Sign In or Register to comment.