Power functions lego train

Обновлено: 28.03.2024


Оживи робота LEGO® MINDSTORMS® или придуманную тобой движущуюся модель LEGO Technic™ с помощью Power Functions.

Отображение 1–12 из 16


M-Мотор Power Functions


M-Мотор Power Functions


XL-Мотор Power Functions


XL-Мотор Power Functions


Батарейный блок AAA


Батарейный блок AAA

Добавь мощности своей системе LEGO Power Functions! Добавь ещё больше мощности и движения своим моделям LEGO с помощью дополнительного батарейного блока, чтобы снабжать питанием модели LEGO Power Functions! Штекер и разъем наборов 88000, 88002, 8879 и 8884 полностью совместим с LEGO Power Function 1.0. Лего представляет мощный агрегатор энергии для твоей системы управления конструкторами Power Functions. Элемент позволяет оживлять гоночные модели […]


Батарейный блок Power


Батарейный блок Power


Блок питания на


Блок питания на


Большой мотор Power


Большой мотор Power


ИК-передатчик Power Functions


ИК-передатчик Power Functions


ИК-пульт дистанционного управления


ИК-пульт дистанционного управления

Управляй своими моделями LEGO при помощи этого пульта дистанционного управления! Добавь ИК-ресивер LEGO Power Functions, батарейный блок и мотор к своим моделям LEGO, а затем используй этот удобный пульт дистанционного управления для управления скоростью! Данное устройство работает с компонентами Lego Power Functions, которые используются в наборах Technic. Этот пульт ДУ позволяет дистанционно управлять моделями машинок из серии ЛЕГО Technics и оснащенных системой LEGO […]


ИК-ресивер Power Functions


ИК-ресивер Power Functions

Добавь функцию дистанционного управления своим моделям LEGO! Встрой этот ИК-ресивер LEGO Power Functions в свои модели LEGO и надели их удивительной подвижностью и функциональностью одним нажатием на пульт дистанционного управления (продаётся отдельно, см. набор № 8885 или № 8879)! Ты даже не представляешь, что приготовил для тебя конструктор Lego! Теперь ты можешь управлять любимыми фигурками на расстоянии! ИК-ресивер Power Functions в сочетании с пультом ДУ, мотором и блоком для батареек […]


Мотор Power Functions


Мотор Power Functions


Use an Arduino to take control of your Power Functions trains.

In this tutorial, we’ll show you how to add an infra-red LED to your Arduino, and use it instead of the Power Functions remote control. This lets you control your trains automatically, no hands required!

This is a basic tutorial – the train moves based on the program, with no user input. We will use the basic principles of this code in later tutorials.

To see it in action, check out the tutorial video.

To get started, we need to set up a few things:

  1. Connect the LED to the Arduino
  2. Mount the LEDs above the track
  3. Power the Arduino
  4. Download the Power Functions library

Connect the infrared LED to the Arduino

Here’s the LED we need – a TSAL6400.

TSAL6400

The LED has two legs; a long and a short.

  • Connect the long leg to a PWM pin on your Arduino
  • Connect the short leg to your resistor
  • Connect the resistor to a Ground pin on your Arduino

Mount the LEDs above the track

The Power Functions remote is designed to be used from above your train. This means you need to place your infrared LED above the track too. Use whatever bricks and blocks you have to build a tower that’s taller than your locomotive – I used the crane building that comes with the 60052 train.

You can use a nail file or some sand paper around the edges of the LED. Keep sanding until you can fit the LED into a standard Lego Technic hole (which has a diameter of 4.8mm). This way, you can hold your LED in place using any Technic brick or plate, by pushing the LED into the hole.

If you still have trouble receiving signals, try removing a few bricks around your train’s infrared sensor – this gives your train a better chance of receiving the signal.

Power the Arduino

All Arduinos can be run from a USB cable of some kind, and they also have a VIN pin to accept power from somewhere else. Since USB power is 5V and most Arduinos run at 5V (yes, some are 3.3V), the simplest way to power them is using a USB cable. If your Arduino also has a power cable, then plug in a standard wall adapter, from 5V to 12V.

Download the Power Functions library

To make the LED send the correct signals to the train, we need to install a library to our Arduino software. This library lets us write simple commands to the Arduino, and the Arduino will interpret those into LED pulses that the train understands.

To get the library:

  1. Visit the Power Functions library download link
  2. In the top right corner, click the Download icon
  3. Save the file to your computer
  4. Open the file
  5. Copy the folder inside to your Arduino library folder (on a Windows PC, this is usually c:/program files (x86)/arduino/libraries)

Fire up the Arduino IDE, and start writing your code.

To start, we include the Power Functions library, and declare which PWM pin on the Arduino is controlling the LED.

There’s nothing to do in the setup, so we skip straight to the loop.

Here we send the train forward, wait three seconds, then stop. We wait for a second, then make the train reverse for three seconds. Stop again for a second, then start the loop from the beginning.

