Arduino for Lego Trains #12: Onboard Arduino for Power Functions

  Рет қаралды 47,230

Arduino Lego Trains

Arduino Lego Trains

Күн бұрын

Integrate an Arduino into your train and take it with you as you move! Features an Arduino Nano, two ultrasonic sensors and a full Power Functions control via infra red led!

Пікірлер: 38
@MrPABLOplay
@MrPABLOplay 7 жыл бұрын
Fantastic video! I am going to install Arduino in my mini cooper and add motors (one for steering, one for drive) and a lot of leds (flashing turn signals, day lights etc.)
@JariBerg4499
@JariBerg4499 7 жыл бұрын
nice! keep up the great work.
@davidclosedthisaccount
@davidclosedthisaccount 7 жыл бұрын
My passengers can't hear incoming trains, so help people with sounds!
@hreindustries
@hreindustries 7 жыл бұрын
Do you have a video on automatic train level crossings where the things go down and lights blink?
@axltrain838
@axltrain838 7 жыл бұрын
Nice! I think I'm going to buy a nano
@ArduinoLegoTrains
@ArduinoLegoTrains 7 жыл бұрын
+Axltrain You can also look for a Pro Micro. Same size, different USB socket.
@SteffenTimm
@SteffenTimm 7 жыл бұрын
Cool function. You could ajust the speed of the train according to the distance to the object. So the train will drive slower to the object before stopping. I think this would look much cooler.
@ArduinoLegoTrains
@ArduinoLegoTrains 7 жыл бұрын
That would definitely be cool! However, the practical limit of these sensors is about 30cm (a foot), and this train with fresh batteries at the set speed (4 of 7, so middle speed) requires 16cm to stop just in time, so there's not much room to play around with in terms of adaptive speed. But don't worry! I will be featuring adaptive speed control in a later video, featuring a 3-axis accelerometer.
@gregorioeugenioragazzini1824
@gregorioeugenioragazzini1824 7 жыл бұрын
You could use a PID (Proportional-Integral-Derivative Control) to set a specific distance at which the train should stop from the wall. Arduino has already a specific library for this function, i use it in many application as for example a control temperature.
@thebrightestbrick3740
@thebrightestbrick3740 5 жыл бұрын
I have a Lego mindstorms ev3 program for that. It uses the IR sensor and a motor, and sets the motor speed to the proximity distance. If the train is far from a wall it goes fast, but as it gets closer, it slows down. You could also use this concept in a Lego car.
@pascalspruit
@pascalspruit 7 жыл бұрын
Very cool! I will definitely look into this. Two questions: 1) would it be possible to control the train motor directly via a motor controller instead of via infrared? 2) could you use the trains power functions battery box to power the arduino?
@ArduinoLegoTrains
@ArduinoLegoTrains 7 жыл бұрын
If you check Tutorial 1, you'll see how to control lego motors using an L298 motor controller. You can convert that solution to control PF motors, but you'll need to sacrifice a PF extension cable (ie cut one end off) to attach it to the motor controller. However, If you put 9V in (the power from the battery box) you'll get less than 9V out, so the train will never run at full speed. You can use the PF battery box using a similar cable to drive the arduino.
@srtking2
@srtking2 7 жыл бұрын
were did you the lego equiped parts?
@Technicmaster0
@Technicmaster0 7 жыл бұрын
Wouldn't it make more sense to control the train motor directly with the arduino and use the lego battery as power supply for the arduino? That would save space and weight.
@ArduinoLegoTrains
@ArduinoLegoTrains 7 жыл бұрын
It would, but then you need a 9v motor controller (L298N or similar) and that requires more than 9V, so more power than the battery box can provide. The best solution would be to replace the PF battery box and IR controller with bigger batteries (3x18650 or similar Li-ion/LiPo), and I will be covering that in a later tutorial.
@Technicmaster0
@Technicmaster0 7 жыл бұрын
But the motor will probably run fine with 7 or 8 volts :P
@ps3lego95
@ps3lego95 4 жыл бұрын
Are this work for 9v train?
@nicholasjize2295
@nicholasjize2295 7 жыл бұрын
If you were running on 9v could you power the onboard Arduino directly from the train motor?
@ArduinoLegoTrains
@ArduinoLegoTrains 7 жыл бұрын
+Nicholas Jize unfortunately no, because when the train stops there is 0volts, so the arduino will turn off.
@banchakhan
@banchakhan 5 жыл бұрын
Request a Circuit electric
@gregorioeugenioragazzini1824
@gregorioeugenioragazzini1824 7 жыл бұрын
For how much time can Arduino works using a power bank power supply?
@ArduinoLegoTrains
@ArduinoLegoTrains 7 жыл бұрын
Arduino uses about 25mA and the power bank I use is 2500mAh, so approximately 1000hours. Of course, LEDs and sensors will drop this time significantly, as will power bank efficiency. Still, it will last a lot longer than the AAA batteries in the train!
@FARIS__KHAN
@FARIS__KHAN 7 жыл бұрын
If I were to just make the train stop without changing direction and only move when there is no obstacle,which part of the code do i change?
@ArduinoLegoTrains
@ArduinoLegoTrains 7 жыл бұрын
where it says: if (distance < 16) { delete the next two lines, and type in: lego.SingleOutput(0, PWM_FLT, BLUE, CH1); and in the else section (where it says Serial.print(distance) etc, add the line: lego.SingleOutput(0,PWM_FWD4, BLUE, CH1); You can then delete all references to "counter", the void changeDirection, the trigPinBack and echoPinBack sections, to make your code much smaller.
@FARIS__KHAN
@FARIS__KHAN 7 жыл бұрын
#include LEGOPowerFunctions lego(6); #define trigPinFront 5 #define echoPinFront 4 byte TrigPin = 5; byte echoPin = 4; void setup(){ Serial.begin (9600); pinMode(trigPinFront, OUTPUT); pinMode(echoPinFront, INPUT); } void loop() { long duration, distance; digitalWrite(trigPinFront, LOW); delayMicroseconds(2); digitalWrite(trigPinFront, HIGH); delayMicroseconds(10); digitalWrite(trigPinFront, LOW); duration = pulseIn(echoPin, HIGH); distance = (duration/2) /29.1; if(distance < 16){ lego.SingleOutput(0, PWM_FLT, BLUE, CH1); } if (distance >= 200 || distance
@ArduinoLegoTrains
@ArduinoLegoTrains 7 жыл бұрын
I don't really understand what you are trying to do. How do you have the L298 connected?
@FARIS__KHAN
@FARIS__KHAN 7 жыл бұрын
Its an L298P shield v1.2..I strip the motor wire,connecting it to the motor driver
@ArduinoLegoTrains
@ArduinoLegoTrains 7 жыл бұрын
So in this case, you just follow the code from Tutorial 4. You do not need to use power functions library at all, because you are not using InfraRed.
@Minecraftmigapiku
@Minecraftmigapiku 7 жыл бұрын
Can't you take power from lego battery pakage
@ArduinoLegoTrains
@ArduinoLegoTrains 7 жыл бұрын
+Michal Pietrzak it's possible but not stable, especially with these sensors. I will show how to do it on the next video.
@Minecraftmigapiku
@Minecraftmigapiku 7 жыл бұрын
Ale dlaczego?
@ArduinoLegoTrains
@ArduinoLegoTrains 7 жыл бұрын
+Michal Pietrzak power output to arduino and motors at the same time is not smooth, so power to sensors becomes unstable which means the code stops working. With LEDs instead of ultrasonic sensors it is not such a problem, but IR leds do not work as long range distance sensors.
@Minecraftmigapiku
@Minecraftmigapiku 7 жыл бұрын
What about big capacitor
@ArduinoLegoTrains
@ArduinoLegoTrains 7 жыл бұрын
Maybe you can try :) I just make simplest solution for beginners
@hiteshinsan398
@hiteshinsan398 5 жыл бұрын
Please tell me , How can I purchase lego trains
@patrykwisniewski6359
@patrykwisniewski6359 7 жыл бұрын
polish chocolate
@ArduinoLegoTrains
@ArduinoLegoTrains 7 жыл бұрын
Najlepsze w swiecie
Arduino for Lego Trains #13: Bluetooth and Digispark
12:38
Arduino Lego Trains
Рет қаралды 24 М.
10 Functions LEGO Technic Needs to Introduce
11:55
Unbrickme
Рет қаралды 62 М.
Incredible magic 🤯✨
00:53
America's Got Talent
Рет қаралды 78 МЛН
КАК ДУМАЕТЕ КТО ВЫЙГРАЕТ😂
00:29
МЯТНАЯ ФАНТА
Рет қаралды 6 МЛН
KINDNESS ALWAYS COME BACK
00:59
dednahype
Рет қаралды 152 МЛН
LEGO Drift Car (With SBrick and Power Functions)
13:32
Brick Science
Рет қаралды 236 М.
LEGO Crocodile Locomotive Easy Fixes for gaps & derailing - 10277
11:35
Building a Model Railway to send Coffee
11:09
ProjectAir
Рет қаралды 658 М.
Why LEGO Control+ is so controversial
9:22
Unbrickme
Рет қаралды 113 М.
Arduino for Lego Trains #2: Light Sensors
9:34
Arduino Lego Trains
Рет қаралды 123 М.
Arduino for Lego Trains #9: Automatic Decoupler
11:58
Arduino Lego Trains
Рет қаралды 146 М.
Clicks чехол-клавиатура для iPhone ⌨️
0:59
Klavye İle Trafik Işığını Yönetmek #shorts
0:18
Osman Kabadayı
Рет қаралды 4,1 МЛН
Battery  low 🔋 🪫
0:10
dednahype
Рет қаралды 7 МЛН
$1 vs $100,000 Slow Motion Camera!
0:44
Hafu Go
Рет қаралды 23 МЛН
Как правильно выключать звук на телефоне?
0:17
Люди.Идеи, общественная организация
Рет қаралды 1,4 МЛН