Shop OBEX P1 Docs P2 Docs Learn Events
Hooking up Potentiometer to Servo — Parallax Forums

Hooking up Potentiometer to Servo

Im trying to write a bit of code where I can control a servo with a potentiometer. I want to be able to move it to any angular position +/- 80degrees from the centre position. I should then display this position to the screen as it rotates.

Does anyone have any idea where I can start with this? I literally have no idea how to get the potentiometer to interact with the servo. Any bit of code would help to get me started!

Thanks

Comments

  • Have a look in whats a micro controller.. In my copy (version 2.2), chapter 5, activity 4 should help.
  • kwinnkwinn Posts: 8,697
    First thing to do is figure out the mechanical linkage. Then you need to determine the position. The simplest method to do that would be using the potentiometer as part of an RC circuit.
  • annamariaannamaria Posts: 4
    edited 2016-09-20 16:53
    Have a look in whats a micro controller.. In my copy (version 2.2), chapter 5, activity 4 should help.

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}

    time VAR Word
    PAUSE 1000

    DO

    HIGH 7
    PAUSE 10
    RCTIME 7,1, time
    time= time */ 185 'scale by 0.724 x 256
    time= time + 500 'offset by 500
    PULSOUT 14, time 'send pulse to servo

    DEBUG HOME, DEC5 time 'display time value
    LOOP

    Well this is the code I have that lets the servo turn to its full capacity both ways. I need to limit it to -/+ 80 degrees and display that value to the screen. That is the part I am stuck on
  • kwinn wrote: »
    First thing to do is figure out the mechanical linkage. Then you need to determine the position. The simplest method to do that would be using the potentiometer as part of an RC circuit.

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}

    time VAR Word
    PAUSE 1000

    DO

    HIGH 7
    PAUSE 10
    RCTIME 7,1, time
    time= time */ 185 'scale by 0.724 x 256
    time= time + 500 'offset by 500
    PULSOUT 14, time 'send pulse to servo

    DEBUG HOME, DEC5 time 'display time value
    LOOP

    Well this is the code I have that lets the servo turn to its full capacity both ways. I need to limit it to -/+ 80 degrees and display that value to the screen. That is the part I am stuck on
  • Test variable time for values that exceed +/- 80 degrees (might need to experiment to determine what the values are). Limit time to the corresponding range.
       if time < [value_corresponding_to_-80_degrees then
           time = [value_ya_ya
           endif
    'similarly test and limit time to value corresponding to + 80 degrees
    

    OR: read carefully where they talk about calculating the multiplier (185) and adjust it.
  • kwinnkwinn Posts: 8,697
    Modify the program so you can step through the entire range of pulse widths and output the pulse width and RC time value, and write down the angle.
Sign In or Register to comment.