A model broomstick driver

#1
One of my pastimes is working on and exhibiting my model railway "Angst-Lesspork", which is a tribute to the Discworld books of the late Sir Terry Pratchett.

The witch on her on her broomstick going up and down is always a crowd-pleaser. However up to date, it relies on the operator having a free hand to either gently pull the cord at the rear of the layout (to make the stick go up) or let it go - again gently - down.

So; could I motorise the effect? I considered using a motor and gearbox to wind the cord in and out, but then someone suggested I could use a servo motor as they were quiet cheap these days. My investigations revealed that I could get a miniature servo for around £6 and also that my preferred microcontroller, the PicAXE can drive a servo using just a resistor. Great!

I bought a servo and breadboarded a suitable circuit to familiarise myself with using the servo. After an initial set-back using the in-built servo commands, I received a work-round solution from the PicAXE user forum and made up a working system.

The witch moves through 60 mm, so I made an actuator arm out of 3mm plywood long enough to encompass that distance when rotated by the servo through about 90 degrees (actually more like 95 degrees) The arm is fixed to one of the plastic actuators that came with the servo.

The PicAXE is programmed to move the arm from one end to the other at pseudo random intervals of up to 65 seconds. There is a s.p.d.t. switch that can be used to force the system to go to one or other of the positions and stay there.

Here's a sketch showing the working details.
Broomstick driver by H Norwood, on Flickr

The witch and broomstick are mounted on the end of a length of 0.45mm brass wire, which passes through a collar in the baseboard. The lower end of the wire sits in a short length of "cotton bud" tube which itself is tied onto the end of a length of cord. A counterweight made of a couple of "penny" washers adds enough weight to ensure the witch descends nice and smoothly.

The cord passes over a couple of rollers and is passed through the baseboard and is hooked over the end of the servo arm. In transit, the witch and wire are stored in one stock box, whilst the cord is unhooked from the servo arm, pulled tight at the rear and held fast.

And here is the circuit diagram:
Broomstick driver by H Norwood, on Flickr

I may have over-engineered the power supply, but the PicAXE manuals suggest the servo should have its own supply; I might have got away with a simpler RC decoupling on the 5v line...

Anyway, here is a photo taken from one end of the layout showing the witch in the air and the servo mechanism. The bead in the cord below the actuator arm prevents the cord dropping too low and allowing the brass wire that supports the broomstick from disengaging with the cup that holds it.

Broomstick driver by H Norwood, on Flickr
 
#2
And here is the code for the system:

(and for the life of me I can't recall why I put the commented "stay-put" lines in it!)


Code:
; test_servo
; 22 March 2018 HN
; some testing of servo control with the 08M2
; 27 March 18 manual control only
; test_servo_v 29 March 2018 tweak the if statements in main

symbol servodriver = C.1  ;servo output
symbol OldPos = b0 ; old position for servo
symbol NewPos = b1 ; new position for servo
symbol GoUp = pinC.3  ; move to one end
symbol GoDown = pinC.4  ; move to other end
symbol PosHigh = 205
symbol PosLow = 95  ; thes set the maximum throw
symbol DelayServo = 20  ; a delay constant to slow down the servo
symbol CntDly = w4 ; a word variable for random pause

; both C.3 and C.4 will be taken high with resistors
; C.4 is actually pin 3
; C.3 is actually pin 4
; C.1 is actually pin 6

init:
	output servodriver ;make pin an output
	low servodriver    ; and set it low
	CntDly = 1234      ; set counter
	random CntDly      ; start random number generator
	NewPos = PosHigh
	OldPos = PosHigh  ;initialise variables the servo should be up
	pulsout servodriver,NewPos
	pause 20
	pulsout servodriver,NewPos
	pause 20
		; init servo	
	if GoDown = 0 then
		NewPos = PosLow
	endif
	gosub DriveServo
	
main: 

	if GoUp = 0 then
		NewPos = PosHigh
		gosub DriveServo
	elseif GoDown = 0 then
		NewPos = PosLow
		gosub DriveServo
		pulsout servodriver,OldPos  ; brief "stay put" to servo
		pause 20
		pulsout servodriver,OldPos
		pause 20
		
	else
		gosub ChangeRandom ; only do random if both switches are HI
	endif
	goto main


	end  ;end of main loop

	
	;subroutine
	
	DriveServo:
	;subroutine from the picAXE forum to use pulseout
	; to drive a servo
	; check if nothing needs to be done
	if NewPos = OldPos then
		return
	endif
	; work out if we are going up or down
	b2 = NewPos - OldPos
	b3 = 1
	if NewPos < OldPos then
		b2 = OldPos - NewPos
		b3 = $FF  ; minus one
	endif
	
	NewPos = OldPos
	for b4 = 1 to b2 ; loop and change the pulse time
		NewPos = NewPos + b3
		pulsout servodriver,NewPos
		pause 20
		pulsout servodriver,NewPos
		pause 20
	next b4
	OldPos = NewPos
	return
			
	ChangeRandom:
	; routine to generate a random delay up to 65 seconds the change direction
	random CntDly
	if OldPos = PosHigh then
	NewPos = PosLow
	else
	NewPos = PosHigh
	endif
	pause CntDly
	gosub DriveServo
	return
The discussion about servo driving took place over on the "Active" forum - my thanks to those who contributed.
 

hippy

Technical Support
Staff member
#3
Nice project and nicely described. The power supply may be over-kill but better to be over-engineered than under.

Even small servos can draw considerable current ( an amp or more ) as they move and this can cause disruption to the rest of the circuit, including any PICAXE. As it is just a PICAXE you may have been able to get away with a diode driving a capacitor, but it's often just as easy to fit a 7805 and not excessively more expensive.

Code:
           .-----.
9V >---.---| REG |---.-------.-----> 5V Servo
       |   `--.--'   |      _|_
       |      |      |     _\ /_
       |      |      |       |
       |      |      |       }-----> 5V PICAXE
     __|__    |    __|__   __|__
     =====    |    =====   =====
       |      |      |       |
0V >---^------^------^-------^-----> 0V
 
Top