Тёмный

Model Railroad Arduino Block Signal Upgraded! 

DIY and Digital Railroad
Подписаться 62 тыс.
Просмотров 16 тыс.
50% 1

#modeltrains #modelrailroad #modelrailroading #arduino #blocksignal
Today we are upgrading my Model Railroad Arduino block signal project. This upgrade will make the model train signal run a lot smoother.
DOWNLOAD UPGRADED SKETCH
github.com/DIY...
DOWNLOAD ORIGINAL SKETCH
github.com/DIY...
DOWNLOAD SCHEMATIC
github.com/DIY...
PARTS
Arduino UNO
amzn.to/2WeLOKP
Infrared sensor
amzn.to/3AKiGKq
LEDs
amzn.to/39DUzRD
Wires
amzn.to/3CLnJe6
Breadboard
amzn.to/39TmMEl
Power supply
amzn.to/3CSJDwd
N Scale Signals
amzn.to/3o5FhO5
HO Scale Signals
amzn.to/3zCXbKd
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

Опубликовано:

 

12 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 56   
@MrToastedtoad
@MrToastedtoad Год назад
Code Tip from a retired commercial software engineer. When comparing some value to a constant, always place the constant first in the statement. example: if (0 == value || 1 == value) { } the alternative being: if (value==0 || value==1) { } You will get a compile error if you instead accidentally code: if (0 = value || 1 = value) { } The compiler will fail attempt change by assignment the constant value of 0 In summary, placing constants on left hand side of the test will allow the compiler to warn you if you inadvertently used the assignment operator ('=') rather than the equality operator ('=='). Thanks for the great video's.
@donaldkormos5529
@donaldkormos5529 3 года назад
Nice job Jimmy!!! Guess I'll have to roundup some parts and give it a try!
@paulhargreaves1497
@paulhargreaves1497 3 года назад
Still at planning stage, so this type of content is perfect!
@brianpagemodeltrains
@brianpagemodeltrains 3 года назад
Very cool, Jimmy! Once again, I'm amazed at how you've managed to amass all the info needed to build these sketches!
@yngsjo
@yngsjo 3 года назад
This is a great beginning. This is quite not how blocksignals work in Sweden. But it's a start to make one. Good ideas.
@edwardaudet8367
@edwardaudet8367 3 года назад
Wow, Wow that's some peice of code. You really put this together and I actually understand it. I've always wanted a signal system on the layout, and tried different things but never completed the project. Jimmy you gave us a setup that looks really do able. Great video and tutorial. Us old guys need to be shown it's actually do able. Thanks again
@johnnyrobertson5971
@johnnyrobertson5971 3 года назад
A huge thank you Jimmy for this update for I am going to use this system and getting very close to installing the signal system and have already programmed my Arduino’s with the old code but will be updating to the new code. Again thank you!!!
@RoyEltham
@RoyEltham 3 года назад
Nice update to your old project, Jimmy!
@jvanamb
@jvanamb 3 года назад
Jimmy, Thank you for the update & upgrade. And YES, "THAT THING HAS BEEN IN THE SHOT THE WHOLE TIME". 🤳🤣 Jim
@CallousCoder
@CallousCoder 2 года назад
Why use so many Arduino's? It makes it rather expensive and more difficult to debug and draws more current etc. If it's because of lack of IO then you can just use an IO extender and if you need analog pins, use a digital switch. I created an extension board that has 32BIT IO (on my channel). The cool thing is that since they run I2C you can easily run 4 wires from your Arduino or Pi (or neighbouring I2C bus) and put the IO where you need it, without running 32 wires (in my case 32 but those are 2 IC's it's 16 per IC and you can have 8 on a single I2C bus) back to the central place. And that can also work on an Arduino, so that's all the digital IO you need (you can add to 8 of these chips on an I2C bus!) And for analog you can use a demultiplexer like a 74HC4051. A raspberry pi or using FreeTOS on Arduino, are better solutions than the standard arduino. As they offer multitasking and in case of a Pi 4 even actual parallel processing. I think you'll find it a whole lot more flexible and solve complex problems. And you can even integrate a nice UI too, showing where trains are depending on IR check points or isolated tracks with current measuring solutions.
@melkitson
@melkitson 3 года назад
Interesting, and I suspect this is going to be very useful. There are a number of questions which I will want to formulate over time but overall I am impressed.
@jaypanditharatne9198
@jaypanditharatne9198 2 года назад
Hi Jimmy, excellent work! We’ll explained, Cheers Jay
@plymouthrovadventures.646
@plymouthrovadventures.646 Год назад
Thank you.. Very nice. I am trying to use a Single Mega replacing the 3 Unio's . Getting my hear around this gives me something to think about..
@roberthughes1796
@roberthughes1796 3 месяца назад
Great information Jimmy. My partner and I built your system last year but have had some problems with it. Mostly bad soldering. I built a signal bridge for one signal target and when I powered it up all of the signal LED's are on. The other signal just the red light is on. What do you think is the problem. I plan on downloading your new sketch. Keep up the great work you do, and thanks
@xicariusx
@xicariusx 2 года назад
Jimmy, I have done something similar and added C/MRI code to the sketch as well. So that it all works with JMRI. Each Arduino is a C/MRI node via USB connection. So you don't need to chain them together and can use as many as you need up to 254 per USB PC hub. In my case Raspberry PI that runs JMRI.
@stephenwadsworth6972
@stephenwadsworth6972 2 года назад
Interesting comment Ian - are you connecting each Arduino to a port in a USB hub - if so how many are you using at the moment, and where do you get a 254 port hub system? I've taken a slightly different tack using Arduino Nanos to check up to 8 sensors and sequence train movement (effectively de-bouncing the sensors) and fed those to JMRI via the sensor inputs on a DCC++EX command station, and then taken a single CMRI node to a Mega to drive 26+ points and 24 signals (so far) using several PCA9685 16 way servo/led driver extension boards (~£3 each) on an I2C bus around the layout.
@phoolb7326
@phoolb7326 2 года назад
Jimmy, Thank You for adding technology to the hobby with the printing and Arduino videos. I'm going to be a bit picky and I do not mean to offend you in any way. It would be better if you used "non-blocking" code for the 5 sec. delays. Presently during the 5 * 1000ms delay the Arduino is just sitting doing nothing and therefore any other inputs that might change during that time may be missed or run in an incorrect order thus possibly sending an adjacent blocks to an incorrect state. This is subtle and is hard to debug should this occur. BTW would you be interested in some oil pumping STL files that I am thinking of making?
@DIYDigitalRailroad
@DIYDigitalRailroad 2 года назад
Hmmm that is interesting to think about. I think the only situation I haven’t accounted for in the 5 seconds would be a train entering at the opposite end as soon as it turns yellow. That wouldn’t take much additional code to remedy. Thanks! As for the stl files. Sure!
@tomg721
@tomg721 6 месяцев назад
I've been enjoying your Arduino programming video's. Have you had any problems with your IR sensors reliably detecting your trains. I have been having trouble detecting my old Lionel metal engines and cars. I'm thinking that the black paint is the problem.
@CallousCoder
@CallousCoder 2 года назад
But first: I love your train set automation videos a lot! It's cool seeing people use embedded systems in their hobbies (warms my progranmer's heart) and very cool. Another tip from am embedded programmer. Don't use int blabla = 12 for a port number. That would compile down to an actual variable, even if you make it a const int -- which btw would've been syntactically better, it is reserved on the read only memory heap. A "#define BLABLA 12" will not steel expensive variable space and translate any BLABLA with the immediate value of 12. This leaves more variables for those complex objects in libraries ;) Also a port doesn't change so a #define or even if you want a "variable" a const is more appropriate. Also the blatant copy of yy to yy1 and only changing the digitalWrite is highly inefficient. You could've changed that into it's own function and parameterised that, with a state parameter and if state is YY1 then set to HIGH else set to LOW and call that function in yy and yy1 respectively. And using globals is a very nasty habit, clearcount could have (and should've) been passed into a function through an argument. And returned after it was updated by the functions. And it could've been a static int clearcount. And one thing that I freak out over, is using delay() in function where there's actually a potential need to keep on running (your trains keep running too) so you don't want to block a function. You would give it a wait amount in an event array, and you keep running the rest of the code and check every time if the time has passed and then execute the command. I tend to make a DelayExecution class that has the delay variable as part of the class. And I inherit from it and implement the "work" method. That way your Arduino keeps working on other tasks in the meantime.
@adambeedle
@adambeedle 3 года назад
Awesome video Jimmy 👍
@dougatwood4056
@dougatwood4056 2 года назад
Jimmy, this is awesome. I breadboarded this out tonight and it works perfectly. I did have a thought: What if a train were to back into the block (say, during switching), trip the sensor, but then move forward out of the block without ever tripping the sensor on the opposite end of the block? The signal wouldn't reset to green. Any ideas? I monkeyed around with the code a bit and setup a "reset button", but hate to have to rely on that.
@scentgrasslakerailway
@scentgrasslakerailway 2 месяца назад
Thanks. Does each Arduino need that sketch you developed inside of it for the system to work as you described?
@Russ97470
@Russ97470 2 года назад
The two infrared sensors at block boundaries could be one shared between two arduinos.
@RRWMFan
@RRWMFan 2 года назад
Jimmy, great video. I have seen others that use a hall effect current sensor instead of the IR sensors. Is there a significant difference in the use of IR vs hall effect? I, like another commentary, am setting this up to also work with JMRI except I will be using RS485 serial communications between the arduinos and the RPi.
@yrunaked4
@yrunaked4 2 года назад
a new series on this could be adding semaphores to the already improved signal series 😄
@robertnagy6015
@robertnagy6015 2 года назад
Great video thank you! I have a question. Could you not use only one voltage detection circuit (like LTV 814 optocoupler that acts like a push botton) for the occupation of the block instead of an entry IR sensor and an exit IR sensor? If there is a train in the block, current flows through the optocoupler that acts as a "push button" and gives signal to an arduino digital pin. If there is no train in the block, there is no current running through the optocoupler so there is no "pushed botton" and no signal to the digital pin. If and when the block is occupied the arduinos of the other blocks can change their signals accordingly. In Hungary we also use red, yellow and green lights to signal track occupancy on real railroad tracks that have automated track occupancy detection between stations, however the neighbouring stations must communicate with each other and pass out the directions of the trains running between them. One station has to be sender and the other must report to be receiver otherwise the system sends an alarm and closes all blocks down with red signals to prevent trains running frontally.
@michaelarmstrong-smith12
@michaelarmstrong-smith12 2 года назад
Hi Jimmy Great video and very well explained. If I wanted to extend this to four or more blocks, is there an easy way of doing it or do I simply daisy chain another Uno or two? - Michael
@DIYDigitalRailroad
@DIYDigitalRailroad 2 года назад
Hey Michael! This setup is built to be able to daisy chain indefinitely with one arduino per block.
@medwaymodelrailway7129
@medwaymodelrailway7129 3 года назад
Nice video you put togehter Jim.
@medwaymodelrailway7129
@medwaymodelrailway7129 3 года назад
Thank you very much for replying to my comment. I would love if you could take a quick look at my page and any feedback would be greatly appreciated. I have a new video out now. Hope you like and share.
@rf64
@rf64 7 месяцев назад
I'm new to this, and I'm already doing something. One doubt was that if two trains run behind each other, it is likely that there will be a red signal. If so, will it stop or do I have to give the order to stop until the signal changes? What if the block is busy, does any subsequent composition stop or not enter that block? Thanks for the help and videos
@ponderingpops
@ponderingpops 3 года назад
Great update. Can this design be adapted for use with a current transformer detection device like the BD20? Great channel, very informative!
@DIYDigitalRailroad
@DIYDigitalRailroad 3 года назад
Yes it absolutely can. It simplifies the code when you do it!
@garagedisimo
@garagedisimo 2 года назад
Hi! Good video! I follow your video and I love it! I have a question. Can Arduino, when the train is near tho the station, play a file MP3 (information about the train) like an real station? Thanks a lot
@NBLeopard
@NBLeopard 2 года назад
It would be very helpful if you could describe where in the block the signals are positioned, what way they are facing and what they are expected to control. For example is one signal at the left end of the block and one at the right end and both facing trains that approach the block so that they control whether trains may enter the block from the left or from the right. I have enjoyed the videos about DCC++ - I am using it and it works very well.
@walshrd
@walshrd 2 года назад
Great video. How does it all work if an adjacent block or 2 is also occupied? Would this/these block's code override RED signals already established by the "current" occupied block turning those RED signals into wrong YELLOW signals?
@eXtremeFX2010
@eXtremeFX2010 2 года назад
Is this a better solution than the current block detection with simple code in a video shared in previous years? Just asking? Trying to decide which route to go. Current Block Detection Or Sensor Block Detection 🤔🤷‍♂️
@alanturner3546
@alanturner3546 Год назад
You have a mistake in line 229. 1024 instead of HIGH
@stanrygula9313
@stanrygula9313 6 месяцев назад
If you were going to have 10 blocks how would you accomplish this using your program. I know you need 10 Arduino’s but how do you define them using this code? Thanks
@ModelSceneryTutorials
@ModelSceneryTutorials Год назад
Will this work on a layout with reversing loops at both ends of a reversing loop?
@railfilm
@railfilm 3 года назад
Hi Jim, the improvement is OK, however the real railroads work a bit differently. I sent you about a year ago my comments and the modified code, where there is a direction bus, ( eastbond or westbond). This turns the signals in wrong direction either too red, or dark, like on the real railroad. ( on analog tracks you can use the track polarity to get the direction signal, in digital you should have a switch to select the traffic direction on the line)..
@DIYDigitalRailroad
@DIYDigitalRailroad 3 года назад
Hey Railfilm! You are correct, I am actually also working on a version of this that will work that way as well. It is actually simpler code than this too! I remember seeing your code and I am so happy that people are taking this and modifying it to work on their layouts!
@henrybest4057
@henrybest4057 3 года назад
Here, in the UK, real railway signals are never darkened. They are always set to red for 'wrong direction' trains. The signals are interlocked with the points [switches] that determine the direction of travel. On models, if the signals and points are interlocked, there should be no need for any direction detectors. Interlocking is a logical operation, easily done on an Arduino.
@railfilm
@railfilm 3 года назад
@@henrybest4057 it is an option to keep the signals for wrong direction red, or darkened. ( there are different rules). Yes, the first signals to the yards can be interlocked with the switches, but in this case we are talking about the automatic block signals on the open line between two stations.
@henrybest4057
@henrybest4057 3 года назад
@@railfilm Its not an option in the UK. The rule here is that they must be set to red for 'wrong direction' trains. Automatic signals must also be able to be controlled from a distance. Does somebody have to walk along the track between the two stations, flipping a switch on every signal to turn it to red (or darken it, in the US), or is it done centrally, through interlocking? Automatic signals must be able to be overridden in emergencies. There's been a landslip ahead. The line ahead isn't occupied (but is obstructed). An automatic signal will continue to show green unless the signaller (maybe many miles away) can turn it to red to prevent an accident. Interlocking isn't only local.
@railfilm
@railfilm 3 года назад
Henry Best Sorry for the confusion.. This signal status is an option on the Arduino project only. Ie. You can select what option you want to have. The red signals or the dark signals. I investigated in several countries and railroads, what is the standard for the signals for wrong direction. There is no common rule, both systems are in operation. On top of that in US there is a line close to Chicago, where all signals are always dark when no train is approaching,. When the train enters the block the signals are turned on, when the train passes the signal the lights are turned off again. In several systems the automatic block signals have an automatic control circuit which continously controls each bulb for conductivity. The red bulbs are special devices with dual filament. Ie when the main tungsten is broken, the second one will turn on and it is indicated in the control box. If any of the green or yellow bulb is broken the signal is turned automatically to red, and there are special rules for the trains what to do in such case. I do not think that these things are important for model RR, it is just some simple summary of the permissive block signals used worldwide with 3 or more lights. (There are automatic systems with 4 lights (2 yellow) for the high speed blocks.. the second yellow indicates the status of the next signal.) For emergency case there are also several systems. Generally all dark signals means STOP for the trains. Ie in emergency case they turn of automatically or manually all signal lights, ie each train must stop before the dark signal.
@EuropeanTrainDriver
@EuropeanTrainDriver 3 года назад
Sehr gut
@ukiepilot5213
@ukiepilot5213 Год назад
Hi Jimmy, does this setup still work if you only have the same entrance and exit into a block such as mine? How do the signals trigger when a switcher is exiting the same way it entered? Thanks much, Jerry K
@dorkydoo683
@dorkydoo683 2 года назад
I am in no way shape or form a programmer, even though I started writing code in BASIC on an Atari 512 and Commodore 64. Is there a significance to the space after the first greater than and no space after the second one? if ((valA1 >"space" 500) && (valA2 >"no space"500) && (valA3==0) && (valA4==0)) if ((valA1 > 500) && (valA2 >500) && (valA3==0) && (valA4==0)) I will be using this on my layout. I am in the process of collecting the pieces and parts needed to start building. As I will be using the DCC++EX, Arduino servo turnout control, Arduino signaling, I am going to need a whole Lotta Arduino's. Thanks. Buzz.
@DIYDigitalRailroad
@DIYDigitalRailroad 2 года назад
Hey Buzz! No there is no significance to that space.
@dorkydoo683
@dorkydoo683 2 года назад
@@DIYDigitalRailroad Thank you for the quick reply. When I was taking C++ WAY back when, everything had to be in the correct position to work correctly. Being an "OLD" guy, the level of tech that model railroading has taken on is amazing. I remember the living room oval or figure 8 with the AFX slot cars running around. Now a degree in computer programming and or hardware is very helpful. Thanks. Buzz.
@CallousCoder
@CallousCoder 2 года назад
@@dorkydoo683 C++ was never space aware. Because C isn't either and C++ compiled down to C initially. So I am really curious what you've used but I never have had an issue with spaces in all my 32 years with C++ :D Unlike python :D
@dorkydoo683
@dorkydoo683 2 года назад
@@CallousCoder It seemed every time I went to compile it would give me errors. I would go through the very simple code, make sure I did not have spaces between the last letter and the semi colon, colons, two spaces between words. I might not have been that, but in removing the spaces, I fixed what was actually wrong. Yet every time I made sure of the spacing, it worked. Really doubt that makes any kind of sense? One of the biggest issues I had, the instructor was GOD level and he had trouble coming down to peasant level. I guess when you are the senior programmer, with years and years of practice, it is difficult to see it from the first time programmer. I did not know enough to be able to ask a proper question. Buzz
@rickmiller595
@rickmiller595 Год назад
Common negative....js, sorry I work in low voltage ....
@4everdc302
@4everdc302 3 года назад
I will never do this but it is intriguing on can be done👍kudos on the effort 🚂🚃🇨🇦
Далее
iPhone 16 для НИЩЕБРОДОВ!
00:51
Просмотров 2,1 млн
a hornet bit me on the nose 👃😂
00:16
Просмотров 2,6 млн
Arduino Block Signal for Model Trains
42:40
Просмотров 75 тыс.
DIY Arduino Model Railroad Reversing Loop
25:24
Просмотров 29 тыс.
Easy Arduino Current Sensing for Occupancy Detection
14:08
G scale track discussion (LGB, Bachmann, Peco, Piko)
6:08
Control 16 Servos Using A PCA9685
18:22
Просмотров 73 тыс.
The Bletchley Derailment | Jakeso
14:04
Просмотров 13 тыс.
iPhone 16 для НИЩЕБРОДОВ!
00:51
Просмотров 2,1 млн