These Android figures are cute, but they don't actually do anything. Let's change that. Have a look at the video:
These are the steps to make an Android that reacts to sound, moves it's head, sends out Morse Code messages and displays some cool light patterns. In the video the LEDs in the body are not that visible, but this is what it looks like:
Step 1: Parts and Schematics
1 x Android Figure from DYZPLASTIC
1 x ATtiny44A from Mouser or Digikey
1 x 14 pin DIL socket e.g. from Digikey
1 x Micro Servo SG90 (plastic) or MG90S (metal)
1 x Microphone e.g. CMC-5042PF-AC from Digikey
1 x Piezo (passive, not the buzzer kind)
2 x blue 5mm flat top wide angle LED from ebay
1 x red super bright 5mm LED
1 x green super bright 5mm LED
1 x yellow super bright 5mm LED
1 x NPN Transistor e.g. 2N3904 from Digikey
2 x Rectifier e.g. 1N4003 e.g. from Digikey
1 x 100uF electrolytic capacitor
3 x 100nF ceramic capacitor
2 x 100K resistor
2 x 10K resistor
2 x 2K2 resistor (or other values depending on your blue LEDs)
3 x 150 resistor
1 x +5V power supply (e.g. USB charger)
There are many different versions of the Android figure. If you want to have LEDs inside the body, it is probably best to choose a light colored Android. Darker ones might block the light shining through too much.
For the eyes I used super bright wide angle 5mm flat top LEDs. They are actually too bright, so I used some larger resistor values to adjust for that. Try different values until the maximum brightness is to your liking.
I used a Mystery SD90 servo with plastic geras. After 2 months of heavy use it wore out. I have now replaced it with a T-Pro MG90S which has metal gears. It is more noisy, but hopefully that one will last.
A +5V USB phone charger makes a nice power supply.
To program the ATtiny44A micro controller you can either use an official Atmel programmer like the AVRISP mkII or one of the many third party programmers.
Step 2: Electronics Assembly
Try to keep everything as small as possible. Solder the resistors directly to the LEDs. There is more space inside the Android.
Step 3: Open Android
Step 4: Modify the Body
The head needs to be able to rotate easily. Trim off about one millimeter around the inner edge of the body.
Step 5: Prepare Head for Servo
Step 6: Install Servo
Step 7: Install Electronics
The power comes in from the back, for instance into one of the feet. For better stability cut off the USB connector and use thinner, more flexible wires for just the power.
You may want to drill a few small holes where the microphone and piezo are located.
Step 8: Software
The servo is controlled by a 50 Hz software PWM. Servos from different manufacturers have slightly different PWM pulse width min/max values. It is important that these are adjusted accordingly. Otherwise the servo may get damaged if it is driven repeatedly over it's limits.
The piezo requires a frequency in the kHz range. The AVRs hardware PWM is used to drive it.
One of the ADC channels is used to read the output from the microphone amplifier. When a certain threshold is reached, the head movement is triggered. Different microphones have an impact on the output of the amplifier. The trigger level can be adjusted in software. Mine is set so that it ignores normal conversations, but get's triggered when things get excited. It's also a good sneeze detector. :-)
The ADC is read from an ADC interrupt. If this interrupt handler is active while the PWM timer interrupt fires, it can introduce a slight jitter to the PWM. This jitter may cause the servo to move a little, which produces enough noise to trigger sound detector. There are two possible solutions to this problem. One would be to not use an interrupt for the ADC and read it in a wait loop instead. This can be a bit tricky and ugly. Instead the current solution is to simply disable the servo PWM pulse while the head is not moving. This will turn of the motor, save energy and PWM jitter will not cause any problems. In general the sound detection is only active while the Android is quiet, as any Morse code beeps or head movement would also trigger it.
One of eight Morse code messages is played at random. Wikipedia has a great Morse Code article. The Morse Code alphabet is encoded in a table which translates ASCII characters to the corresponding Morse signals using a two bit encoding. The actual Morse Code messages can therefor be stored in easy to read and space efficient ASCII strings.
The source code can be compiled and programmed into the MCU wit the free AVR Studio IDE. There are open source alternatives as well.