I Made an Automated Model Train With An Arduino!

Поділитися
Вставка
  • Опубліковано 5 жов 2024
  • Today we are making a fully automated model train setup using an arduino, a motor driver, and some infrared sensors!
    Download the Arduino Sketch Here
    github.com/DIY...
    Kato Pocket Line Tram
    shorturl.at/hkKVY
    Parts(Affiliate Links)
    Arduino UNO--amzn.to/3jTbDJ4
    L298N Motor Driver--amzn.to/3EuMgVJ
    Infrared Sensors--amzn.to/3nIqsPD
    Resistor--amzn.to/3CBtPxS
    Rotary Potentiometer--amzn.to/3mwkIZN
    Wires--amzn.to/3GwYFtY
    Breadboard--amzn.to/3w0KIjg
    Power Supply--amzn.to/3jSOkPx
    Barrell Plug Adapter--amzn.to/31j3Iya
    Arduino DC Control
    • Arduino DIY DC Model T...
    Automation using Relays
    • Easy Model Train Autom...
    I have an Amazon Store!
    www.amazon.com...
    Check out my Facebook page
    / diyanddigitalrr
    Support the channel on Patreon
    / diyanddigitalrailroad
    Check out my Instagram
    / diydigitalrailroad
    Check out my Etsy Store
    www.etsy.com/s...
    N Scale Train Set
    amzn.to/33TzsbS
    HO Scale Train Set
    amzn.to/311N17g
    O Scale Train Set
    amzn.to/3lAZCGu
    G Scale Train Set
    amzn.to/312Cn09
    I do a lot of 3D Printing. Here are some great printers
    Anycubic Photon
    amzn.to/2SAnJZn
    Creality Ender 3
    amzn.to/3lkMogX
    Camera I use
    amzn.to/2SyuPh5
    Support the channel with some Merchandise!
    teespring.com/...
    Connect with me at ddrrcommunity@gmail.com
    I do a lot of 3D Printing. Here are some great printers
    Anycubic Photon
    amzn.to/2SAnJZn
    Creality Ender 3
    amzn.to/3lkMogX
    Original Prusa Mini
    shop.prusa3d.c...
    Elegoo Mars
    amzn.to/386NZSa
    Anycubic Mega Zero
    amzn.to/3mHfdpi
    Qiditech Shadow S 5.5
    amzn.to/3cZl059
    Samaritan’s Purse
    www.samaritans...
    Camera Used
    amzn.to/2X87yWR
    “The godly may trip seven times, but they will get up again.
    But one disaster is enough to overthrow the wicked.
    Don’t rejoice when your enemies fall;
    don’t be happy when they stumble.
    For the Lord will be displeased with you
    and will turn his anger away from them.
    Don’t fret because of evildoers;
    don’t envy the wicked.”
    Proverbs 24: 16-19 NLT

