Venderwel

New (Noob) Arduino Train automation project.

Recommended Posts

1 minute ago, MAB said:

For switching points, SG90 type servos are a cheap alternative to Lego motors. You can get quite low quality ones for about $1 each and these are perfect for switching throw switches on points.

Thanx, I'll keep it in mind! For now I have 4 old 9v lego motors and as long as I can still get them for a reasonable price, I think I'll stick with those. 

Share this post


Link to post
Share on other sites
6 hours ago, Venderwel said:

Have a digital overview of my layout and see what train is where. Like for example in nControl by 4DBrix, I believe @GianCann is very busy with this one... ;-) (but I am open for other suggestions!)

I think that nControl is very, very, very good product with a lot of potential.

I believe that @Lowa has already done a great job and that the next releases will be even more versatile, with additional features for even the most demanding AFOL maker.

I suggest you check the 4DBrix forum  https://www.4dbrix.com/forum/index.php and maybe test the software yourself.

Share this post


Link to post
Share on other sites
26 minutes ago, GianCann said:

I think that nControl is very, very, very good product with a lot of potential. 

I fully agree on that. The tile based programming is a blast. While you build your track layout you are getting already programming functionality for each tile if you wish. Custom controllers can be seamlessly integrated. It is fantastic!

Best
Thorsten 

Edited by Toastie

Share this post


Link to post
Share on other sites
On 9/3/2020 at 4:27 PM, GianCann said:

I suggest you check the 4DBrix forum  https://www.4dbrix.com/forum/index.php and maybe test the software yourself.

I am going to test the software myself and I wonder if you could give me an example of your sketch. How do you put the sensors and switches in there to work with nControl?

Share this post


Link to post
Share on other sites
On 9/3/2020 at 3:42 AM, Venderwel said:

Hey @Toastie, that's no problem at all! It's a thread about me getting my layout automised. With help of Arduino. Not being said all has to be in Arduino. If there are other programs that can make life easier and only use Arduino to control the switches and get input from the sensors. Even better! Also want others to learn from this thread.

What I'd like my system to do in the end is:

  • Be able to function on it's own: Random asign stations and routes to trains etc.
  • Be able to easily add and control trains of other users.
  • Also give me the option to asign stops to a train myzelf, handle that order and go on after the order is finished.
  • Have a digital overview of my layout and see what train is where. Like for example in nControl by 4DBrix, I believe @GianCann is very busy with this one... ;-) (but I am open for other suggestions!)
  • Be able to use something like https://scratch.mit.edu/ to have my kids (or maybe a class at school) program the tracks and trains.

It will be a lot of work to get there I think, or maybe it's easier then I think. 

I've started down the Automation journey about a month ago.  The kids are part of the driving force, but also I wanted to get back into coding, so this was a good foray for that.  I've also been a log time lurker, very little poster here.

I was looking at the nControl suite, but opted to go a bit of a blend of Internet of Lego & Mattzo's paths [http://www.internetoflego.com/ & http://mattzobricks.com/ ]  leveraging the NodeMCU ESP8266 modules for controlling the sensors, lights, switches, and will get to train control as well.  I do like what Mattzo was looking at towards integration with rocRail for full automation, but am starting out with Node-Red on a raspberry Pi.  This allows the audrino boards operate as a individually, and the parallelism is centralized via MQTT messaging to the flows within Node-Red.  It's allowing me to start slow, test, build up in scaling out.   While the flows in Node-Red won't let you visualize the track per-se, it will allow me to make a dashboard to control the track sections and trains, creating a sudo-autonomous situation at first, and then maybe flows can do full automation.  I'm still very early on in the work, getting the hang of programming again(been a number of years since doing stuff at this level), and also the feel for it all and Node-Red, MQTT, etc.

Share this post


Link to post
Share on other sites
On 9/4/2020 at 11:20 PM, Venderwel said:

How do you put the sensors and switches in there to work with nControl?

@Venderwel I guess this is very nicely explained by @Lowa on their website.

Also, what kind of sensors/actuators are you planning on using? I bet you said that somewhere here - but this thread  is becoming long. And it is getting like a moving target as there are so many options and pathways to follow. I believe what @DGoSec is pointing to is also very powerful. However, there should be a well-thought-out way of how to accomplish your goals.

