| What
if you could control eight servos at once with just a single
chip and a few components. Here I have a Pic Micro 16F84
chip and I'm going to show you not only how to program and use
these microprocessors for animatronics but the stuff you really
need to know. |
 |
 |
Lets
take a closer look - as you can see theres not much to the circuit
design which makes it ideal for driving servos. Other than the
5 volt regulator, you dont even have to worry about heat sinking
anything when building it. I
put a 1000 microfarad capacitor between the supply voltage and
ground because when you run this many servos you want nice even
voltage and that cap will help keep it steady. |
| Of
course you want to use an 18 pin chip holder for the microprocessor
Im using a 24 pin servo header There's a 4mhz ceramic resonator
and a couple of resistors. Well that's about it for the circuit,
now you can see why it's so quick and easy to build. |
 |
 |
Now
let's take a look at what you need to program these chips.
1- You need a computer.
2- You need a programmer.
I am using an epic plus programmer (about $40)
|
| This
one has the ZIF or zero insertion force socket so you dont need
to pry the chip out of the programmer every time you set it
up. You connected it to the computer using the parallel printer
port. And of course you need the PIC 16F84 chip. |
 |
 |
Now
the most expensive thing about this setup is the compiler. it's
just a program you need to convert your BASIC code into a HEX
file that will be burned into the chips memory. We'll go over
the actual coding you will need a little later. |
| When
you are done writing your code, just open up the Programmer
software. and load your finished hex file. Your Hex files need
to be in the PBC (pic Basic Compiler directory) for them to
work. So I load up the Hex File and put the PIC in the Programmer.
The zif socket makes this a snap. Next - Just click 'program'
and your underway. |
 |
 |
The
Red LED on the programmmer will indicate it's working. IT's
really that simple. Now the PIC 16F84 is programmed with your
code so Let's put it in the Circuit and see how it works. Seat
the Microprocessor - be certain of Pin orientation. Connect
a few servos. Power it up and voila |
| On
the Power supply side, we have 5 volts to pin 14, and a 4.7k
pull up resistor between power and pin 4 MCLR. We also have
filtering capacitors between positive and ground. |

click
here for larger schematic |
This
is the 4 megahertz ceramic resonator which is easy to connect
one side to 15 - one side to 16 and the middle to ground.
click
here for larger schematic detailing the 4mhz ceramic resonator
or clock. |
Now
this series of pins - 6 through 13 are your I/O or input output
pins. Most of what we're going to do is on these pins.

We can use them as
inputs, like if we want to read the status of an
event trigger. we could use them as
outputs - driving a servo, or turning a relay on.
As they say, the sky is the limit and you will see that once
you get used to programming these microcontrollers, you can
pretty much use them for anything you dream up. |
We'll start by blinking an LED, then we'll move on to servo
control.
Line 1 - Typing HIGH 0 (zero)
- I am telling the PIC that I
want pin RB0 to go HIGH - (logic high that is.. 5 volts on RB0).
Line 2 - Pause 250 tells
the pic to wait (or pause) 250 milliseconds. which is 1/4 of
a second (on the 4mhz clock)
Low 0 tells
the pic that I want RB0 to go Logic low, zero volts,which
turns the LED that will be connected to RB0 off. |
I'll
show you how easy it is to write PIC
Basic code and use microcontroller to control
things. |
 |
when
the program is executed the PIC does excactly what I'ts told
- Nothing more. So it only did it one time, which is what
exactly what we told it to do.
The
PIC will execute line by line until the program is finished
and stop.
|
|
But that's pretty boring and I'm sure you can handle more so
let's modify the code a little. Typing in Start
- with a colon after it lets the PIC know that everything after
the word START should
be executed IF the
program encounters the word START.
I could have used pretty much any word instead of start,
because it's just a name, but lets keep it logical. |

GOTO start. When
the PIC encounters this directive, it goes to
start... and executes the commands line by line..
this is called a LOOP. |

Even if it may seem complicated, It's really not. In Halloween
Animatronics Volume 1 - You actually SEE how simple
it is! Plus you get several useful scripts included with your
purchase! From servo movement to turning stuff on and off and
more! All you have to do is copy and past it in your editor
or type it in and start programming your PIC's right away !
|
Ok, Let's move on .
A few simple rules when programming the PIC.
1-You have to tell a pin that it's going to be used as an
INPUT ahead of time but that's easy.
INPUT 1 tells that microcontroller
that RB1 is now considered an INPUT and it should LOOK
for a logic HIGH or logic LOW and remember what state the
pin is in until it checks it again.
What good is this? Well, if you had an event trigger hooked
up to this INPUT Pin, the PIC will just sit there waiting
until the trigger is tripped, then the PIC will perfom it's
routine ! That's handy, let me tell you !
Logic High = 5 volts / Logic Low 0 volts
|
| IF
pin1 is equal to zero (logic low) THEN
we want it to do something.. I want it to blink the LED. So
the microcontroller checks for a logic low on RB1 - if there
is not a logic low, it simply goes back and checks again. If
it SEES a logic low (zero volts) then it is commanded
to execute the BLINK part
of our program. It goes to the LINE with the word BLINK
and then executes the statements line by line until
it encouters the command GOTO START |
INPUT
1
start:
IF pin1=0 THEN blink
GOTO start
blink:
HIGH 2
PAUSE 500
LOW 2
PAUSE 500
GOTO start
END
|

