DIY servo controlled pneumatic switches

Unless you have the materials and the skills, this is not for you. I will use this in a robot I’m working on, but Mindsensors sells pre-made versions of the same concept.

What this allows you to do is, using either a RC receiver or a NXT servo controller, make pneumatic robots!

These things are relatively easy to make. Materials:

  • A drilling machine
  • A drill of the same size as LEGO pins.
  • A small drill for the servo screws.
  • A jigsaw
  • A pen
  • Misc. LEGO parts.
  • A small servo with horn and screws.
  • Plywood.
  1. Saw a rectangle big enough for the switch and the servo.
  2. Draw a line around the servo, and a dot through the pinholes of the switch.
  3. Drill out the pinholes, and make an extra hole on the servo outline.
  4. Open the jigsaw, and put the blade through the hole on the line.
  5. Close the saw and saw out the servo hole.
  6. Drill small holes for the servo screws.
  7. Attach the servo and the switch to the wood with any LEGO at hand.
  8. Bend a piece of iron wire around the switch and the servo horn.

Generic programming tutorial

I have wanted to teach you some programming since I started this blog, but I refrained from doing so, because there are so many ways to program, and I want to use them all.

What I’m going to attempt, is not to teach you a programming language, but teach about programming itself. This may seem useless to you, but my experience is that when you understand programming, the language does not really mater, and you can program in anything that is not excessively weird.

For practical reasons, any code examples will be written in NBC, Python, NXT-G and Clojure.

A computer

To understand programming, you first need to understand what a computer is. For our purpose, it suffices to think of a computer as a processor, a block of storage, and a block of memory.

This is true for desktops, smartphones, the NXT, and anything else with these components. Of course there are some other components involved, which can be divided in inputs(keyboard, sensor) and outputs(screen, motor).

What a computer does, is read instructions from the storage, execute them on the processor, which modifies the memory and reads/writes to the in- and outputs.

To give you an idea, you could put instructions in the storage that tell the computer to store the number 2 in memory, copy it, and multiply the two numbers, saving the result in memory.

A more useful set of instructions could put the input from the keyboard to the screen, or read a sensor, do some math and control the motor.

A compiler

When I said instructions, I did not mean instructions in plain English. Processor instructions are not easy to read and write for humans, that is why we let computers translate them for us.

In its most basic form, a compiler is a set of instructions which converts words like “add” and “read” to stuff that a computer understands.

More advanced compilers also allow you to define new words, such as “turn left”, in terms of other words, such as “motor on” and “motor off”.

A language

A language is a set of instructions, as understood by a specific compiler. A language consists of a few things.

A syntax

This is like grammar for compilers. A few examples of adding a number:

  • Python: 1 + 1
  • Clojure: (+ 1 1)
  • NBC: add 1 1 result
Which are all the same thing, except that NBC is a statement instead of an expression, more about that later.


This is the hardest part of programming. But let me tell you, even good programmers don’t remember all APIs, you simply google them.

An API is the set of words at your disposal to express your problem. This API is different for every language.

In NBC there is a word called “OnFwd” which can be used with an output, like “OnFwd(OUT_A)”, but in Python, there is no such thing. Python doesn’t even know what a motor is, or what forward means.

However, people have already defined words to talk about the NXT in Python. To use words already defined elsewhere, we can say “from nxt.motor import Motor, PORT_A” in Python. Now we can say “Motor(my_nxt, PORT_A).run()”


Expression have a value. The value of (+ 1 1) is 2, so we can also say (* 2 (+ 1 1)), which has the value 4.

People commonly say expressions ‘return’ a value, which is what you do when you define an expression in Python:

def expressions():
    return 2


Unlike expressions, statements do not have a value. What would be the value of “while True:”(the start of a loop in Python)?

Note that not all languages have expressions and statements.

NBC has only statements, which is why you write “add 1 1 result”, so that the result of the addition gets saved in memory.

Clojure has only expressions. if something has no useful value, it returns nil.

Python is a mixed bag.


So far I have talked about that block of memory as an abstract thing where you save and retrieve values. In reality, it is very useful to label the box you put it in.

For example, in Python you can say

x = 1
y = x + 1

These are statements that store the value of the expression. ‘x’ now references the value of 1, which is 1. ‘y’ is now a reference to the value of adding the value of x(1) to the value of 1(1).


So far we used numbers as values, but what if you want to talk about a collection of things?

languages usually provide means of defining a collection of things, and for doing things to the elements or the whole collection, like sorting it, or getting/setting elements.