I remember that the degree of complexity will be high - at least too high for me. In this case I'd decide first: Control from a desktop/laptop with maybe even 2 screens? Then the number of trains, switch points, other things to control comes into play. And then: Will it be all LEGO? All based on PUp or mixed, e.g. PUp and PF, PUp and EV3/NXT, Spike or not. This all counts in. All wireless, or both? WiFi, BLE, BT? Or all? The ESP32 nodeMCUs talk it all ... 

With nControl you can customize your layout using LEGO as well as other hardware, including your own home-brews. Distributed intelligence, as @DGoSec is mentioning (one RPi controlling/managing numerous Arduinos for example (or ESP32s ore ESP8266s). What I like most though is to have the layout as integral part.

(I am happy to share any code I have. Thing is the Laptop all that stuff is on, is waiting to be picked up by Dell. I dumped as half glass of wine over it. It went dead and then began to develop bad hot electronics smell accompanied by some smoke. A quick inspection indeed showed burnt electronics ... I am now on my old laptop)

Also @Lowa was very responsive when I began fiddling with nControl. I bet you can ask them specific questions and will get very helpful replies.

All the best
Thorsten

 

Share this post


Link to post
Share on other sites
13 hours ago, Toastie said:

Also, what kind of sensors/actuators are you planning on using? I bet you said that somewhere here - but this thread  is becoming long. And it is getting like a moving target as there are so many options and pathways to follow. I believe what @DGoSec is pointing to is also very powerful. However, there should be a well-thought-out way of how to accomplish your goals.

 

I plannend on using lightsensors for detecting trains. I found out these don't work good enough to use. So I decided to use IR sensor modules for that, they work to good, they sense all kind of things, not only the trains. So now I'm looking into using reed sensors, the way Mattzo is using them, seems to be near flawless! So I'll use them to detect trains in sectors and I'll use lego motors connected to L298n modules for track switches. Trains only PUp......

The rest is not decided yet. I'd like to be able to let all trains ride automatically, let the system decided when to stop where. But I'd also like to be able to run by hand and give actions during the automatic fase. First thoughts were to let the ESP32 do everything, but reading more stuff en watching more video's makes me thing the ESP32 should only be the man in the middle handling the sensors and switches and let the laptop and the train software like nControl or RocRail do the controling part. Having it on a screen like that makes also makes it easier to show someone else.

Share this post


Link to post
Share on other sites
6 minutes ago, Venderwel said:

So I decided to use IR sensor modules for that, they work to good, they sense all kind of things, not only the trains. So now I'm looking into using reed sensors, the way Mattzo is using them, seems to be near flawless! So I'll use them to detect trains in sectors and I'll use lego motors connected to L298n modules for track switches.

So this is exactly what I use at the moment. Reed and IR for detection and the L298n with Lego m motor for the switches. Plus Rfid for recognizing trains.
So I few remarks/questions;
- I started with IR beams because due to the movement of the trains on exhibition tables the reed sensor sometimes breaks. Can someone provide a link to "Mattzo" as mentioned in the quote, as I am interested to see in what way his setup is different and maybe it will help me to improve my setup.
- I also use IR to stop trains, and then the advantage is that the train will keep the ir sensor blocked so I can use that in my code. The reed sensor is only triggered by a magnet, so that does not suit me
@Venderwel you state the IR is also triggered by other things, can you elaborate a bit. If you set the range to a few cm I would say only the train or a manual intervention can trigger it. Or is it also triggered by dust or shadows (which sounds a bit strange)

Share this post


Link to post
Share on other sites
3 minutes ago, aawsum said:

@Venderwel you state the IR is also triggered by other things, can you elaborate a bit. If you set the range to a few cm I would say only the train or a manual intervention can trigger it. Or is it also triggered by dust or shadows (which sounds a bit strange)

Maybe I need to experiment with it a little more, but for now I can't seem to get the range small enough. It keeps detecting my train at the otther end of the loop, or a person sitting there or stuff like that. And also can't seem to get a reliable reading when I actually do want it to detect, when a train is passing. Maybe it's to close? I don't know yet. Thing I still want to try is to have my IR on a bit of an angle up, maybe that helps.

http://mattzobricks.com/ very informative!

Share this post


Link to post
Share on other sites
16 minutes ago, Venderwel said:

Maybe I need to experiment with it a little more, but for now I can't seem to get the range small enough.

Did you try out one of these (or the like, TCRT5000 based): https://eckstein-shop.de/TCRT5000-IR-Barrier-Line-Track-sensor-Infrared-Reflective-Photoelectric-Switch ?

@GianCann also used them without the additional electronics, I believe. With the additional electronics as shown in the link you can dim down the sensitivity to about 2 cm or even less. The only downside is very bright (sun) light as they sometimes falsely detect that as reflected IR. I am using four of those without any glitch so far. They also point upward, 2 cm range, so that hardly anything other than a train is detected.

Best
Thorsten

Share this post


Link to post
Share on other sites
1 hour ago, Toastie said:

They also point upward, 2 cm range, so that hardly anything other than a train is detected.

This was also what I was going to try, mount them in between the rails, facing upward. I am going to try the ones that are adjustable in range and set them as small as possible.

Share this post


Link to post
Share on other sites
24 minutes ago, Venderwel said:

You use them completly upward? As in laying in the track?

Uhmm - yes. See here: 

And here is a detail: bild4small.jpg

Best
Thorsten

P.S.: The sensors I am using just "snap in" between the rails after very little filing at the short ends. Their PCB is then almost level with the sleepers. Can show details, if you wish. 

Edited by Toastie

Share this post


Link to post
Share on other sites

I just ordered and installed the IR sensors, slight variant of Toastie's selection that I could get in the US from Amazon (https://smile.amazon.com/gp/product/B01I57HIJ0/ref=ppx_yo_dt_b_asin_title_o00_s01?ie=UTF8&psc=1) that I just used for my train crossing, this seems to work better than the reed switch sensors I was gonna use as it will detect not just the locomotive, but all the cars as they pass, with one sensor on each end of the crossing.  I mounted between the rails as well, no filing, but I did raise my track to nominal ballast level (2 plates above baseplate) and the top of the IR bulbs is about even with the top of the rail.  Works well so far, not had to adjust for an sun/outside light interference yet, will test.  This is running to my custom Arduinio controller, ESP8266 based.    I hope in the next few weeks to get my code up into a github once it's cleaned up.

Share this post


Link to post
Share on other sites

I use gesture sensors, they are even better, they detect train direction and distance... Custom PCB to let it fit just between the tracks.

Share this post


Link to post
Share on other sites
1 hour ago, JopieK said:

use gesture sensors, they are even better, they detect train direction and distance... Custom PCB to let it fit just between the tracks

Nice one!

I bet that there are many, many more powerful alternatives to the sensors I used. The IR-line tracker sensors are just dead cheap. And have two states: Yes or No. I guess it simply depends on what one wants to accomplish and then make the choices. For me it was: A Crocodile that runs back and forth on one stretch of track, with a triggered (not by time) acceleration and deceleration section and defined (>safely< triggered) end stops. The latter is of particular interest as the far end of the track is above a stair and behind a bookshelf on a sloped wall. When I need to get there because the Crocodile derailed it will be some effort - provided it did not fall from 3.5 m height onto the ground of the room below.

BTW, did a "stress test" of the setup (ESP32 nodeMCU based with the four line tracking sensors set to low distance) for about an hour (actually the batteries drained ...) as well as in sunlight and in the dark. No failure once. All 4 sensors fired each time (4x per revolution).

So far we now have at least the reed contact, laser distance, gesture, photo-electric barrier (IR/VIS), as well as the IR line tracker sensors. Nice selection. And most probably many more. It then pretty much depends on what the goal of the setup is to decide on which sensor to be used and which level of customization (e.g. custom PCB board) is feasible or: within reach. Plus cost per piece. And integration into code of course. On/Off or L/H is easiest but then there is no distance information other than: It is there or not.

Oh well, it all depends I guess, when it comes to judge good - better - best. For me it is more: "Fits well" with regard to the task/goal.

Best
Thorsten 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.