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

แชร์
ฝัง
  • เผยแพร่เมื่อ 24 ส.ค. 2024

ความคิดเห็น • 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.)

  • @davidclosedthisaccount
    @davidclosedthisaccount 7 ปีที่แล้ว +9

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

  • @SteffenTimm
    @SteffenTimm 7 ปีที่แล้ว +3

    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.

  • @JariBerg4499
    @JariBerg4499 7 ปีที่แล้ว +1

    nice! keep up the great work.

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

  • @banchakhan
    @banchakhan 5 ปีที่แล้ว

    Request a Circuit electric

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

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

  • @srtking2
    @srtking2 7 ปีที่แล้ว

    were did you the lego equiped parts?

  • @ps3lego95
    @ps3lego95 4 ปีที่แล้ว

    Are this work for 9v train?

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

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

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

  • @hiteshinsan398
    @hiteshinsan398 5 ปีที่แล้ว

    Please tell me , How can I purchase lego trains

  • @patrykwisniewski6359
    @patrykwisniewski6359 7 ปีที่แล้ว +1

    polish chocolate