An array of 5 integers in NBC:

dseg segment
  int reference[5]
dseg ends


We talked earlier about the words that make up an API. In most cases, words are also just references to values.

These values are usually called functions, and consist of a collection of other functions.

Not all languages have functions as values. In NBC, functions are statements, which don’t have a value. Clojure, however…

(def x 2)
(def square (fn [n] (* n n)))
(square x)

Here, I defined ‘x’ a reference to the value 2, and ‘square’ a reference to a function that multiplies a number by itself. The, I called the value of ‘square’ with the value of ‘x’, resulting in the value 4.

Learning a programming language

I hope to have given you a good understanding of how a programming language works. To actually start using a language like NBC, you need to find out a few things:

  • How do I use words/call functions?
  • How do I define references to values in memory?
  • How do I define new words?
  • What existing words do I have at my disposal?

A good starting place is usually a beginners tutorial. Google for “<language> tutorial” and click the first result.

After a section or two, they usually start to talk about how to do things. You might continue, or stop here, and get your hands dirty. If you run into trouble, simply google for “<language> how to <problem>” or find the function reference by searching for “<language> function reference>”.

If you are really in deep trouble, Stack Overflow is a great website for asking questions.

I hope this is enough preparation for you to start learning, and for me to focus on explaining how to do things in any language needed, like plotting a picture with the NXT 😉

RCX Snow Plow

Over here in the Netherlands we usually have just a few days or weeks of snow per year. When the time comes, there are three things that absolutely have to happen.

  1. Go sledging
  2. Go ice skating
  3. Build a robot to drive in the snow

I wont bother you with the first two items, but I thought you might like number three.

I was surprised that I couldn’t find a single video of  a snow plow, plowing real snow. There are robots pushing LEGO around, and static models of a snow plow. This is what I made.

The robot is a regular half-track, but uses a triangular tread configuration to keep the motor out of the snow. It also has a rotation sensor on the unpowered front wheels, to detect the robot isn’t moving.

I’m not sure if you are interested in the software or building instructions, because it uses the RCX with parts from Ultimate Accessories and Ultimate Builders sets, as well as miscellaneous red parts. Are you?

NXT model of Twente One Solar Racer

I wrote earlier about the solar panels I bought from eBay, and how I connected them to the NXT. The next logical step was of course to build a robot, so why not start out with a solar racer?

I’m Dutch, so I started to look at the cars of the 2 Dutch competitors for the World Solar Challenge, the universities of Twente and Delft. Delft has won for several years in a row, but I still decided to go for the Twente car from 2007, called the Twente One.

I had several reasons for choosing the Twente one. Emotional ones, like a team member that gave a presentation about the car at my old school. Technical ones, like that the powered wheel is not also the steering one. But maybe the most interesting reason is that they have a tilting solar panel, for which they won the innovation price in 2007.

With my LEGO model of the Twente One, I tried to add all the same features as the original model, including:

  • Direct drive on the rear wheel, although the NXT motors are in fact geared down
  • Double wishbone suspension on the front wheels
  • Trailing beam suspension on the rear wheel
  • Tilting solar panels

Winter probably isn’t the best time to try to build a solar racer, but I still made a video of it driving around.

Besides of course the solar panels, this model also requires these motorcycle wheels and 4 springs of the strong variety. I had to buy these myself as well, totally worth it IMO.

I did not include building instructions for the solar panel, as they are easy to make and yours might be different. You could also just use a piece of cardboard instead(but that would be cheating). The panel connects to 3 pivot points at the top of the car.

Download building instructions

Explorer robot without sensors

Usually the first robot you make when you get the NXT is the wheelbase with a bumper, you know, make it run into a wall, turn back and repeat.

To really get my point about saving sensors across, I made a robot like that without any sensors.

It works by turning the motors in regulated mode(constant speed, varying power) and measuring the actual power applied. If the robot runs into a wall, the firmware will apply extra power to the motors to keep them turning. With some tweaking, you can even detect which wheel hit the wall.

The commented code:

// define 2 variables for containing the actual speed
dseg segment
  aaspeed byte
  caspeed byte
dseg ends

