For halloween I thought I'd make a robotic skull called ScareDuino that I could wear on my shoulder as a 2nd head, and that'd be controlled by an Arduino. A servo opens and closes the jaw, LEDs light up the eyes and a speaker makes a scary sound. All this is activated by a switch I hold in my hand.
Below is shown all the parts and a circuit diagram. The control box contains an Arduino Uno, a 9 volt battery to power it, a small circuit board with some resistors and around 5 volts of AA batteries connected in series to power the servo.
Below you can see the inside of the skull from the back. The eyes are each an LED inside bottle caps with aluminum tape wrapped around the back of them to prevent too much light from going anywhere except forward. The servo is a small one that works a lever arm that's attached to the back of the jaw. And the speaker is a small electromagnetic one taken from a gift card.
The hand control is simply a momentary switch and an on/off switch. When the momentary switch is pressed the Arduino begins its sequence of activity, which runs for a fix period of time. If the momentary switch is released before that time is elapsed then the activity is ended sooner. The other switch is for cutting off power to the servo for times when it's not in use, to save battery power.
The sound vs motor challengeTo open and close the jaw I wanted to use a servo since it was such a simple and low torque action and a servo suits that well. A DC motor requires an H-bridge and possibly some sensors and more complex code, and a stepper too requires more complex code. I knew of two sound libraries, the first being Talkie on github.com which I also go into detail on here on my Arduino speech synthesizer page and the second being Mozzi on github.com. Talkie gives a compilation error if you include Servo.h in your Arduino code which means I couldn't use it with a servo. Mozzi looks like it might work with more motors than Talkie but requires an abstraction layer which I didn't want to use since I wanted to keep it simple and learn vanilla Arduino. Luckily the Ardunio comes with the tone() function which allows you to use simple PWM to make sounds with just an attached speaker and a resistor if needed. The sound is like the old 8-bit sound but did the job. And it doesn't conflict with the servo library. The Arduino source codeBelow is the source code for this Arduino skull project. It's also in this downloadable file scareduino_arduino_controlled_skull.zip. The actions may seem simple, but couldn't be written with a loop() function that was simply a sequence of actions and sleeps (calls to delay().) Instead it had to be a proper microcontroller loop function that doesn't sleep so that if the switch was released at any time, the jaw would start closing. So the loop instead checks the switch positon and then goes into a state machine to see what to do next. The sound is pretty simple, consisting of a rising frequency while the jaw is opening, followed by a constant frequency while the jaw is open, and then a falling frequency while the jaw is closing. However, since it uses the tone() function, all sorts of funky sound manipulations could be done, possibly under the control of an array of frequencies and durations. /* ScareDuino - Scarey skull controlled by an Arduino. When a switch is closed this: - turns on two LEDs, - starts playing a sound at a certain minimum frequency and - starts opening the jaw, but does so in small steps. While the jaw is still opening this: - continues to increase the sound frequency and - continues to open the jaw in small steps until a certain time is up. The jaw is left open and the sound continues playing for a predetermined period of time. When that time is up this: - starts decreasing the frequency and - starts closing the jaw in small steps until the same time as was used for opening is up. When the time is up this: - turns off the sound - turns off the LEDs. At any time during the above process, if the switch is opened, then the LEDs and sound are turned off and the process of closing the jaw in steps is begun. The motor also has a switch that the Arduino doesn't know about that controls power to the servo. If that switch is off then the jaw simply won't work. NOTE: tone() causes interference with pins 3 and 11. To see it in action, go to: http://rimstar.org/science_electronics_projects/arduino_controlled_skull_scareduino.htm */ #include Video - ScareDuino - Arduino controlled Skull with Servo, LEDs, SpeakerThe following video shows ScareDuino in action and goes over the various parts. Video - How to Make ScareDuino - Arduino controlled Skull with Servo, LEDs, SpeakerThis video goes through step-by-step how this Arduino controlled skull was made. | |||||||||||||||||||||||||||||