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
@MrPABLOplay7 жыл бұрын
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.)
@JariBerg44997 жыл бұрын
nice! keep up the great work.
@davidclosedthisaccount7 жыл бұрын
My passengers can't hear incoming trains, so help people with sounds!
@hreindustries7 жыл бұрын
Do you have a video on automatic train level crossings where the things go down and lights blink?
@axltrain8387 жыл бұрын
Nice! I think I'm going to buy a nano
@ArduinoLegoTrains7 жыл бұрын
+Axltrain You can also look for a Pro Micro. Same size, different USB socket.
@SteffenTimm7 жыл бұрын
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.
@ArduinoLegoTrains7 жыл бұрын
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.
@gregorioeugenioragazzini18247 жыл бұрын
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.
@thebrightestbrick37405 жыл бұрын
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.
@pascalspruit7 жыл бұрын
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?
@ArduinoLegoTrains7 жыл бұрын
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.
@srtking27 жыл бұрын
were did you the lego equiped parts?
@Technicmaster07 жыл бұрын
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.
@ArduinoLegoTrains7 жыл бұрын
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.
@Technicmaster07 жыл бұрын
But the motor will probably run fine with 7 or 8 volts :P
@ps3lego954 жыл бұрын
Are this work for 9v train?
@nicholasjize22957 жыл бұрын
If you were running on 9v could you power the onboard Arduino directly from the train motor?
@ArduinoLegoTrains7 жыл бұрын
+Nicholas Jize unfortunately no, because when the train stops there is 0volts, so the arduino will turn off.
@banchakhan5 жыл бұрын
Request a Circuit electric
@gregorioeugenioragazzini18247 жыл бұрын
For how much time can Arduino works using a power bank power supply?
@ArduinoLegoTrains7 жыл бұрын
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__KHAN7 жыл бұрын
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?
@ArduinoLegoTrains7 жыл бұрын
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.
I don't really understand what you are trying to do. How do you have the L298 connected?
@FARIS__KHAN7 жыл бұрын
Its an L298P shield v1.2..I strip the motor wire,connecting it to the motor driver
@ArduinoLegoTrains7 жыл бұрын
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.
@Minecraftmigapiku7 жыл бұрын
Can't you take power from lego battery pakage
@ArduinoLegoTrains7 жыл бұрын
+Michal Pietrzak it's possible but not stable, especially with these sensors. I will show how to do it on the next video.
@Minecraftmigapiku7 жыл бұрын
Ale dlaczego?
@ArduinoLegoTrains7 жыл бұрын
+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.
@Minecraftmigapiku7 жыл бұрын
What about big capacitor
@ArduinoLegoTrains7 жыл бұрын
Maybe you can try :) I just make simplest solution for beginners