top of page

Hexbug Hack

Give your Hexbug a Real Brain!
Chapter 3 - Controller Design - New Brains -

The new controller will need to replace the functions of the original board:

Motor control- Forward and Reverse
Detection of obstacles- Antennae
(No microphone- for reasons that will become clear later.)

And will add:
Motor Off
Blinkable ‘Eye’
Low battery detection
Light level detection

To implement this, the first item needed will be an 8 pin, Microchip PIC microcomputer. The PIC series can run on voltages as low as 2 volts, and use less than 1 micro-amp in sleep mode. (Microchip provides excellent support and Application Notes for the PIC chips, and provides a free compiler/debugger, as well as inexpensive programming modules- More on this later.) Next, we need an H-bridge to control the motor, the original antennae, an LED, a piezo-buzzer, and a voltage reference.

But where is the light level detector? Here we use the LED in two different ways- as both a light source, and light detector. This works because the I/O pins on the PIC chip can be reprogrammed on-the-fly, and this ability will be very useful in implementing the rest of these functions.

So, how many control pins from the microcontroller do we need? To be able to fully control the H-bridge we need 4 pins. The antennae will need 1 pin, and the LED 1 pin. The piezo-buzzer 1 pin, and voltage reference 1 pin, but here we have two complications.

1) The piezo-buzzer will not be very loud at the low 3 to 1.8 supply voltage. This can be doubled to a peak-to-peak voltage twice that (6 to 3.6 volts) by driving it differentially from 2 pins.

2) The voltage reference will need an additional pin to turn it on and off to conserve power.
This gives us a total requirement of 10 pins. Oh, we also need power and ground- that’s 12 pins. We only have 8, and it would be nice to have some available for future expansion. We need to re-use pins.
Let’s start with the H-bridge. Four pins will give us 16 possible combinations, or states:


H-Bridge and Cross-wired Bridge with On/Off Switch


We only need three states- Forward, Reverses and Off.

Cross wiring the bridge will require only 1 pin instead of 4, giving 2 states, Forward and Reverse. One complication with this configuration is ‘shoot-thru’- as the MOSFETs change state, both the ‘P’ and ‘N’ are momentarily on at the same time, and a large amount of current 'shoots thru'. If one more MOSFET is added, the H-bridge can be switched On and Off, giving us the Off state, and shoot-thru can be prevented if we are careful to turn the bride off before we change direction. The On/Off control line needs to be dedicated, however, or re-using it could turn the motor on when it’s not needed.

Now we’re down to 10 pins.

One pin can be used to power the LED and drive one side of the piezo-buzzer. By re-configuring that pin to use the PIC’s A/D converter, it can read the voltage reference or the LED’s voltage when it’s working as a photocell. ( Yes, an un-powered LED is a photocell; any diode is a photocell. If a discharged capacitor is placed in parallel with an LED, the LED will convert photons to electrons, and start charging the capacitor. The more photons the LED picks up (brighter light source), the more electrons, and the faster the voltage on the capacitor rises. By measuring the voltage after a set time period, the light level can be determined.) Another pin is assigned to power the voltage reference, and can also be used to power-on future expansion modules. One more pin is needed to power the other side of the piezo-buzzer, and can also be used for future expansion- if the piezo-buzzer’s other leg is connected to a pin that the PIC chip turned off (set as a high impedance input), it can be re-used as a digital In, Out, or Analog In. (In most cases, it doesn’t matter what the other leg of the piezo-buzzer is connected to, as it will appear as a small capacitor.)
So, here are the pins we really need:

And, we still have two pins left for power and ground.

For the 8 pin PIC chip used for this upgrade, pins 1 and 8 are assigned to power and ground, respectively.

Pin 4 is input only, and must be available for programming, so this is a good choice for the antennae. Pins 7 and 6 are used for the In-Circuit-Serial-Programming (ICSP) function, and must not be loaded with a capacitance (the piezo-buzzer) or a low resistance. Pin 7 will be connected to the dedicated motor on/off signal, as the gate of the MOSFET has very high impedance, and will not interfere with programming, and pin 5 as the motor direction control. Pin 6 is assigned to drive the piezo-buzzer, but will have to be switched between the ICSP programming function, and driving the piezo. Pin 2 is assigned to powering the voltage reference and external expansions, and Pin 3 is assigned to the LED, piezo and voltage reference.


Pin-1Vdd- Power
Pin-2GP5- Voltage reference & expansion power
Pin-3GP4- LED, voltage reference, Piezo-buzzer
Pin-4MCLR, GP3- Antennae
Pin-5GP4- Motor Direction
Pin-6ICSPCLK, GP1- Piezo-buzzer
Pin-7ICSPDAT, GP0- Motor On/Off
Pin-8Vss- Ground

Because the motor is a brushed DC motor, it can produce inductive voltage spikes on the power buss that could disrupt the PIC’s operation. This is easily remedied by placing a filter inductor between the PIC’s power buss and the motor’s.
Resistors are also needed to keep the H-bridge in the ‘Off’ state while the PIC is in sleep mode.
Also needed are connector pins for programming, switching of the dedicated programming pins, and a means to turn power off. This can be solved by bringing these signals out to a row of header pins at the back of the board. A jumper block can be used to switch power and the programming pins used for operational mode. Another header can be used to both connect a programming cable, and also disconnect the battery, and power to the motor.