thread main
  // turn the motors on, regulated
  // wait for the robot to accelerate
  // it will apply full power here
  wait 1000
  // get the actual power used
  getout aaspeed OUT_A ActualSpeedField
  getout caspeed OUT_C ActualSpeedField

  // print the power to the screen
  NumOut(0, LCD_LINE1, aaspeed)
  NumOut(0, LCD_LINE2, caspeed)

  // if one of the motors uses more than 75 power
  // jump to either LResistance or RResistance
  brcmp GT LResistance aaspeed 75
  brcmp GT RResistance caspeed 75

  // repeat forever
  jmp Forever

  // reverse, turn right, jump to start
  wait 2000
  wait 500
  jmp Start

  // reverse, turn left, jump to start
  wait 2000
  wait 500
  jmp Start

Saving sensors with structural limits

When building a robot with some sort of back-and-forth motion, such as a steering car or a robotic arm, you commonly see touch sensors at the end or center to easily move to that point.

However, the NXT motors have built-in rotation sensors, so with a bit more fiddling, you can get rid of most touch sensors in your system by using the structural limits of the model.

The basic idea is that you move the motor slowly forwards until it doesn’t go any further, record the tacho count, rotate backwards slowly until it stops, record the tacho count. Now you know the center point(the average of the two), and you can move to any point within the limits real quick.

In NXT-G this can very easily be done using the PID block by HiTechnic, but it does not give you the endpoints, which you can notice in the video.

In NXC there is a more powerful absolute position regulation, implemented at firmware level. Flexible, fast, precise, awesome.

NXT on solar power

Just as I was thinking about what it would take to make a mars rover with the NXT, I found the dSolar panels from Dexter Industries. How cool is that, a mars rover that actually runs on solar cells!

However, $100 seems a bit expensive for such a nice-to-have feature. Looking around on eBay revealed you can get more power for half the money, only it doesn’t come in a LEGO friendly package.

I bought them anyway, and documented the customizations. Soldering iron required!

[update]: It is recommended that you put diodes between the panels, see comments below.

So basically I connected the panels in parallel with a few plugs from an old computer. The whole thing is connects to the NXT via 2 fake batteries made of hot glue cartridges. To prove it really works:

I can’t wait to make a robot with these.

Chocolate dispenser

The latest in chocolate breaking technology! Using patented breaker technology, bar after bar is transported and broken off. No animals where harmed in the making of this robot.

My father eats a lot of chocolate, so the original idea for this robot was for it to keep track of and limit your chocolate eating. Unfortunately the NXT doesn’t keep track of the time, so you could just restart the program and eat more.

A solution to this problem would be to use the Mindsensors realtime clock, which costs $20, but since I have no intention to actually keep this robot around, I just used it as a dispenser for the weak and lazy.

Chocolate is fed into the back of the robot and is then transported to the front. A light sensor detects the foil and aligns the chocolate to the front edge. I keep the foil around the bar to make detection easy and to keep my LEGO clean.

When the button is pushed, one bar is extended over the edge and broken off by 2 NXT motors. Check the NBC code:

#define BLOCKWIDTH 100

dseg segment
  button byte
  light word
dseg ends

thread main
  wait 100

  OnRev(OUT_A, 50)
  brcmp EQ, NotThereYet, light, INPUT_BLACKCOLOR

  RotateMotor(OUT_A, 50, -100)

  GetButtonState(BTNCENTER, button)
  brtst EQ StandBy button

  RotateMotor(OUT_A, 50, -##BLOCKWIDTH)

  OnFwd(OUT_BC, 100)
  wait 1000
  OnRev(OUT_BC, 50)
  wait 1000

  jmp StandBy

It took some time to calibrate the machine, but it was delicious. No extra parts are required for this robot, except some chocolate.

Download building instructions

Tower Crane

Picking up and carrying around stuff is fun, but another claw/gripper? Can’t we do something new?

That is what I did. I sat down with the idea of Pythagorean triangles in my mind, and then I imagined a tower crane, with all these diagonal truss beams. Djing!

So I started laying out triangles and piecing them together. I’m pretty content with the result, which uses 3 different triangles.

A few caveats:

  • You need a turntable, I didn’t dare putting so much stress on a single axle.
  • The hook and winch are not in the manual, I used 3 different ones, and I bet you need another 3 for your own projects.

At first I used my gamepad code to control the crane, but later I programmed it as well.

Tower cranes are usually used to build high buildings right? It’s maybe not as cool as flying robot builders, but I managed to let my crane build a tower.

The logic goes something like “turn around until the ultrasonic sensor reads less than 20cm, pull the winch down and up, go to starting position, go down and up, repeat”, and can easily be programmed in NXT-G or NBC.

Before you buy, remember that you need a turntable and of course a bit of string. Both the old and new model turntables should work with minimal modifications.

Download building instructions