Arduino for Lego Trains #11: Controlling Power Functions Trains
ฝัง
- เผยแพร่เมื่อ 7 ก.พ. 2025
- This introduction tutorial explains the basic steps to control a Lego Power Functions train with an arduino! From wiring up an infrared LED to writing the code, this tutorial has everything you need to know to automate your Power Functions train!
Power Functions library: tinyurl.com/2p... *NEW LINK 12/12/2021*
LED Resistor calculator: led.linear1.org...
I am impressed with the start of the video, having the POV of the train. Really awesome camera work throughout. These videos of yours are really inspiring me to invest into my own LEGO arduino combinations. Thanks for these high quality video tutorials.
Well done ! You have a pleasant voice, a neat pommie accent and you make the technical bits sound easy - great for building confidence in your viewers! Looks like it is time to dump the N-gauge and get a few Lego trains! I also love ARDUINO - I use it in my Christmas Villages.
This is great! I loved the series and watched them all, but never really considered doing anything with it because I wasn't going to get the old tracks and motors. This definitely opens up a lot of possibilities with a very simple solution.
Mike Brum Exactly.
I realise this is an old video but I just found it recently and just wanted to thank you for posting it. It inspired me to play with my Lego trains again - this time in a more advanced way, with an Arduino.
I’m very happy I found your channel! Very interesting topic and great info. Thanks again!
This is a fantastic tutorial! I followed the steps and now have one of my LEGO trains controlled with an Arduino + IR emitter. Thank you for a great step-by-step approach :-)
I would also suggest to go to google, search for "Arduino pin max current", notice it's 40mA, and use transistors for your LEDs.
It will survive the 200mA with IR leds as they a pulsed very briefly, but if for some reason your code hangs and leaves them on you are going to cook the Atmega chip.
i agree it would probably survive in this situation but i did add a 2n3904 to drive the leds
So to avoid this could you do the same thing but use the 5v constant and make the io pin gnd?
Thank you very much!!!
Everything works!
The best explanation!
With best wishes from Russia!!!
I have following you posts for sometime now. Thankfully you came up with something I can use. I am a Power Function user (no metal wheels). I have the using Qt Creator (C++). I know that Arduino uses C++ as well. Thank you...!!!
BEST LEGO CHANNEL EVER!
is my new profile picture showing up? its a yamanote line e231 500 series train.
trains rule no
Awesome! Love this! I’ve just started printing track for an aerial line round my living room. Will be implementing full Arduino control. Thanks for sharing1!
Fantastic mate good stuff! I am looking forward to doing this in conjunction with motorised points and sensors to make the train stop at stations automatically etc! Thanks from Oz!
Great to hear! Let me know how you get on!
Geovnnie
Thank you I am definitely going to use this in the future for my projects
Thank I. Have been waiting for you to do your first video
He makes it look easy
That's great! But, I think you should make more videos about the power functions trains.
very nice tutorial, i got everything to work first try
however i added a 2n3904 to drive the leds because the arduino pins arent capable of much current
Siemka Polaku , niezła robota ❤
Really great video
This has given me some great ideas, how easy would it be to control the trains via a web page controlling the arduino to have real time control of them?
Nice work. 2 questions: Did you write the PowerFunctions library yourself? If so a video about how you decoded the default remote would be nice. Lastly, can you control multiple trains like this with a single arduino?
Thank you for tutorial!
The old lego train get power from track ? That was pretty cool , like , battery won't last long right , on the other hand , powered track is last forever as long as get electricity , can someone tell me more about that powered track lego train ?
Very nice video! ;-)
Just a small point, but when searching for a datasheet, isn't it better to search on the components code and the word datasheet instead of the code and pdf? Not all datasheets are PDF's, obviously most are but some are weblinks, and true there is usually hundreds of results for popular components, but sometimes obscure components are hard to find and by just searching on PDF you may mis a datasheet. Can I just ask something, how come when you search on google it's the Polish version, when you are very obviously from England, home counties by the sounds of it, why and how come? Are you hiding in flat coming out when he leave to buy hamster food? Great videos BTW, thanks.
I want to control my oo gauge railway automatically (technically the type of Lego railway which gets power from the track) could you do a video on the Lego trains which get their power from the track because oo gauge railways are literally the same thing
can you mace same with te old rc trains like the 7897 ice or the 7898 cargo train
Merci beaucoup de la part d'un Français :D Tu a fait un très bon travail :)
Question do you have a code for PU trains. Your code for Bluetooth and Power Functions i go also use this year. I have in total 5 trains. 2 PU and 3 PF (bluethooth and some with Sbrick)
So I take it that you're back or something?
Thank you so much for this, i've tried getting the codes that the remote sends to the reciver but it did'nt work=)
The Lego reciver has two cable outputs posibilities; one BLUE and one RED. Yo must write in the arduino code the same color than the one that you have conected. This could be your problem, because this happened to me.
Hello sir.. very good video.. thanks so much. I got inquiry, can we used the tsal6200 instead of tsal6400?
I went looking for the TSAL6400 but there is very hard to come, there is a replacement that you use more here for
Is there a way to write our own power functions library? I don't have access to the PFlibrary in the link he shared
Interesting tutorial. May I ask,where did you get this Ir library from and specialy timings and frequency of ir pulses that can be registered by the Lego Ir receiver?
Maybe this video will help: th-cam.com/video/6RttvmTGm74/w-d-xo.html
It seems useful, thanks!
2:22 how do i buy that part inside the train.
Thank you
But you have 120 volt not 220 like shown it shows 🔌 from another country come on here. I live in the United States. And play with my train sets too and set them up also but the settings are off I need to check the local Lego sales office I guess to help me out!
Will keep this saved too to help me with my layout ideas also!!
Does anyone know if there is a powerfunctions library that works with the newer bluetooth lego trains?
Can i use TSAL6100 instead of TSAL6400?
Mate great vid. I get this message when I'm done writing code : 'LegoPowerFunctions' does not name a type. It probably refers to the copied files, which may have failed. Is that it ? :)
Did you download the library I linked to and install it on your computer?
I find your videos always good but this is a slight disappointment : Why cant you just connect the function to the battery already in the train? I mean, it is illogical that the train will have two power sources, when in fact you could use the Lego battery box to operate both the wheel movement and the remote onboard control unit. No ?
+TitinaNasturbova Thanks. Yes, you can use the Lego battery box, which is what I do in the next video. But it requires buying a dedicated lego cable, destroying it, and soldering a custom cable from it. This video aimed to show the proof of concept (onboard IR control) without that expense or complexity.
and the next this year 2018....the BLUE TOOTH Controlling ^^
Excelent, this totally works, thanks to the master hacker!
Hello Arduino lego trains, I really would like to do a project like this, so could you please help me understand the whole resistor cable thing and create a detailed supply list, It will be really helpful thanks!
You can check out the project blog for a full guide: arduinolegotrains.wordpress.com/2017/03/26/tutorial-controlling-power-functions-trains/
When you write code your first line is :" #include " ?
Yes. #include tells the Arduino IDE to look for commands in the legopowerfunctions.h file, which you need to copy from the provided link to your computer.
lowest resitor I had was 560 ohm so I guess my raqnge will be limited by a lot
hey,
Great video! But I was wondering if this also works with another type of train (7898). I tried it but is won't work. :(
Sorry - 7898 is an RC train, not Power Functions, so you'll need to use a different method.
On your website it says I need a 100ohm resistor but in your tutorial you said you needed a 39ohm resistor, Im confused??????
The video shows you how to calculate the resistor value for that specific IR LED (the TSAL6400). In most cases, a 100 Ohm resistor will work fine for most IR LEDs. If the resistor is too high then the IR range will be low, but if the resistor is too low then you risk damaging the Arduino, so 100 Ohm is a "safe" value.
Alright, Thank you
Can you also explain what BLUE in code means ? Thanks
Lego Power Functions transmitters and receivers use 8 channels: RED 1-4 and BLUE 1-4. You can see this indicated on both the transmitter and receiver. In this case, BLUE tells the arduino to transmit commands to the motor connected to the Blue plug on the Power Functions receiver (ie the one inside your train).
can I do the same thing with an uno board??
Sure! The only difference between the Uno and Nano is the size, so the setup and code is identical.
so..... I need my Old Arduino, or a new one cause I left it die in some lab of the University. Awesome video
Is this a dumb question... I cannot find the parrameters for a resistor for this led I'm thinking of getting to try this
www.adafruit.com/products/387
From the video: "Go to the datasheet and find the forward current and forward voltage values." The website you linked shows "Approx 1.6V forward voltage", and the datasheet that's linked on that page says "Continuous Forward Current - 100mA". Those are the values you need when using the resistor calculator shown in the video at 2:55.
Arduino Lego Trains thanks
FAKE: He plugged in USB first try
Like Stanley Kubrick, I took 156 takes until I got it right.
I did too, but mine's USB-c
Meh, 50/50 chance. I'll allow it.
who does have exacly one 39 Ohm resistor?
Current limiting resistor. Without one, all LEDs would try to operate at maximum current and blow themselves up.
Dobry angielski (zdradziłeś się z Google Polska) :)
bo jestem Anglikiem! ale mieszkam w Polsce od dawno.
do you have a fiverr account?
Not any more, because the fees are too high. What would you like me to do?
oh mann:(Actually basically the features that you have on ur channel but all combined into one.But using wireless communication between the train and the components on the train track.
Don't worry, wireless communications will feature in the next video!
Arduino Lego Trains but is it possible to cut the wires of the motor and connect it up to the L298 Motor?because I'm having problems with which wire to connect to which pins
hi i got a question to ask,if i were to strip the wire of the wheel motor, to connect directly to the motor driver,where does the wire have to go on the motor driver that will be on the train.
.
.