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

Поділитися
Вставка
  • Опубліковано 14 лип 2024
  • 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 років тому +1

    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 років тому +1

    nice! keep up the great work.

  • @davidclosedthisaccount
    @davidclosedthisaccount 7 років тому +9

    My passengers can't hear incoming trains, so help people with sounds!

  • @axltrain838
    @axltrain838 7 років тому +1

    Nice! I think I'm going to buy a nano

    • @ArduinoLegoTrains
      @ArduinoLegoTrains  7 років тому +1

      +Axltrain You can also look for a Pro Micro. Same size, different USB socket.

  • @hreindustries
    @hreindustries 7 років тому

    Do you have a video on automatic train level crossings where the things go down and lights blink?

  • @SteffenTimm
    @SteffenTimm 7 років тому +2

    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 років тому +3

      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?

  • @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

  • @ps3lego95
    @ps3lego95 4 роки тому

    Are this work for 9v train?

  • @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 років тому +1

      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 років тому +1

      But the motor will probably run fine with 7 or 8 volts :P

  • @gregorioeugenioragazzini1824
    @gregorioeugenioragazzini1824 7 років тому

    For how much time can Arduino works using a power bank power supply?

    • @ArduinoLegoTrains
      @ArduinoLegoTrains  7 років тому +2

      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 років тому +2

    Can't you take power from lego battery pakage

    • @ArduinoLegoTrains
      @ArduinoLegoTrains  7 років тому +1

      +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 років тому +2

      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 років тому +1

    polish chocolate