-
Pinkmodule

invention

LittleBits Automated Railroad #bitify

by rbender

Published on December 4, 2014

For my entry in the Bitify Your City contest, I automated a Lego railroad with a crossing gate and station stop since a good rail system is vital to a thriving city.

The crossing gate uses a Long LED and Light Sensor bit to detect when the train approaches a crossing. An Arduino Bit measures the light value from the sensor and when it drops below a threshold, it triggers a Servo Bit to lower the gate and blinks a pair of LEDs on the crossing sign in an alternating pattern. After a couple seconds, the Arduino raises the gate and turns off the LEDs.

I found that the cables for the Long LEDs were too short and a little stuff to work with for the crossing sign, so I made a pair of custom longer LED cables. I found some old wires with the same connector as the Long LED in a bin of parts I salvaged from broken electronics and soldered LEDs to them.

Connecting the Servo Bit to Lego was a bit of a challenge. I found that the mounting holes on the servo 
can clip onto Lego pole pieces to hold it in place. To connect the servo to a Lego gear, I used some thin wire to tie the round horn to the gear, but needed a small washer between them, otherwise the wheel would be slightly crooked and turn unevenly. The servo turns more than 90 degrees, so I had to use a pair of two differently sized gears to get the crossing gate to turn 90 degrees.

The station stop also uses a Long LED and Light Sensor Bit to detect the passing train. When triggered, the Arduino uses an IR LED Bit to stop the train at the station platform for a few seconds and then starts the train back up again. I found an Arduino library online for generating the right IR pulses to control a Lego Power Functions receiver.

My Arduino source code for the project is available online at: https://github.com/rbender/LittleBitsLegoTrain 

Credits: Rob Bender

How To Make It

STEP 1

Connect a Power Bit, Long LED Bit and Light Sensor Bit together attached to a Brick Adapter to make the approaching-train sensor. Attach it to a short Lego wall along the tracks and run the LED wire under the track and point it toward the Light Sensor. You may need to raise the tracks a little using some Lego plate pieces so the LED wire can fit under them.

STEP 2

Use a Wire Bit to connect the Light Sensor to the A1 input on an Arduino Bit.

STEP 3

LEDs can partially fit inside the hole of Lego Technic bricks. Run two Long LEDs from Arduino outputs D1 and D5 to the crossing gate. You can place red translucent colored 1x1 round Lego plates at the other end of the Technic brick holes to give the light a red color.

STEP 4

I found the Long LED wire to be too stiff for working into the crossing, so I made my own LED cables using extra scrap wires I had. (If you don't have wires with the same connector as the Long LED wire, you could also use regular wires with the Proto Bit instead)

STEP 5

Replace the horn on the Servo Bit with the circular one. Place a small washer around where the screw sticks out. Then place a Lego "Technic Wedge Belt Wheel" piece (http://www.bricklink.com/catalogItem.asp?P=4185) over the washer and use thin wire or string to tie the wheel piece to the round servo horn. You now have a way to attach various Lego pieces to the Servo Bit!

STEP 6

Use a short Lego Technic axle to attach a small Lego gear to the wheel on the Servo.

STEP 7

To hold the Servo Bit in place, you can clip the screw holders onto a pair of Lego bar/antenna pieces. I then built an electrical-transformer looking box around the Servo to better hide it.

STEP 8

Place the Servo by the railroad crossing so the small gear turns the larger gear.

STEP 9

Attach the Servo Bit to the Arduino output D9. Set the output switch to PWM instead of Analog.

STEP 10

Download the LittleBitsRailroadCrossing sketch from my GitHub repo, open it in the Arduino IDE and upload it to the Arduino.

STEP 11

If you open the Serial Monitor in the Arduino IDE, you will see the values read by the Light Sensor. Try blocking the Light Sensor and see if the crossing gate activates. If not, try tweaking the LIGHT_THRESHOLD value in the Arduino sketch or the sensitivity of the bit until it works properly.

STEP 12

Encase the Arduino Bit in a small Lego shed to hide it. Be sure to make spots for the wires to run out of it.

STEP 13

The Station stop os much easier to construct. First build a second approaching-train sensor as described in Step 1.

STEP 14

Connect it to the A0 input on the second Arduino.

STEP 15

Connect an IR LED Bit to output D5 on the Arduino. Be sure to switch the output type from Analog to PWM.

STEP 16

Download the Lego Power Functions Arduino library from http://forum.arduino.cc/index.php?topic=89310.0 and unzip it into your Arduino libraries folder (See http://arduino.cc/en/Guide/Libraries for instructions on installing libraries)

STEP 17

Upload the LittleBitsStation sketch from my GitHub repo to the Arduino.

STEP 18

As with the crossing, the Arduino sketch outputs the light sensor reading to the Serial Monitor. Tweak the LIGHT_THRESHOLD or sensor sensitivity as needed.

STEP 19

Build a station platform for the train and hide the Arduino inside it.

STEP 20

Build a structure to go over the tracks and suspend the IR LED from it so that it points down toward the track.

Related Projects

Quick, start! A quickstart project for LittleBits Arduino

#quickstart #complete #template #translate #interface #normalize This quickstart project provides a complete templa...

Studio Rave Lantern

It has a light that matches the beat of the music using a controller.