I like to make things modular, so I created several general purpose modules. The original purpose of this module was to drive a servo motor based on 3 ultrasonic SRF05 inputs.
I made this so I could hook up more inputs then I used for the servos and the ultrasonic sensor
I used a Picaxe because it’s really a microchip PIC with a basic interpreter preloaded. It’s just pennies above the cost of a normal PIC and the ease of use is worth it.
The 3 servos are physically pointing towards the front, to the left and to the right.
Each one is pulsed in turn
The code turns the servo to one of 5 locations. The optimal values for the 5 locations are full left, half left, center, half right and full right.
The speed at which it turns was found via trial and error. The command ‘pulseout’ gives a length of pulse proportional to the location of shaft on the servo motor. Changing the ‘pulseout’ value in increments of 5, 10, 50 and the pause time, gives the movement speed. A minus step speed reverses the direction. One problem you can run into is that the movement is too fast and the servo overshoots one way, then the other, giving an oscillation effect.
I have included an PCB schematic in PDF form
I used Kicad (open source PCB software) to draw the schematic and layout the PCB.
The PCB has traces on both sides. With some extra effort Kicad can create a 3D view as well as gerbers. Here is the servo board
The three groups of four holes (P1,P2,P3) on the right are for the SRF05 detectors. (connections are power, pulse out, pulse receive and ground)
They feed into the 28 pin Picaxe (U19) on the left.
The three holes immediately above the (U21) 8 pin picaxe connect to the servo motor (J9 connections are signal Power and gnd).
U19 controls the 3 ultrasonic detectors by triggering a pulse and receiving the signal back from each one in order.The 3 numbers are converted from time in uS to the object to a distance number. Then based on the stored numbers the output pins at pin 26,27 and 28 go high or low the number can be 0 to 7. The number represent 5 locations front, left right mid-left and mid-right
In my application U21 scans the inputs available (in2, in3, in4), reads a binary number and jumps to the location suggested by the number. This translates the inputs to a rotational position turning the servo to the left or right. When it has finished moving the servo it rescans the three inputs, and makes the servo rotate based on the next set of numbers.