Now a schematic can be created, and a printed circuit board can be laid out.

(Click image to enlarge)

- The Great Revision -


The Improved Hexbug PC board - After building several upgraded Hexbug’s using the HXB14c PC board, and doing various experiments and evaluations, I realized that a few modifications and adjustments to the original design could make it even more versatile. So, after further analysis, the following modifications and features where added to the original HXB14c printed circuit design:


1) Minimize any changes that would make the new board incompatible with the original HXB14c design and its software.


2) Layout the PC board to allow the use of either a surface mount SOP or leaded DIP package. This enables lowering the Bug’s shell to the original height with the SOP, but will make replacing the PIC much more difficult. The mounting holes for the DIP have been slightly enlarged to allow the use of individual, flush sitting, socket pins instead of a standard, above board socket. This also allows the shell to be lowered.


3) Allow the use of either or both surface mount and leaded capacitors, and use only the ‘larger’ (right... .120x .060 inches is large) surface mount components to make hand soldering a bit easier.


4) Using just the one (Cyclops eye) LED light detector complicated tracking the direction to the brightest light. Providing placement for two LEDs improves this, and looks more like ‘Eyes’.


5) Move the ZXRE4041’s output to the ADC Vref input pin. (This is the only significant change to the software configuration due to the hardware changes. Pads for an additional surface mount resistor to use the same configuration as the HXB14c board have been provided.)

Why move it?

6) The LED light detector configuration used the 10-bit ADC with the supply voltage as its reference voltage. With fairly new batteries providing a full scale voltage reference of 3.0 volts, 1 bit equals 3.0/1024= 3mv. This does not allow very good discrimination of different low light levels. If the ADC is supplied with a lower voltage, external reference (via the pin 6 Vref), one bit now equals 1.225/1024= 1.2mv per bit- better than double the discrimination. (There may be other advantageous uses for this configuration.)


7) If instead of turning the Vref on with one pin and reading it through another, a capacitor is placed in parallel with it, then only one pin is needed. (This means more flexibility for further expansion) This one pin first charges the capacitor to the reference voltage, then is reconfigured to read it. Though some careful analysis must be done first, the results are very stable and repeatable. The voltage on the capacitor does slowly decay, but at a rate of 30mv/sec (measured), and with an A/D conversion rate of 45µsec, a lot of conversions can be done before there is a significant change in accuracy. This can even be used to advantage to improve the sensitivity of the LEDs as photo detectors. If the capacitor voltage decays at a known rate, the software can delay reading the ADC until the voltage is lower. This results in more bits per millivolt.


8) Although the IR receiver module could be mounted anywhere, and wired to the PC board (this is still an option), mounting holes have been provided to mount it directly on to the PC board.


9) The option of using the header-jumper to switch power, or install the Bug's original miniature switch to turn it on and off is now avalible. If you wanted to preprogram the Bug as a gift or presentation prize, a non-technical recipient would be less confused by a standard switch as compared to the jumper.


10) Easier mounting of the filter inductor, L1. The original layout required the leads to be scrunched-in to fit onto the PC board.


11) A capacitor has been added across the motor terminals to reduce electrical noise and add protection for the MOSFETs from inductive spikes.


These modifications required moving most of the parts, so the new HXB27e board has a new parts layout diagram. It uses the same parts, and is tolerant of variations on some of these. The resistor that limits current to the piezo and LEDs can vary from 150 ohms to 1K. Larger values will save power, but give softer sound, and dimmer LED’s. Smaller values will reverse these effects. The values chosen are a good compromise.


Assembly is basically the same as the original HXB14c. The only changes are the addition of several new components.

NEW HXB27e Schematic

Why no Microphone?

Duplicating the current ‘clap to turn’ function of the original board adds limited functionality, and increases power consumption.To be really useful, the input from the microphone should be processed to convey more information than just the detection of a loud noise. (We are trying to build an autonomous Robot, not replace ‘The Clapper’.) A more useful sound detection system would use a phase-locked-loop (PPL) to detect specific tones, and use these as command inputs. By using an IR receiver module, and a TV remote control, a simpler, lower power method for remote control and programming can be implemented.A more complex sound control/communication system could be created, but would use more power, and would best be implemented as a separate module that could be turned off to conserve power when not needed, or in ‘Sleep’ mode.Besides, it is more entertaining to have the Bug do all the talking.

1]The micro-robotic Hexbug is the result of collaboration between Ignition (Plano, TX;, an industrial design and development firm, and Innovation First Inc. (Greenville, TX;, a product engineering company. RadioShack is the exclusive North American retailer of the Hexbug. Bandai, the leading toy manufacturer in Japan, also recently signed a deal for global distribution rights, with plans for other products to follow. “We had a rough idea for this product, but Ignition brought it to life,” says Joel Carter, VP of marketing at Innovation First. “They transformed our concept into a viable market-ready product and helped us to create an entirely new product category.”

Anchor 1
bottom of page