Balancing Robot

This page is about my inverted pendulum 2 wheel balancing robot.  The robot has six PIC processors from Microchip Technology that handle all the functions including receiving control inputs from a Hitec RC controller, controlling and filtering the inputs from the IMU module, reading the slotted encoders, controlling the CMUcam camera module and sonar ranging sensor, and controlling the speech synthesizer chip.

The video linked below shows a demo of the functions of the robot.  The first part shows the robot balancing and moving around under manual remote control from my Hitec radio control.  The second part of the video shows the head following a red ball that I’m holding.  The robot speaks a random phrase whenever the camera re-locks onto the ball.  The mouth LED patterns are mapped to the speech synthesizer vocal elements so it follows whatever is being spoken.  The last part shows the robot following the red ball while balancing.  The head follows the ball to track it and the balancing drive compensates to turn in the direction the head is facing.  The sonar sensor detects the distance to the ball and sends information to the balancing drive so it moves forward or backward to try to keep the robot a fixed distance from the ball.

Front and Back Views

The CMUcam module is the right eye of the head assembly and the sonar sensor is the left eye.  The LED matrix displays the “mouth” of the robot.  There’s a speaker behind the LED matrix for the synthesized voice.  The main 24 cell NiMH battery pack is at the top of the robot, and the circuit boards are mounted on both the front and back of the body.  The motors and another 6 cell battery pack are at the bottom.

Chassis Construction and Gear Train

The main chassis is constructed from aluminum angle and sheet stock.  The motors are some surplus gearhead units I got from Gateway Electronics.  The wheels are 5 inch diameter Du-Bro model airplane landing gear wheels from Tower Hobbies.   The slotted encoder parts are from an old mechanical wheel-type mouse. I used both the slotted wheel and the LED/photosensor part from the mouse, remounted on a piece of perfboard. The aluminum cover helps keep out stray light. The shaft of the slotted encoder is fixed into an aluminum hub that turns inside a rollerskate ball bearing.  Note that the slotted encoders are used only to determine the distance moved by the robot – they are not used to balance the robot at all. The balancing data comes from the IMU module (see below) which outputs an angle that is used to drive the wheels either forward or backward to maintain an upright attitude.  The motors, encoders, and wheels connect via three gears. The drive gear attached to the motor has 24 teeth, the one on the slotted encoder has 14 teeth, and the one attached to the wheel has 72 teeth.  The large gear is attached to the wheel and the assembly is drilled to accept a bronze bushing that rolls nicely on the 1/4″ steel axle. Setscrew collars on the ends of the shaft hold the wheels on the axle.

Circuit Boards

The schematics and circuit boards are drawn and designed using the freeware version of Eagle CAD.  There’s a 160 by 100 mm size limitation for the free version, and these boards just fit within that limit.  Once the PCB was designed, it was printed on a PNP-Blue transfer sheet on a laser printer, and then ironed onto a bare copper clad board.  About 1/2 hour of agitation in ferric chloride removes the unwanted copper.  Then comes the drilling of hundreds of tiny holes.  I used the same PNP-Blue iron-on technique to apply a parts layout to the top of the finished boards – it sure makes populating the boards easier.

Master/Receiver, IMU, Sensor/Encoder, and Motor Driver Boards

  • The master processor board has two PICs – the receiver PIC decodes the radio control receiver’s PWM outputs and passes the results to the master PIC which controls the whole system.  All software running on the robot was flowcharted and then coded in assembly language.
  • The IMU (Inertial Measurement Unit) processor board has a PIC that implements a Kalman filter to process inputs from a solid state three degree of freedom module from Sparkfun Electronics.  The module holds an Analog Devices ADXL320 accelerometer and ADXRS401 gyro rate sensor.
  • The Sensor processor board has two PICs – one to capture data from the slotted encoders to provide position feedback (but not balance information). The other PIC on this board handles communication with the CMUcam1 camera module and a Maxbotix LV-EZ4 ultrasonic range finder.
  • The H-Bridge motor controller board takes PWM direction and enable commands from the master processor to control the two drive motors.

