Automation using the PIC Brick

This is my version of Will Chapman's PIC Brick. Mine is built into a small 9V battery box (available as spare part #5038). Click on the photo above for a closer view of the internals.

What Is It?

The PIC Brick contains a tiny microcontroller board that runs BASIC programs. It can be programmed from a PC by downloading the compiled code via a simple serial interface. It has non-volatile storage so it remembers the program after the power is removed. This is great because you can build it into a model and it's ready to go as soon as you switch it on.

What Can It Do?

It can control up to two Technic or Train motors, one other auxiliary device and has two input sensors. In addition, the button on the battery box can be used as a third sensor. The auxiliary device can be any LEGOŽ 9V Electric System element, including any motor, but can only be driven in one direction.

It has pulse width modulation so it can be used to control the speed of motors, not just on/off. So far I have only used mine to control my Remote Control Level Crossing, an infrared sensor detects a train approaching the crossing and automatically lowers the barriers. When the train has passed, it raises them again.

Here are some other possibilities for automating train stuff:

Inputs and Outputs

Unlike Will's design, mine is built into a 9V battery box which has only 6 pairs of conducting studs on it. Since I have to supply power and there are 5 input/output pairs I can't give each one 2x2 studs of room for the LEGOŽ connectors. So I only give them 1x2 studs. This makes it a bit difficult to use them all simultaneously, but many combinations are possible. It helps to have 1x2 conducting plates. I designed the layout so that it doesn't matter, in some cases, if a 2x2 connector overlaps onto one of its neighbours. For example, a motor output can overlap with a sensor (it just means the sensor reads which way the motor is going!)

Layout of connections:

BS1-IC I/OFunction01
0Motor 1 EnableOffOn
1Motor 1 DirectionForwardsBackwards
2Motor 2 EnableOffOn
3Motor 2 DirectionForwardsBackwards
4Aux OutputOffOn
5Input 1Open CircuitClosed Circuit
6Input 2Open CircuitClosed Circuit
7ButtonPressedNot Pressed

The power input, auxiliary output, and sensors are polarized so it's important to connect them correctly. However, the motors can be driven either way so the polarity is only important if you want the motors to go the way that the program intends!

I put amplifiers on the sensor inputs so that I can directly connect infrared phototransistors, but mechanical switches work as well.

Circuit Diagram

Click here for a circuit diagram. This is a 76K file, probably best viewed when printed out.


Peter Hoerlein has built a more professional version of the PIC brick that uses a custom made printed circuit board PCB. He has provided his artwork and the parts list he used.

See PIC Brick Parts' Sources.

Example Program

This is an example of a BASIC program, the one I have downloaded to control my level crossing.
' Automatic level crossing
' 0 Not used
' 1 Not used
' 2 Enable barrier motors
' 3 High for down, low for up
' 4 Lights flash
' 5 Train sense (low if beam broken)
' 6 Not used
' 7 Not used
low 2
high 3
low 4
loop:
if pin5=0 then train_coming
low 2
high 3
goto loop
train_coming:
high 4
pause 50
high 2
pause 1100
low 2
still_coming:
pause 50
if pin5=0 then still_coming
pause 50
if pin5=0 then still_coming
pause 50
if pin5=0 then still_coming
high 2
low 3
low 4
pause 1000
high 3
low 2
goto loop

Acknowledgements

Thanks to Will Chapman for helping me build my PIC Brick.