Lego Ball-and-Beam (BNB))

Lego Ball-and-Beam (BNB)

The photo and YouTube video above is a Lego-based Ball-and-Beam (BNB). The BNB is a classic setup used to demonstrate and teach control systems design. The objective is to keep the ball centered in the middle of the beam. When the ball is perturbed (i.e. pushed away from the center), the beam's angle is adjusted to restore the ball to the middle. Real-time step response plots (i.e. perturbation) from Excel data streaming, are shown below.

This tutorial presents the Parts List, Lego Build Plan, the mechanical and electrical construction, and operation. This version employs the Arduino UNO. However, a version using the NXT Brick and NXC language can also be used.

1. Motivation and Audience

Many engineering labs use turnkey BNB systems like those from Quanser. However, systems like these cost over $5000 USD. Google and YouTube searches reveals many DIY ball-and-beam (BNB) examples and demos. Some of these are also constructed from Lego. However, the performances are mixed and suspect. For example, some use light-weight balls, like ping pong balls. Here, the low moment-of-inertia of these balls, does not make for a challenging control problem. Others employ sensors like ultrasonic or infra-red distance or time-of-flight sensors. It is unclear whether the micro-controller used are sampling data quickly enough. Also, these sensors reflect off the ball and the "cone" of data is sensitive to reflections and scatter. Lastly, these DIY systems often are constructed by 3D printing parts. The net effect is that BNBs for classroom use suffers from cost, limited performance, and most importantly, hides underlying details.

Motivation was to provide every student a tackle box of parts. They could quickly assemble the Lego BNB without any special tools in under 30-min. Students can design controllers and run BNB experiments in their dorms, libraries, or classrooms. When the lab lessons are concluded, the BNB can be quickly disassembled and the tackle boxes can be stored until the next time the lab is offered. The total cost runs about $250 USD - the bulk of this cost is the Arduino UNO, EVShield, and Spectra Sensor linear potentiometer.

This Tutorial assumes the reader has the following background and interest:

2. Parts List and Sources

All Lego parts are listed in this Build Plan PDF | Studio IO file. Bricklink.com and Brickowl.com are good sources for parts. Additional non-Lego parts needed are listed in Table 1 below.

Table 1
Part Name/Description 2024 Price [USD] Quantity Notes
1-1/4 inch Hard Wear-Resistant 52100 Alloy Steel Balls $4.52 1 McMaster-Carr Part 9528K44
Spectra Symbol Sensor Linear 300mm Connector $31/73 1 Digikey Part 905-1055-ND
EVShield for Arduino Duemilanove or Uno $75.75 1 Sold by Mindsensors.com
Arduino Uno REV3 $27.60 1 Any Arduino UNO can be used
Male-to-Male Jumper Wires $8.29 1 Only 3 jumper wires are needed
9V 2A Power Supply for Arduino Uno $9.20 1 Needed to power Arduino Uno and NXT motor
XFasten Double Sided Woodworking Tape 1/2" x 36 Yards $16.49 1 Sold as 4-pack by Amazon. Just need about 12-inches/td>

3. Construction - Mechanical

The Lego Build Plan consists of 68 steps and takes about 30-min to complete. This may seem daunting, but it is modular. It mimics the Modular Integrated Landscaping System (MILS) popularly used in the Lego community. Each module is constructed using a layer of Lego plates. Modules are then connected using Lego friction pins. This provides a solid base to mount the motor. One can also experiment using different sized beams and/or re-positioning the beam's location on the base.

Step 3-1:

Follow the Lego Build Plan until Step 52. Before Step 53, one needs to attach the Spectra Symbol sensor as seen in the photo below. One precaution: don't use the tape that comes pre-attached to the Spectra Symbol sensor. It is very adhesive and makes it hard to remove when disassembling the BNB. Instead, apply double-sided tape and press onto the beam of the BNB. After affixing this sensor, complete Step 53 and continue to Step 68.

4. Construction - Electrical

Step 4-1: EVShield Hookup

Use three male-to-male jumper wires to connect the Spectra Symbol sensor to the EVShield. The EVShield's pinouts are shown in the figure below and detailed in the EVShield Advanced Development Guide (PDF). Make sure to power the Arduino UNO with the 9V 2A power supply. Not only does it power the Arduino UNO, but it will also drive the NXT motor (which can draw up to 1 to 2 A when loaded).

Step 4-2: Arduino UNO Code

Below is the Arduino sketch for bnbPid0_1e.ino. It is commented to make it easier to understand. It is an example of PID control. One would change the PID gains to desired response time and steady-state error.

6. Final Words

This tutorial presented a Lego Ball-and-Beam (BNB). It serves as a compact kit that a student can quickly assemble and conduct control system design experiments. It costs about $250 USD in total. Many of the Lego parts are common. Also many may have a spare Arduino UNO, 9V 2A power supply, male-to-male jumper wires, and double-sided tape. This reduces the cost mainly to the EVShield and the Spectra Symbol sensor. Arduino source code was provided and is self-explanatory. It implements PID control by reading the Spectral Symbol sensor's voltage reading.

A range of experiments can be conducted. For example, the beam's length can be changed by adding or removing Lego bricks. One could also change the pivoting position. One would re-attempt PID control given these physical changes. Future work would be use this Lego BNB to compare different control techniques (e.g. optimal, fuzzy, sliding mode) to PID. These would be topics in future Lego BNB tutorials.

For questions, clarifications, etc, Email: paul.oh@unlv.edu