Speech Processor, Battery Monitor, Bluetooth Module, and Speech LED Driver Boards

  • The speech processor board has a PIC that handles control of an old SP0256-AL2 allophone based speech chip.
  • The battery monitor board has comparator circuits to monitor the various battery voltages and light LEDs when the batteries drop below minimum levels. The board also outputs a signal to the speech processor to activate a vocal warning.
  • The bluetooth module provides a wireless link to the camera or master serial lines. It’s a JY-MCU bluetooth module and provides a convenient way to monitor parameters for debugging.
  • The speech LED driver is circuit is used to drive the 8 by 5 LED matrix for mouth animation. It connects to the speech processor board.

Head Assembly

Here are some closeups of the head assembly.  The CMUcam1 module is the robot’s right eye and the Maxbotix LV-EZ4 ultrasonic sensor is the left eye.  The speaker that outputs the audio from the speech synthesizer is located behind the mouth display LED matrix.  The speaker and LED display are attached to an articulated bracket that pivots upward as the eye section rotates downward.

Body Views

Here are a couple closeup pictures of the overall body arrangement and board packaging from the front and back.

Charging System

This is the charging system connected to the robot.  It is the same one that is used with my snake robot.  The first photo shows the charger connected to the motor battery banks and the processor battery.  When the green and red lights go out, the batteries are fully charged.  The second photo shows the charger connected to the camera & servo battery.  In normal use, the 9 cell motor banks take longer to charge than the 6 cell processor battery.  The red cable can typically be switched over and the 6 cell camera & servo battery can also be charged before the motor batteries are full.

System Block Diagram

The first picture shows how the system is interconnected via all the ribbon cables and header connectors.  The second picture shows how the system is configured when turned on and off. When the power switches are off, the 18 cell motor pack is electrically separated into two banks that can be charged independently.


  • Master and Receiver Processors:  Note the system bus is 8 bits wide plus various “ready” and “read” signals that are used to deconflict transfers between the processors. The system bus couples all the PICs on the robot – the master, receiver, encoder, sensor, and IMU processors.
  • IMU Processor:  This includes analog circuitry at the left side to take inputs from the Analog Devices ADXL320 accelerometer and ADXRS401 gyro rate sensor which are mounted on the IMU module.
  • Sensor and Encoder Processors:  The encoder processor handles data from the slotted wheel encoders, and the sensor processor handles control of the CMUcam1 module and the Maxbotix LV-EZ4 ultrasonic sensor.
  • Motor Controller:  This is an optoisolated H-Bridge design that drives the two motors providing balance and locomotion for the robot. It is driven by PWM outputs from the master processor.
  • Speech Processor and Speech LED Interface:  This board has an SP0256-AL2 chip to generate speech outputs.  The LED mouth matrix is also driven from this board.  The data latch signal from the PIC is used to latch the speech board data input when high and the LED board input when low.  Every allophone in the SP0256 has a corresponding mouth “image” that’s scanned into the LED array as the sound is uttered, rendering an animated set of lips.  See the video above for a demonstration.
  • Serial Debug Probe:  I didn’t want to have a whole bunch of RS232 to TTL drive circuits for all the serial lines in the robot, so this is a separate dongle that can be connected to up to 2 of the various serial ports for debugging.  
  • Bluetooth Interface:  Instead of having cables connecting the robot to a computer, this bluetooth interface can do it wirelessly.  The bluetooth module is a very inexpensive JY-MCU module available from many sellers online and on ebay.
  • Battery Monitor:  This board has comparator circuits to monitor the battery voltages and light LEDs when the batteries drop below minimum levels. The board also outputs a signal to the speech processor to activate a vocal “low battery” warning.
  • Charging System:  My NiMH charging system is based on Maxim MAX712 chips.  It is the same one used with my snake robot, with a 4 pole double throw (4PDT) mode switch added because of the different battery cell configurations between the two robots.

Comments are closed.