seriously,
once you get one of these toys, you will be programming your
animatronics to do all sorts of very complicated tthings! |
OK,
when we run this program, RB1 has a logic low (zero volts)...
nothing is hooked to it.. so I't is executing the BLINK
part of the program. When I apply 5 volts, Logic HIGH, to RB1
the microcontroller sees
it and since it is not equal to 0 zero, it does not execute
the BLINK part of the program it just goes back to start and
keeps looking for logic low. |
| Allright,
enough of this.. let's program a SERVO.
This is the basic code I am going to use to tell a servo what
postion to be in. Do you Remember the Pulse we made with the
555 timer circuits? This is the same thing. We type in PULSOUT
and then which pin we are going to be connecting the servo pulse
to (in this case RB0) and how much pulse width we want. |
 |

click
here to see a better picture of this servo movement code |
PULSOUT 150 or 155 is about center position for most servos,
You can see the LOOP - FOR B0 = 1 to 60 and NEXT B0. Picbasic
wants to see variables in this form B- somthing.. for byte sized
variables or W - something for larger variables. So in order
to make this work, just use B0 as the variable. PULSOUT - pin
number and postion. 155 is about center position. |
| now
Just copy this code and paste it. I am going to change the pulse
width of this second loop to 100 which is going to drive the
servo LEFT Paste the loop once again and change the pulse
width to 200 to drive the servo RIGHT. Compile and
burn this code into the PIC with the software and programmer
board (EPIC) and the servo moves CENTER
then LEFT then
RIGHT then goes back and
does it again. Incidentally It
will never see the line that says END because the loop does
not allow it to ever get there but I always include the statement
END |
start:
FOR B0= 1 TO 60
PULSOUT 0,155 'center servo
1
PAUSE 18
NEXT B0
FOR B0= 1 TO 60
PULSOUT 0,100 'left servo 1
PAUSE 18
NEXT B0
FOR B0= 1 TO 60
PULSOUT 0,200 'right servo
1
PAUSE 18
NEXT B0
GOTO start
END
|
start:
FOR B0= 1 TO 60
PULSOUT 0,155 'center servo 1
PAUSE 18
NEXT B0
FOR B1= 1 TO 60
PULSOUT 0,155 ''center servo
2
PAUSE 18
NEXT B1
FOR B0= 1 TO 60
PULSOUT 0,100 'left servo 1
PAUSE 18
NEXT B0
FOR B1= 1 TO 60
PULSOUT 0,200 ''right servo 2
PAUSE 18
NEXT B1
FOR B0= 1 TO 60
PULSOUT 0,200 'right servo 1
PAUSE 18
NEXT B0
FOR B1= 1 TO 60
PULSOUT 0,100 ''left servo 2
PAUSE 18
NEXT B1
GOTO start
END |
So
Lets just add another servo to this program. Just type in
the pulseout, pin 1 for RB1 and the desired pulse width. CENTER
1 then in the next loop I just add the same line, and set
the pulse width so the servo goes RIGHT then in the final
loop I just add the line and set the pulse width so the servo
goes left.
Now
you should start seeing the advantage of adding the PIC 16F84
to your Halloween Animatronics. The PIC 16F84 can be reprogrammed
thousands of times so even if you mess up the coding you program
it with, you can simply fix it, then re- burn it.
Now
you wont need to make those pesky 555 servo ckts for the bulk
of your electrical animatronics, Just use the PIC or the BASIC
stamp. I prefer the PIC because it's only about $7 dollars
last I checked and the BASIC stamp microcontroller is much
more expensive. Here are some
PIC 16F84 links to check out

GET
YOUR FREE PIC 16F84 SAMPLES HERE
GET the COMPLIER and PROGRAMMER From
http://www.rentron.com/
|
| Now
you can see how to easily get started and seriously improve
your Halloween animatronics. The video shows you not only the
BASICS (yes you don't need to know electronics to get started)
and then gets you up to WARP SPEED with
nothing held back ! We go in depth with PIC routines
and then on to using Serial Sofware and automatically controlling
your Halloween animatronics using your computer and MORE, yes
MORE! |
|
| Click
here to go to Animatronic Neck designs |
|