This device sorts 2x2 bricks into two piles - red on one side, blue on the other. The bricks slide down the chute on the right side until they rest against a light sensor. The light sensor determines what color the brick is, then uses a motor to slide the "arm" to the right or left to eject the brick. A touch sensor indicates when the arm has moved far enough, which is a signal for the motor to reverse and re-center the motor (again determined by the touch sensor).

A side view of the sorter

A close up of the sorting arm - note the three "holes" used by the touch sensor to determine when to stop the arm's motion.

It really works...

/* sorter.nqc
* written by Dave Baum for NQC 2.0
*/
#define EYE SENSOR_1
#define BUMP SENSOR_3
#define ARM OUT_A
/* you may need to adjust these */
#define COLOR_BLACK 45
#define COLOR_RED 51
#define BRICK_DELAY 10
task main()
{
/* setup sensors */
SetSensor(EYE, SENSOR_LIGHT);
SetSensor(BUMP, SENSOR_TOUCH);
/* run until there are no more bricks */
while(EYE > COLOR_BLACK)
{
/* check color of brick */
if (EYE > COLOR_RED)
Fwd(ARM);
else
Rev(ARM);
/* move arm to end */
On(ARM);
until(BUMP == 1);
until(BUMP == 0);
/* reverse direction arm */
Toggle(ARM);
/* wait until arm has returned to center */
until(BUMP == 1);
until(BUMP == 0);
/* stop arm */
Off(ARM);
/* wait a little while for next brick to slide down */
Wait(BRICK_DELAY);
}
}