КОМЕНТАРІ • 129

  • @machmar
    @machmar 2 роки тому +4

    Nice video. BUT! You have wired the potentiometer completely wrong - side legs got to gnd and vcc (which is which doesn't matter), middle leg is the output. No resistor needed

  • @donaldkormos5529
    @donaldkormos5529 2 роки тому +6

    Cool video Jimmy!! As an HO steel mill modeler I have been experimenting with similar Arduino automation schemes. I'd like to automate a small switcher dedicated to a coke oven battery (to move coke receiver car from oven door to quench tower) or dedicated to a blast furnace (to move a hot metal car from the furnace to other set locations in the mill). Steel mills have lots of these short runs that can be automated. Your example is perfect for these applications!
    Have three comments.
    First, some DCC engines will operate in DC mode as well. I've been using a HO Athearn EMD 40 switcher previously equipped with NCE DCC decoder. It's the right size for my steel mill applications. Glad I didn't have to buy another engine.
    Second, I'm using a higher voltage for HO scale ... 15V DC instead of 12. With a change of voltage, your automation method will work with many scales. I've made something similar work with T scale using 5V DC supply to motor driver.
    Third, using a random() function call, the time spent at any of your stations can be made slightly more realistic. Simply add (or subtract) a reasonable random value from your 5000 msec delay.
    All the best ... Happy Model Railroading ...

  • @AJMansfield1
    @AJMansfield1 2 роки тому +11

    What's the reason for wiring the potentiometer as you've done, with the extra resistor? Usually you'd wire the outer legs of the pot to GND and VCC and the center leg to the analog input with no extra resistors. This standard voltage divider configuration gives a linear response from potentiometer position to the voltage output, and makes it possible to use the full 0 to 1023 range of the Arduino's ADC input, while the circuit you've shown gives what's called a "harmonic" response curve -- the ADC input value becomes extremely sensitive at one end, and much less sensitive at the other, while only reaching 94% of the full-scale voltage (with your resistor values).

  • @MrArpSolina
    @MrArpSolina 2 роки тому +7

    For station3, here's a better way to code it:
    if (station3 < 500) {
    // Direction doesn't matter for the 3 following lines
    digitalWrite(5, LOW);
    digitalWrite(6, LOW);
    delay(5000);
    if (Direction == 1) {
    digitalWrite(6, HIGH);
    // No need to set port 5 to LOW as it is already set to LOW
    }
    else {
    digitalWrite(5, HIGH);
    // No need to set port 6 to LOW as it is already set to LOW
    }
    // Direction doesn't matter for the 1.5 sec delay
    delay(1500);
    }

    • @MatzeFrenkie
      @MatzeFrenkie Рік тому +2

      And since we use this multiple times for other potential "in between" stations it also is much more neater to put all of this in a function with stationN as argument. No need to copypasta stuff when you add a station and no spaghetti code.

  • @4everdc302
    @4everdc302 2 роки тому +6

    Very intriguing 👍 I'm too old school and would be using bump switches & relays for this. Still watching🚂🇨🇦

  • @cascadesouthernmodeltrains7547
    @cascadesouthernmodeltrains7547 2 роки тому +4

    The pin you were having a hard time reading was the "ENable A" pin ENA. On the other side is ENB or "ENable B"

  • @jprince46
    @jprince46 Рік тому +1

    Thank you - great project. Used 5VDC from Motor driver to power Arduino Nano and sensors - works great.

  • @gregbowen617
    @gregbowen617 2 роки тому +2

    Excellent video Jimmy! This is a really helpful topic that will benefit those who have commuter trains they want to run independently as automatic start/stop/reverse etc.
    Cheers from Melbourne, Australia!

  • @Electric91
    @Electric91 2 роки тому +3

    cool video Jimmy, in the coding you should use sub voids in the code.
    like this,
    void loop(){
    station1=analogRead(A0);
    station2=analogRead(A1);
    station3=analogRead(A2);
    speedval=analogRead(A3);
    speed=map(speeval,0,1023,0,255);
    analogWrite(3,speed);
    delay(50);
    if (station1

  • @jimkretzmer9193
    @jimkretzmer9193 2 роки тому +1

    Thanks, Jimmy. This is exactly what I need to model the NJRT from the early 1900's on my upcoming new build! Timing could not be better! The link to the Kato Tram is an added extra to the arduino hardware and sketch. The tram is a close approximation to the NJRT Jewett cars!

    • @carolbaskas6929
      @carolbaskas6929 Рік тому

      The link to the Kato Tram doesn’t work for me. Can you direct me to a new link so I can purchase?

  • @eytanbarak2261
    @eytanbarak2261 Рік тому +1

    Thanks! i have been watching yr videos session for a long time. u do it very clear and slowly for anyone to follow.
    I started ardunio for train few weeks ago and I fine yr work very helpful.

  • @brianpagemodeltrains
    @brianpagemodeltrains 2 роки тому +2

    Sweet setup, Jimmy! Thanks for sharing that with us.

  • @danielvanmieghem1091
    @danielvanmieghem1091 2 роки тому +2

    Nice. However, based on the type of IR sensors you use, which have a built in comparator / trigger, you can use simple digital inputs for the station1, station2, station 3 detection. ALso, if you really want this to "go pro" you can create slow start and stop routines using variation in PWM signals. But hey, for a startere, this is a great example ! End you do explain it clearly and decently in easy-to-understand language, cudos for that !

  • @johnalex3023
    @johnalex3023 2 роки тому

    Cool idea. I’d consider adding an input for a start/stop button. If it’s running, continue to next sensor and stop, if it’s not running, run.

  • @richardmycroft5336
    @richardmycroft5336 2 роки тому

    What occurs to me is that this might be a great foundation for a tram system that runs in a loop. I love trams, so thanks for this video.

  • @DieCastoms
    @DieCastoms 2 роки тому

    I have a project I am working on. it is a g scale train in a store window christmas display. I want to add a push-button (a big "Easy" button from Staples, hopefully) that when pressed will make the train run for a certain amount of time and then stop until the button is pressed again. also, if the button isn't pressed for longer than 20 minutes, the train would run on it's own, once. I am hoping to learn enough from your channel to achieve this! thank you for posting!

  • @goodrails
    @goodrails 2 роки тому

    I always wanted to do that. My day dream is to run my bullet trains point to point while I do my switching..
    My thought was to put the electronics in a lineside building so I could just push a button.
    Nicely done.

  • @d.j.peters
    @d.j.peters 2 роки тому +1

    you can shift right 2 bits an int to get from 10 bits to 8 bits :-)

  • @jamieayy260
    @jamieayy260 Рік тому +1

    Thanks for making this so simple and accessible to everyone

  • @paulhumphrey3195
    @paulhumphrey3195 Рік тому

    Thank you so much. With this I was able to make the rigi duo ski lift autonomous. It works great. And I know there will be more to make with this. Thanks again. Great teacher too.

    • @paulhumphrey3195
      @paulhumphrey3195 Рік тому

      Forgot to add....I had to add a ground from arduino to power side of motor control. Works great

  • @keyplayermark
    @keyplayermark 2 роки тому

    I am currently building a future city layout with a bullet train that goes through different futuristic cities. I came across this and it was absolutely perfect for what I need. I just got a soundboard that will kick off train station chimes and information on arrivals and departures. I hope to get the sensors down the track a bit and time the train to slow into and out of the stations. Thanks!

    • @JonniHill
      @JonniHill Рік тому

      Can you share your progress? I want to do this

  • @HobkinBoi
    @HobkinBoi 2 роки тому +1

    Small tweak, perhaps make it so that speed ramps down/up when arriving/departing a station.

    • @jeffb33
      @jeffb33 Рік тому

      Don't do this. Nearly 1 year later, I made this project and you get a very high pitched noise from the motors during the ramps, at least using this driver. You should use an alternate driver for that

  • @Ron_Rhodes
    @Ron_Rhodes 2 роки тому +1

    Thanks for the video. I just figured out how to automate my street cars using JMRI Jython scripts but I'll need to run some DC motors for Magnorail to control my autos, so this tutorial is great. We all have those 30 year plans we've been waiting to get to. I think I'll use an ESP32 so I'll have MQTT remote control over WiFi.

  • @donmartin9567
    @donmartin9567 2 роки тому +1

    Hi Jimmy, I'm looking at doing a similar thing except adding in some turnout control and likely a second Tram. But, I have a couple of questions:
    1) While I've used the Arduino for a few things, from what I see it "knows" the difference between the Analog 3 port and Digital 3 port. When I do an analogRead(A3 - it knows to read from the Analog port. But when I do an analogWrite(3 - it knows to write to the Digital port as a PCM port. Have I got that right?
    2) You've used digital ports 3, 5 and 6 for motor control. All PCM ports. But, you really only need to use one for the speed control - right. Seeing as the other are written with either "HIGH" or "LOW".
    While I'll put together my own test system to test this out I just thought I'd check with you first, could save some time.
    Oh and I'll be "borrowing" more of your code from your turnout automation video as well.
    Thanks for all the good work!

  • @johankruize6817
    @johankruize6817 2 роки тому

    Nice video, a great help to anyone that likes to play around with an Arduino on their layout. One minor note from my side, please try to omit the use of 'sleep()' functions in any sketch, as they are blocking the core from doing anything else. If this code is ported to an Arduino ESP32 with WiFi, it will fail to run correctly in combination with the WiFi. In addition, modification of the speed will currently also only happen 1.5 seconds after leaving the station.

  • @RichardParker-mu8qj
    @RichardParker-mu8qj 6 місяців тому +1

    Great video. Potentiometer type/ resistance? Cheers

  • @brucewoods9377
    @brucewoods9377 2 роки тому +4

    That pin would be ENA “Enable”

  • @johnhenshaw4429
    @johnhenshaw4429 10 місяців тому

    That’s not a good way to wire up the potentiometer.. the centre pin is the wiper which goes to the arduino input.. the outer pins are the vcc & gnd supply to the potentiometer track. You don’t need the resistor.
    And if you did need a resistor you’d use 470 or 430 ohm.. 440 ohms are not a member of either the E12 or the E24 resistor ranges..
    However, I do like the idea to use the IR sensors.

  • @edwardthebruces
    @edwardthebruces 18 днів тому

    Do you know of a sensor that could be attached to a toy train running in a loop and the sensor would be used to make the train stop once it detects an objection in front of it?

  • @oldgrumpyhunter
    @oldgrumpyhunter 2 роки тому +8

    Great info Jimmy, I have been wanting something like this for years long before I got into DCC. The one thing I would do differently is to put the pot on A0 so that the station numbers would be the same as the analog numbers, but that is just me and my ODC.
    Are you going to remove the LEDs from the IR sensor boards and extend the leads so that the boards can be hidden or are you going to just put the IR sensor boards below the roadbed with the LEDs pointing up?
    I've been watching you for a while and realized I am not subscribed, will I just took care of that.

  • @kylefoster2891
    @kylefoster2891 Рік тому

    Model trains meets electrical/computer engineering 😍

  • @AleksandrIvin
    @AleksandrIvin Рік тому

    Nice project and cool video! I'm thinking to do something similar, but for wooden train.

  • @MrToastedtoad
    @MrToastedtoad Рік тому

    double equal means compare the values, where as single equal means assign.
    thanks for doing the video.

  • @wandersonsilva-fx1cs
    @wandersonsilva-fx1cs 2 роки тому

    Mr. Congratulations on your project! I thought it was fantastic. Mr. can you explain to me or post the schematic where the engine is and how the train runs?

  • @napkin62
    @napkin62 2 роки тому

    Very useful and your details in typing with patience great I got this realy you are a great teacher... God bless you always make such tutorial for lay man like me 🙏🙏🙏🙏👍

  • @bigrenegade7121
    @bigrenegade7121 2 роки тому

    The pin you removed the jumper from with letters on it is the enable pin. So the letters read E N A

  • @bluedeath996
    @bluedeath996 2 роки тому +1

    There is a lot of bad practice here. Use ferrules on your wires, don't put dupont pins in a screw terminal, use case statements if it can't be more than one at once, you should use functions to set direction and at station 3 you have already set the direction so you don't need to change it.

    • @eduardkompast3063
      @eduardkompast3063 2 роки тому

      So, how would your code look?!

    • @bluedeath996
      @bluedeath996 2 роки тому +1

      @@eduardkompast3063
      int Speed;
      int Direction;
      int station;
      void setup() {
      Serial.begin(9600);
      pinMode(3, OUTPUT);
      pinMode(5, OUTPUT);
      pinMode(6, OUTPUT);
      }
      void loop() {
      station = map(analogRead(A0) + (analogRead(A1) * 2) + (analogRead(A2) * 4), 0, 7161, 0, 14)
      Speed=map(analogRead(A3), 0, 1023, 0, 255);
      switch(station) {
      case 1: //between 511-1023
      Stop();
      Dir(1);
      delay(1500);
      break;
      case 2: //between 1023-1534
      Stop();
      Dir(0);
      delay(1500);
      break;
      case 5: //between ~2500-3000
      Stop();
      Dir(Direction);
      delay(1500);
      break;
      }
      void Dir(Direction) {
      switch(Direction) {
      case 0:
      digitalWrite 5, HIGH);
      digitalWrite 6, LOW);
      Direction = 0;
      break;
      case 1:
      digitalWrite 5, LOW);
      digitalWrite 6, HIGH);
      Direction = 1;
      break;
      }
      }
      void Stop() {
      digitalWrite(5, LOW);
      digitalWrite(6, LOW);
      delay(5000);
      }
      This isn't tested as I don't have any of the hardware and I am sure someone else could condense it further, but the point is it is much easier to add stations and there is far less repetition.

  • @STho205
    @STho205 2 роки тому

    Like DCC, this will be more used as the install and programming process is higher level 4GL or 5GL Visual.
    EEs still like doing this like coding traffic sensors IRL, but most people don't.
    When the sensor is a simple up sensor drilled between the ties, they are all that plug in to the controller, with simple plugs and to program it:
    You pull up a screen with the stations drawn on a line as objects and you give the stations actions in English as you would PowerPoint animation...
    Stop, hold 1 minute, Reverse
    Or... proceed at speed 5 for sensor 10
    Proceed at speed 3, blow horn 3 times at sensor 11
    Better yet name the objects as MainStreet, Pine and Vine, Lockwood
    For old school LISP, PLC and even C programmers... that sounds boring... But it makes it user friendly for the average automator.... And easier to change.

  • @eytanbarak2261
    @eytanbarak2261 Рік тому

    I started an Arduino course a few weeks ago in order to be able to control my HO DC train layout. your videos are a great, super helpful for a 78 yrs old man. I m confused about what to start first: train control? I have 3 different DC controllers. Can I apply only on one line (controller) .
    from your experience, can you write to me, about what to do first and that second...and the next stages?
    many thanks
    Eytan Barak from Israel😇😍

  • @prapri91
    @prapri91 Рік тому

    thanks for the project, in reverse direction the voltage in yhe tracks goes very low and the locomotive does not move request for a solution

  • @tgribbon1962
    @tgribbon1962 Рік тому

    Fantastic video Jimmy very helpful

  • @peterlutz7191
    @peterlutz7191 2 роки тому

    Many KATO items, including trolleys are available on ebay, there are some actual Japanese hobby shops that sell on ebay.

    • @richardmycroft5336
      @richardmycroft5336 2 роки тому

      I picked up a few KATO trolleys from eBay and I love them, very reliable. But I should note that about half of my locomotives are also KATO, so yes I am biased.

  • @wanderershubarmy8295
    @wanderershubarmy8295 2 роки тому +1

    Thank you so much sir😊

  • @manshedrailroad
    @manshedrailroad 2 роки тому

    I am absolutely inspired!

  • @6yjjk
    @6yjjk 2 місяці тому

    New drinking game: Take a shot every time he says "go ahead and" :P

  • @anfieldroadlayoutintheloft5204
    @anfieldroadlayoutintheloft5204 2 роки тому +1

    good vid jimmy keep up the good vids thanks lee

  • @leonardosouza6290
    @leonardosouza6290 2 роки тому

    Thanks, that is what i looking for!

  • @ulrikesteinkogler4755
    @ulrikesteinkogler4755 Рік тому

    Could you imaging doing the same stuff on a digitized locomotive

  • @TheRealStructurer
    @TheRealStructurer 2 роки тому +1

    I had a quite nice Märklin setup when I was young and wished the Arduino was available then! Now I have Arduino but no train and no space.
    It would be nice to add some acceleration and deceleration at the stops and maybe some signal lights? I always love to put in those kind of small details to make it even more real, and with the Arduino that would be easy and not expensive. Cheers!

  • @carlopinton
    @carlopinton 8 місяців тому

    I take advantage of the portal for a question on roco geoline motorized exchanges with 61195 without decoder. Is it possible to control the switch via Arduino and a relay? Thank you. Carlo

  • @carlfranz6805
    @carlfranz6805 2 роки тому

    Well, that was cool.

  • @romanpapierz5066
    @romanpapierz5066 4 місяці тому

    my car starts when I wave my hand infront of the #2 sensor and does one forward and one backward cycle but will not run continuosly. Do I have something reversed?

  • @maddiek9
    @maddiek9 2 роки тому

    I have a G scale New Bright train for my granddaughter. It is battery-powered (no track power) with a very crude mechanical method of forward / stop / reverse. I would like to add an Arduino / Bluetooth system to control the train motion. I have an Arduino Uno. Any help would be appreciated. A company called BlueRail has already solved this problem, but they have no product due to chip shortage

  • @TDMan-de6jv
    @TDMan-de6jv Рік тому

    Do you need to solder the wire on the train track ? If so how can you solder the wire onto the train track?

  • @dannyvanstraelen3273
    @dannyvanstraelen3273 Рік тому

    I'm just wondering can you replace the infra red sensor by an reed switch

  • @RailyardProductions
    @RailyardProductions Рік тому

    Is there a way to increase/decrease speed while the train is moving. Slow start/stop.

  • @artproposal7774
    @artproposal7774 Рік тому

    Is there a way to make the Tram to add more realistic slow down before stop and speed up gradually?

  • @jmdirstein
    @jmdirstein 5 місяців тому

    Anyone had any luck using an arduino to make a passing loop on an oval single track layout with opposite direction trains? I'm using Kato unitrack turnouts.

  • @leohamelinck3524
    @leohamelinck3524 2 роки тому

    Hello, Very clear explanation. Thank you. I still have one question: If I don't want station 3, I can still use all "//" where station 3 is concerned? In other words; i can skip station 3.

  • @robertneglia1135
    @robertneglia1135 2 роки тому

    This looks just great and i have a spot for this on my track but i can't seem to get it working. I have no power to my test track for the engine. Am i missing something , I have gone over all the coding and the pin plugin on the arduino. I'm stumped.

  • @nordictram
    @nordictram 2 роки тому

    Nice video and great project :) - Cheers NordicTram

  • @tristanclack4052
    @tristanclack4052 2 роки тому

    Thanks Jimmy!
    I'm going to give this ago. However, how would I go about adding additional stations?

    • @deadly_dave
      @deadly_dave 2 роки тому

      I'd be happy to guide you, but if someone just tells you, you won't learn.
      So with that in mind. Consider the information you have so far, what do you think you would have to do to add another station?

  • @dcctrain
    @dcctrain 2 роки тому

    Awesome!

  • @BrianMills
    @BrianMills 2 роки тому

    For the stations in the middle, would it be possible to connect multiple IR sensors in parallel to the same input? That would allow adding additional stations to the setup without altering the code. Or is it imperative that each sensor have its own input pin?
    Also, would it hurt any to write the code to have additional stations even if there's no sensor connected to those pins? Like write the code to have 5 stations even if there are only 3 on the layout. I'm thinking about adding something like this to some T-TRAK modules, but I would likely be building the end station modules first, and adding modules with the additional stations at a later date, most likely one at a time, and it would be easier to not have to remember to adjust the code when adding a new station.

    • @DIYDigitalRailroad
      @DIYDigitalRailroad  2 роки тому

      Hey Brian! I am not sure about the sensors in the middle. I am leaning toward no, but I would be willing to try and be happy to be proven wrong. As for the additional code, not at all! you can actually just put a "//" at the beginning of each line of code you want to be inactive.

  • @pearl9894
    @pearl9894 Рік тому

    Is this train special for aurdiona or any train can used for this project?

  • @Tony770jr
    @Tony770jr Рік тому

    Nice job jimmy! Do you think you could do the same for a DCC layout instead of a 12v DC?

    • @nanderv
      @nanderv Рік тому

      Much different. It's possible, but it requires that you translate into DCC commands, and use a booster to translate that to a DCC signal.
      In principle it's not crazily hard to write code to control the train, especially if there's just a single train. It's just a bit more expensive or complex to set up. For DC, in principle the sensors plus two relays is enough for automating a there and back layout. Nicely oldfashioned electronics, nothing overly complex. For DCC it's largely the same, except that the train control is more involved.
      Oh, and the example of the video expects there to be only one train, so if there's more than one then you may run into issues.

  • @Tony770jr
    @Tony770jr 2 роки тому

    Nice and easy!

  • @jamit2576
    @jamit2576 2 роки тому

    Thanks for this video ,Great video ,

  • @kkrolf2782
    @kkrolf2782 2 роки тому

    Could you provide your sources for the components of this control?

  • @garryhulshof4383
    @garryhulshof4383 2 роки тому

    Wow I think hooking up my home entertainment system was easier

  • @swyntopia
    @swyntopia 2 роки тому

    What´s the purpose of the jumper on the motordriver ?
    Why to remove it ?
    Would it not be easier to use functions for the motorcontrol ?
    Nevertheless: thanks for the description.
    I see, you didn´t use pwm for speedcontrol ?

    • @DIYDigitalRailroad
      @DIYDigitalRailroad  2 роки тому

      The jumpers basically make the motor outputs simple on and offs. By removing them, you can control the speed. Sometimes DC locomotives aren’t great with pwm, so I stuck with the tried and true. As for functions, I try to keep the tutorials as easy to understand as possible. This builds on previous tutorials I have done, so it’s easier to understand.

    • @swyntopia
      @swyntopia 2 роки тому

      @@DIYDigitalRailroad Thank you very much.

  • @bobtaylor9740
    @bobtaylor9740 2 роки тому

    Hi Can this be used over a stretch of a dcc layout.
    cheers ,

  • @bruceyoung1343
    @bruceyoung1343 2 роки тому

    SWEET

  • @joveld6038
    @joveld6038 2 роки тому

    Thanks for the nice video.

  • @petrbucha5762
    @petrbucha5762 2 роки тому

    Super video

  • @AlexEhn
    @AlexEhn 2 роки тому

    Brilliant! Very inspirational!
    Do you know if these IR modules are available in a smaller form factor, e.g with SMD LED's?
    I have issues hiding such bulky IR sensors on my layout.

    • @garrettswoodworx1873
      @garrettswoodworx1873 2 роки тому +1

      How about putting leads between the boards and the LEDs and remoting the board underneath or somewhere else? Just need a little heatshrink to insulate the LED's leads.

    • @AlexEhn
      @AlexEhn 2 роки тому +1

      @@garrettswoodworx1873 That would make it smaller indeed!

    • @DIYDigitalRailroad
      @DIYDigitalRailroad  2 роки тому +2

      What Garret said!

    • @dand8282
      @dand8282 2 роки тому +2

      just put a phototransistor under the track from gnd to a gpio, then use a pinMode of a gpio INPUT_PULLUP. The shadow of the train will make the pin high.

  • @loispadgett6306
    @loispadgett6306 2 роки тому

    This is always fasinating to me but I get lost after a bit. Do you have any recommendations on a book I could get that would help to understand all this? Keep up the good idea's and have fun.
    GOD BLESS 🚂💖🚂💖🚂💖

    • @DIYDigitalRailroad
      @DIYDigitalRailroad  2 роки тому

      I would check out the sponsor in my next Monday video Skillshare. They have a bunch of beginner classes.

    • @loispadgett6306
      @loispadgett6306 2 роки тому

      @@DIYDigitalRailroad
      Can't wait for Monday then.
      Thank you. GOD BLESS
      🚂💖🚂💖🚂💖🚂💖🚂💖

  • @falin9557
    @falin9557 2 роки тому

    I would have written this code:
    int Lstation;
    int Cstation;
    int Rstation;
    int speedVal;
    void setup ()
    {
    Serial.begin (9600);
    pinMode (5, OUTPUT); //Enable
    pinMode (6, OUTPUT); //Direction. 1: Left, 0: Right
    pinMode (3, OUTPUT); //PWM
    //This while moves the train to the right station
    while (analogRead (2) < 500)
    {
    analogWrite (3, 50);
    digitalWrite (6, LOW);
    digitalWrite (5, HIGH);
    }

    digitalWrite (5, LOW);
    }
    void loop ()
    {
    Lstation = analogRead (0);
    Cstation = analogRead (1);
    Rstation = analogRead (2);
    speedVal = analogRead (3);
    speedVal = map (speedVal, 0, 1023, 0, 255);
    if (Lstation < 500)
    {
    analogWrite (3, 0);
    digitalWrite (5, LOW);
    digitalWrite (6, LOW);
    delay (5000);
    analogWrite (3, speedVal);
    digitalWrite (5, HIGH);
    }
    if (Rstation < 500)
    {
    analogWrite (3, 0);
    digitalWrite (5, LOW);
    digitalWrite (6, HIGH);
    delay (5000);
    analogWrite (3, speedVal);
    digitalWrite (5, HIGH);
    }
    if (Cstation < 500)
    {
    analogWrite (3, 0);
    digitalWrite (5, LOW);
    delay (5000);
    analogWrite (3, speedVal);
    digitalWrite (5, HIGH);
    }
    while (Lstation < 500 || Cstation < 500 || Rstation < 500)
    {} //wait doing nothing until the train leave any station
    }
    It's similar, but the while loop on the setup moves the train to the right station, no matter where it is

    • @DIYDigitalRailroad
      @DIYDigitalRailroad  2 роки тому +1

      That's such a great idea! I never thought of moving the train to the station in the setup!

  • @ReaverLordTonus
    @ReaverLordTonus 2 роки тому

    If I were to make a homemade dcc setup, would I need a separate arduino for everything (sensors, switches, etc.) Or can a single arduino run multiple operations?

    • @DIYDigitalRailroad
      @DIYDigitalRailroad  2 роки тому

      It really depends on your level of code ability. This is something that I have always wanted to try, but the level of code required is quite daunting to me.

    • @Robert_Gauld
      @Robert_Gauld 2 роки тому

      @@DIYDigitalRailroadfeel free to get in touch, I'm happy to explore giving you a hand with this.

    • @Robert_Gauld
      @Robert_Gauld 2 роки тому

      @@DIYDigitalRailroad so I had a shower thought (on TonesTheGeek's question), there's a simple (as in minimal extra learning) solution using the DCC++Ex (thanks for finding that for me by the way). The DCC++Ex can be given instructions from a PC over the serial port (see their documentation for details), if you take the arduino from this project and connect its serial port pins to that of the DCC++Ex then this project can control the command station. At which point instead of your code controlling the device which powers the track it sends commands to the command station instead.
      It will require finding the right speeds to send for the effect you want and will be limited to a specific loco (until you change and reupload the code).

  • @dr.blast__2713
    @dr.blast__2713 Рік тому

    So how does the infrared red sensor go on the train, or how does the train know to stop?

    • @DIYDigitalRailroad
      @DIYDigitalRailroad  Рік тому

      The infrared sensors are proximity sensors. When the train trips the sensor the arduino cuts power to the track which stops the train.

    • @dr.blast__2713
      @dr.blast__2713 Рік тому

      @@DIYDigitalRailroad aaah okay thank you, im trying to make my own train that can tow 50-100 pounds, but i was trying to figure out how i wanted to control the 2 motors and was interested in the set up

  • @colevoncole3180
    @colevoncole3180 2 роки тому

    Ever think of laying your own track

  • @metras3
    @metras3 2 роки тому

    I wired up this a demo and to see how it easy to get my Arduino and getting motor control working. I bought a set of 4 L298n boards and only could get about 2 Volts with 12 vdc. After a lot of troubleshooting I found I possibility received 4 bad L298 boards.
    I tried by passing the Arduino and just using 12 v in, and remove applying 5v from the the pin s 5/6 would go an still no output
    Is likely I received 4 badL298N Motor Driver Controller Board or am I just missing something?

    • @DIYDigitalRailroad
      @DIYDigitalRailroad  2 роки тому

      I just want to make sure that you have pin 3 from the arduino. connected to the ENA pin for motor 1 on the arduino.

    • @metras3
      @metras3 2 роки тому

      @@DIYDigitalRailroad The L298 was not grounded to the Arduino. Whoops! All better now

  • @StephenParsey
    @StephenParsey 2 роки тому

    Great video, Jimmy! I am trying to do DC automated running in Z scale using Arduinos thanks to your tutorials and some other ideas I’ve found around the internet.
    Any thoughts on accel/decel going into and out of the stations? I’d like to have it ramp up and down but I think that’s going to mean using like 4 million sensors…

    • @BrianMills
      @BrianMills 2 роки тому +1

      I think you can do it without adding too many more sensors. If you know how much distance it takes to stop the train, just set sensors to either side of the station at that distance, and set the delay before reading sensors after the train starts again to long enough for the train to clear the sensor on the other side. I built an automated DC controller for train shows that runs a train for x time and then stops for y time, and adjusts the speed variable as it transitions so that it speeds up and slows down. I'm not at home or I could share the code that I used, but it's basically increase/decrease by x, then sleep y milliseconds until reaching max speed or 0 depending on whether it's accelerating or decelerating.

    • @DIYDigitalRailroad
      @DIYDigitalRailroad  2 роки тому +1

      I think when we get into speed ramps and slowdowns, you may have to look into current sensing if you want ot limit your number of sensors. It's another project I would like to tackle.

  • @stephenjones8928
    @stephenjones8928 2 роки тому

    toot toot!

  • @mrab4222
    @mrab4222 2 роки тому

    I don't understand the wiring of the pot and the need for the resistor. Couldn't you just connect one side of the pot to VCC, the other side to GND, and the wiper to the analog input?

    • @DIYDigitalRailroad
      @DIYDigitalRailroad  2 роки тому

      Yes you could go without a resistor in wiring the POT, but the additional resistor helps to stabilize the readings from the pot and makes it more sensitive. Without it, it tends to jump from max to min with very little in between.

    • @KennethFinnegan
      @KennethFinnegan 2 роки тому +1

      @@DIYDigitalRailroad the way you wired it didn't make any sense to me either. Typically the center pin is the wiper and the two outer pins are the ends of the fixed total resistance, so you would normally connect the two outer pins to gnd and 5V, then the center pin should follow a nice linear sweep 0-5V

  • @colevoncole3180
    @colevoncole3180 2 роки тому

    Adweo is to confusing

  • @philmissy1
    @philmissy1 2 роки тому

    NO one, I repeat NO ONE ever uses red or white for positive power EVER.

  • @zthanhz23
    @zthanhz23 2 роки тому

    Hello! i have followed some of the arduino code you shared and it worked, but this time i seem to have a problem with the IR3 sensor (aka Station 3) it seems to have no effect on starting and reversing afternoon. Please give me your contact email or facebook and I will send you a clip of the problem, hope you can reply to this soon, dear!

  • @colevoncole3180
    @colevoncole3180 2 роки тому

    Very complicated

  • @tag666kill
    @tag666kill 2 роки тому

    Get bigger trains.
    Put all the pcb's and sensors in the train.
    Program electronic signals for trains to read.
    That would be an interesting set up