But what does all this lego.Singleoutput stuff mean? I’ll break it down for you so that you can understand the specific library commands:

  • lego. – use one of the instructions in the Power Functions library
  • SingleOutput – control one of the two motors connected to the Power Functions receiver
  • PWM_FWD4, PWM_FLT, PWM_REV4 – the commands to make the train move. There are 7 forward speeds (FWD1-7), 7 reverse speeds (REV1-7_, and a stop command (FLT)
  • RED – the red motor connection on the Power Functions receiver. Can also be BLUE
  • CH1 – the channel on the Power Functions receiver. Can be CH1, 2, 3 or 4.

In this loop, I’m using FWD4 and REV4, as these are the middle speeds for Power Functions motors. Make the numbers bigger to go faster, or smaller to go slower.

To try it out yourself, copy the complete code from our Code section and upload it to your own Arduino.

Once it’s all wired up, turn on your battery. The Arduino will power up, and start running the train automatically.

Project for controlling a LEGO Train with Arduino and LEGO® Power Functions.

Arduino and LEGO® Power Functions

Things used in this project

Hardware components

Story

  • The train must stop at the station every time that passes.
  • When starting from the station a whistle as to sound
  • After leaving the station, the train must change to the inside track
  • After accomplish two laps on the outside track, the train must be transferred to the outside track

To build the project, beside the LEGO blocks and train, was used:

  • One arduino
  • One buzzer
  • two obstacle sensors
  • One servo
  • Two IR leds
  • UTP cable (to make connections between components)
  • One breadboard
  • One 220kohm resistor

To control the train at the station were needed two IR leds due to the range and angle of these. One controls the station entry and the other the station exit. To control the position of the train were used two obstacle sensors. One controls the number of laps on the inside track and the other controls the station entry. One difficulty that arises was the train control. LEGO offers the code to interact with their Power Functions (more info here) and there are four ways to interact with the train. Initially i used the Combo PWM but the train stops when exits the IR led range. After some help from the Portuguese lego Community (Comunidade0937) change the functions to the Single Output and the problem was solved.

This is the code used. It’s also available on my GitHub account.

The obstacle sensors return ‘1’ there isn’t an object in range and ‘0’ if there is.

Highslide JS

During the last decades LEGO has re-invented his train system on and on. Looking at the rails and the drive by the train motors you'll find many different systems which – more or less – are compatible to each other.

First of all, the gauge of LEGO trains did not change over the years. The gauge is 6 studs (~38 mm or "L-Gauge").

It is not very easy to remain clear-headed …

Highslide JS

4,5 V system (blue era), 12 V system (blue era), 4,5 V system (grey era), 12 V system (grey era) and 9 V system

Highslide JS

Curve Radius

The radius of LEGO train track did not change over the various eras. From the middle of the track the radius is 40 studs . A larger curve radius however can be realised with a trick.

Various third party manufacturer offer further radii in the sizes 56 studs, 72 studs, 88 studs, 104 studs and 120 studs.

Highslide JS

Switch/Points Geometry

The geometry of LEGO train track switches/points was change with the 9 V system. The parallel track is now 8 studs aside the main track. The parallel track at the 4,5 V/12V system is directly at the main track without any gap.

Various third party manufacturer also offer different switches/points with larger radii.

Powered Up

In autoum 2018 the next generation of LEGO electronics was released: Powered Up. Powered Up trains carry their power on board and they could be used on all rail types.

Highslide JS

Instead of a receiver and the power supply now a "hub" takes over this task. It is as big as the Power Functions battery box, but also contains the electronics with the Bluetooth receiver in addition to the 6 AAA batteries.

Compared to the Power Functions system, however, only a maximum of two consumers can be connected to one hub; two train motors can not be connected in combination at one output. With one hub, either two train motors or one train motor and one light can be operated. From the point of view of the predecessor system a real step backwards.

Visible are the Powered Up components on the six-core cables and the new connectors. They are similar to known network connectors, but are LEGO-specific. Unfortunately, you can not connect multiple plugs to one output of the hub.

The sizes of the Powered Up train motor, the Power Functions train motor and the 9 V train motor are identical.

For any new LEGO train fan who is just starting to build and collect LEGO trains I would recommend the latest system. Older systems will get expensive on the second hand market.

Highslide JS

Power Function Trains

Power Functions as standard system to electrify LEGO models found it's way to LEGO trains till 2017. Power Function trains carry their power on board and they could be used on all rail types. LEGO themselfs offer only plastic rails these days.

Highslide JS

RC Train

With RC trains LEGO also established the plastic rails. They are compatible to the former 9 V track but the current-carrying metal is missing.

Highslide JS

9 V Train

From 1991 to 2004 the 9 V system was used for LEGO trains. This system is recognisable by the current-carrying tracks and the metal wheels which pick up the power for the train motor. 9 V trains run very smoothly on the 9 V tracks and the tracks look quite realistic. That is way LEGO fans still like this system the best. This could be observed at the astronomic prices, especially for straight 9 V track pieces and 9 V train motors.

On 9 V track any other train powered by battery can run, e.g. Power Function trains or old 4,5 V trains.

The available geometries for tracks are limited. But using smooth curves or ME Metal Rails you can expand the possiblities of this kind of track.

Highslide JS

12 V Train (grey era)

The closest system to real model-railroading was the 12 V train system back in the 1980's. The powering of the trains was done by using a heavy speed regulator (trafo) which provided power through the current-carrying middle track elements for the 12 V train motor. The fun was even bigger when other remote controlled accessories like points/switches, signals, decoupling unit or a level crossing were used.

The rails were clipped on the sleepers. That made the track relative stable but setting up such a layout took some time.

Highslide JS

4,5 V Train (grey era)

The 4,5 V train system of the grey era is a further development of the 4,5 V system from the blue era. It meant to be a "starter drug" into the 12 V system. It was easy to replace the 4,5 V motor by a 12 V motor and also the rails could be reused by just adding the additional current-carrying middle track element.

Highslide JS

12 V Train (blue era)

At the end of the 1960's LEGO offered the first 12 V system in parallel to the 4,5 V system. The powering of the trains was done by using a heavy blue speed regulator (trafo) which provided power through the current-carrying middle track elements for the 12 V train motor. The accessory assortement wasn't as big as till 12 V grey era times but remote controlled points/switchs were available.

Highslide JS

4,5 V Train (blue era)

The 4,5 V systems uses batteries to power the train. These batteries are carried on board in a special battery waggon. The signal could stop the train and the direction switch made the train change directions.

The rails were single blue rails and as sleepers standard 2x8 plates were used. This arrangement wasn't very stable at all.


Raspberry Pi and javascript controlled train station.

This is a special post because it was the main driver for building this blog! I could not find any way to control the Lego infrared power functions using NodeJs. There are libraries available for Arduino sketches and Python for Raspberry Pi, but neither worked well with my environment.

Today we will discuss how the IR power functions work, various resources and how I eventually got it to work. I hope that this is beneficial to somebody and that you share your experiences and other ideas. Ideally, somebody could take the time to write a nice NodeJS NPM to simply include into a project and share with the group 😉

  • Detect train at the City Station, stop it for 5 seconds and then resume moving.

Challenges:

  • Use the Lego infrared signals to control the train
  • Detect the train
  • Send infrared commands to the train

Components:

  • Raspberry Pi
  • Arduino
  • 1.8v LED
  • Infrared LED

Circuit:

The circuit for controlling infrared Lego power functions is not that complicated. We basically just need to attach an infrared LED and a standard LED to the Raspberry Pi GPIO pin 22. The standard LED will be used for visual feedback that the infrared LED is transmitting. This is extremely helpful while troubleshooting.

I’ve chosen to use the Keyes KY005 infrared transmitter, as it was part of this awesome sensor kit I purchased.

infrared transmitter

KY005: Infrared Transmitter Module

There will also be an infrared proximity (reflective distance) sensor to detect when the train has arrived at the station. This is attached to an Arduino because of a larger project, but could easily be connect to the Raspberry Pi instead.

infra-red-reflective-distance-sensor

Schematic:

Pin 22: LED and IR Transmitter

GPIO 6: IR Sensor

Power Infrared Sensor and transmitter from 5v source

IR Power Functions Circuit

This code was created from searching the Internet and reading forums that only got me half way there. The only NodeJS infrared module was called lego-ir but was designed for the (expensive) Tessel transmitter module. There is also an Arduino sketch library that I imagine would work very well, but that’s not the language I am working with. But then I found the answer! I used the following code/guide from Diomidis Spinellis who was kind enough to post this on GitHub. Click here for the complete work. Ultimately, the answer is to use the LIRC infrared linux driver. By using NodeJS to call a native Linux command, I was able to easily send signals to my Lego power functions.

We will first follow the steps outlined in Diomidis’s GitHub post to get the Raspberry pi using the IR transmitter.

LIRC installation and configuration

  • Configure LIRC by editing /etc/lirc/hardware.conf to be
  • For kernels before 3.18 lacking a “device tree” also add in /etc/modules the following line
  • For a 3.18 kernel (or newer), which has a device tree, uncomment and adjust the following line in the file /boot/config.txt ; you can find full instructions here
  • Copy the PWM command configurations generated by this modified PWM generation program file to the Raspberry Pi’s LIRC configuration directory.
  • Reboot your pi
  • Test the sending of Lego commands from the command line.

Now we can work easily with Infrared using the Raspberry Pi !!

Basic Flow

  • Create a function to utilize the LIRC infrared commands
  • Detect train at station
  • Stop train for 5 seconds
  • Start train
  • Wait for an additional 5 seconds before detecting a train again

Source

Now save and close your file.

Note: If this is your first project, you will need to initialize the folder and add the johhny-five module.

If you have been following along with previous projects, we will need to still add support for external commands with NodeJs and to use the GPIO pins on the Raspberry Pi (more info about using Raspberry Pi with Johnny-five here).

Читайте также: