Author Options:

Picaxe and Servo problem Answered

Ive been using this picaxe uC for a while and have had no problems, but in my latest project I wanted to pan a servo back and forth. Problem: for the life of me I can only get the servo to move in one direction. It is a GWS pico servo and I have "operated" it on 5v and 6v, so i dont believe it to be a voltage issue. coding issue perhaps? ( I have tried the SERVO command, the SERVO and SERVOPOS command, and even the correct PULSOUT commands to no avail) I have scoured other forums, even rev-ed.com's, but no one seems to have my same problem. As far as I know the SERVO command SHOULD work fine but doesnt. I have tried the commands with and without a 220 ohm resistor on the signal wire, but this seems negligible. When my picaxe 18x is loaded with any servo capable code and the connections are all hooked up, the servo simply moves all the way and stops. the only way i can "reset" my servo to its original position is by quickly removing and tapping the V+ or GND supply wire to the servo. after the servo has moved I can feel the tiny motor jiggle whenever I tap the signal wire as if trying to work. ANY suggestions are welcome!


Hello bud is it an analogue or digital servo?

Haha, I'd almost forgotten about this topic. I've made a lot more progress when it comes to working with electronics since then. It was a digital servo. There was no major issue, I had simply forgot to connect the two ground/common lines together. Worked like a charm afterwords!

Nice 1 bud, i was also having issues with diff type of servos until i cracked it.
Keep up the good work.

Im just getting into Picaxe... How would i connect the servo to a picaxe 18 like the one pictured?

Well, first you'll need a separate 6 volt powersupply for powering the servo (4 AA batteries connected together in series will work) a 4.5 volt power supply for the PICAXE (3 AA batteries) and a wire to connect from the digital output line of the PICAXE to send the signal to the servo. I made a quick image to show this. Note, the grounds (negative black wires) need to be connected together too.

picaxe servo.jpg

Thanks! I guess I was more hoping for an attachment I could solder the to picaxe board for servos.... Is there anything like that? That picture really helps!

Well, I've long since lost that particular board, but if you have that same one, I recall that the output holes are spaced very wide, so no standard attachments. I would just solder a wire directly from the digital output pin you wish to use for the servo. If you google picaxe servo board, plenty of boards should show up. You may wish to check out: http://www.picaxe.com/Hardware/Add-on-Modules/21-Channel-Servo-Controller/


7 years ago

has this been fixed?

for you who don't want to read this whole post the short version is:

when servo is on pin2, the servo command is
servo 2,<position>
where position is stepped from position 65 to 220 by 5's and back using "for, next" instruction.  My servo could move from about position 60 to 220.

output 2 'declare your outputs!
for b2 = 65 to 220 step 5
servo 2,b2
pause 9
next b2
for b2 = 220 to 65 step -5
servo 2,b2
pause 9
next b2

I am using this code to make a picaxe 08m drive a useless box, I destroyed the box while I was tweaking it so I need to get a new box from the craft store at the moment.

I use one pole of a dpdt as the on-off switch, when you turn it on it powers a 7805 to convert 9v to 5v, arm moves off a microswitch which powers the circuit when dpdt is in power-off position, arm moves to turn dpdt to power-off position, second pole of dpdt closes to send signal to pin4 which moves arm back to open microswitch and removes power from the 7805. Sadly the capacitors needed to smooth the power held enough juice to move the servo off the microswitch, which caused the servo to cycle off and on the microswitch. I found I could drain the power to ground but broke the box trying to get the microswitch flipped around so I could do that.

' useless_box.bas - using picaxe as controller
' pin1 is led, servo is pin2, off switch(dpdt) pin4
'need to debounce open micro-switch, try grounding non-power side
' by connecting ground to center pin of microswitch to drain capacitors
' or figure out code to do so.

input 4 'second pole of dpdt
output 1,2 ' led is output 1, servo is output 2
low 1 'set led low

gosub switch_off: 'move arm to turn dpdt switch power open, input 4 closed
gosub detect_off: 'sense that switch has been turned to off position
end ' nothing else as power should be off at this point

switch_off: high 1 'led on
for b2 = 65 to 220 step 5
servo 2,b2 'servo on pin 2 gets signal to move to switch off
pause 9
next b2

if pin4 = 1 then shut_down:
pause 50 'added delay to detect pin4
goto detect_off:

shut_down: 'move arm back to rest position
low 1 'led off
for b2 = 220 to 65 step -5
servo 2,b2
pause 9
next b2
return ' power is off at this point

I have the same servo and im getting the same thing it only wants to go one way

lol, hopefully this works for you, but back when this was a problem I didn't know that you had to connect all grounds together, once I did that everything worked like a charm,when it comes to electronics it usu isnt a hardware failure and probably the simplest of mistakes (like tying all grounds together) that causes the most grief, in this case it was my own ignorance :P

i can't see any problem nor could my uncle so maby its the code could you send me the code you used

here you go: loop: servo 2,75 ' move servo to one end pause 2000 ' wait 2 seconds servo 2,150 ' move servo to centre pause 2000 ' wait 2 seconds servo 2,225 ' move servo to other end pause 2000 ' wait 2 seconds goto loop ' loop back to start

hrm, Ive tried lots of various code, but regardless of what proper code I choose, all commands just make the servo turn to one side and then causes it to jitter ( i do have it on a separate power supply)

. Single-step through your code and verify the outputs with a VOM. . If the outputs are good, the servo is probably bad. . If the outputs are not good, then I would suspect something is not getting initialized properly or possibly a hardware problem

when I check the ouput of my VOM it just displays the supply current heading to my picaxe, I dont have access to a scope, so considering the pwm is occuring obviously about 50 times per second, how should I measure this with my VOM?

. Single-step the program so that you control how fast the outputs switch.

Is it possible your commands are trying to move the servo too far? That's all I've got, sorry.