Introduction: Arduino Balancing Robot

This details the final project for the Mechatronics course at Rowan University. For this project, a robot was designed and constructed to use an Arduino board, motors and an accelerometer to balance upright on two wheels. To accomplish this, the body of the robot was designed in Solidworks, and cut from acrylic using a laser cutter. The robot was then assembled, and Arduino code was developed to read the accelerometer input signal and output a signal to the motors. Values in this code were tuned to achieve a fine degree of control over the balancing behavior of the robot. An On-Off control scheme was used to code the robot. Ideally, a gyroscope would have been used to obtain more accurate position data, but due to purchase order delays and time constraints, an accelerometer was used instead. A list of parts used in this project can be found in the following Materials Section.

Step 1: Materials

- (1) Arduino Uno Board
- (1) 9V 1250 mA wall-wart

- (2) 12V DC motors ( )

- (1) MMA7455 Accelerometer (

- (1) Small breadboard

- (1 sq. ft) 1/4" acrylic

- (1 sq. ft) 1/8" acrylic

- Miscellaneous arduino cables, nuts, bolts, and washers

Step 2: Design

The robot body was designed in Solidworks, with the intent that it be relatively simple to cut and assemble using a laser cutter. It was also decided to design the body with a high center of mass by placing the major components near the top of the assembly, to improve the ease of balance. Solidworks files may be found attached.

Step 3: Construction

Holes were drilled and tapped in the edges of the acrylic sides to facilitate assembly. A breadboard was fixed to the inside of the front plate of the robot and the accelerometer was attached. The motors were attached to the side plates using screws and nuts, and the Arduino was fixed to the inside of the back plate using screws. The side plates were attached to the back plate using the tapped holes drilled in the acrylic. The front plate was attached between side plates in a similar fashion. The wheels were affixed to the axles of the motors.

Step 4: Circuit

The Circuit for this robot is relatively simple. It is composed of two 12V DC motors, which are wired to the Arduino through an H-bridge motor shield, and an Accelerometer. The 9V wall wart and USB cable must be attached to the Arduino's respective power and USB ports to power the robot.

Four connections must be made between the Arduino and Accelerometer:

- Accel. GND > Arduino GND

- Accel. Vin > Arduino 5V+

- Accel SCL > Arduino analog A5

- Accel SDA > Arduino analog A4

The positive and negative terminals of each DC motor must be attached to one of the two sets of positive and negative terminals on the motor shield, labeled "Motor A" and "Motor B". Six additional connections must be made between the Arduino and the motor shield:

- Shield GND > Arduino GND

- Shield Vin > Arduino Vin

- Shield B_IA > Ardunio Dig. 9

- Shield B_IB > Ardunio Dig. 8

- Shield A_IA > Arduino Dig. 11

- Shield A_IB > Arduino Dig. 10

Step 5: Code

The Arduino code was created to read angular position data from the accelerometer along the relevant axis of rotation (Z axis). An on-off control scheme was implemented to control the output power and direction of the motors based on the input angle data. This controller enabled the robot to balance upright, correcting for imbalances by moving the base, in the manner of an inverted pendulum. Arduino code used may be found below. This code utilizes two distinct libraries: The Wire Library, which is built into Arduino's IDE and used for controlling the DC motors, and the MMA_7455 library, which is used to read data from the accelerometer. You will need to download and add the MMA_7455 library to the Arduino IDE's "libraries" folder. This library can be downloaded here (click on the 'downloads' tab):

Step 6: Testing

Before testing, the accelerometer first needs to be calibrated. Hold the segway as vertically as possible and check the Z-axis value being printed to the serial monitor. Then, in the setup loop, use this value to replace the third zero in the line of code that reads: mySensor.calibrateOffset(0,0,0).

The code was tested, and values for the set points to switch directions on the motor were determined heuristically, through testing and refinement of the sensitivity of the accelerometer. Attached is a video of the Segway's performance.