Venderwel

New (Noob) Arduino Train automation project.

Recommended Posts

Interesting project. You have a few light sensors, but no light source? Are you counting on stray light in the room?

The ESP32 is not 5V tolerant on inputs, strongly suggest level converters.

You plan on controlling the train via BT from the ESP32 and the switches? How will you control the ESP32, or the logic behind all? 

I do wonder how experienced you are in programming, afraid you are facing a steep learning curve here. 

 

Edited by LEGO_duden

Share this post


Link to post
Share on other sites

i think he is counting on stray light wich should work. as an extra tip: the gaps between individual cars will trigger the light sensors aswell so programm some sort of dead time in.

 

XG BC

Share this post


Link to post
Share on other sites

I bought these motor controllers https://www.amazon.nl/gp/aw/d/B081JXSXJ1/ref=ppx_yo_mob_b_track_package_o0_img?ie=UTF8&psc=1.

 

Why 12v? Because I have some 12v power supplies laying around. ?

Light sensors: I expect the room to provide enough light to notice that a train is passing by. Good point about the individual cars though! I'll take that in mind!

I have little coding experience. I am used to reading and understanding code. I can copy code from other projects and adjust to my benefit. Still there will be enough to learn yes. 

I will use Arduino on the ESP32 and yes I hope to find out I can control the trains with bt too with. Or otherwise through an other program on pc....much to find out. But that makes it fun! (And probably frustrating sometimes! )

Share this post


Link to post
Share on other sites

thanks for the link they should work with 9v aswell as i said it probably isnt an issue if you are runnung the motors for a short period of time as you do when switching a switch just check if your motors get excessively hot. if thats the case i would switch to 9v. but i am interested to see what you come up with.

 XG BC

Share this post


Link to post
Share on other sites

Just run pwm at 75% and you will effectively  run the motors at  9V..

Do you have a switch powering design ready? 

Share this post


Link to post
Share on other sites
7 hours ago, LEGO_duden said:

Just run pwm at 75% and you will effectively  run the motors at  9V..

Do you have a switch powering design ready? 

I know in the past that the old mindstorms system that were used to control various LEGO robotics and automate trains, the voltage was controlled using PWM and it put a lot of stress on the train motors and would wreck them. 

Just a warning about LEGO motors and PWM.

Share this post


Link to post
Share on other sites
29 minutes ago, supertruper1988 said:

I know in the past that the old mindstorms system that were used to control various LEGO robotics and automate trains, the voltage was controlled using PWM and it put a lot of stress on the train motors and would wreck them. 

Just a warning about LEGO motors and PWM.

I don't know about the older motors, but, the Power Functions IR Receivers use PWM (This is responsible for the whining sound made when not at full power). So, Power Functions motors and probably PUp motors should be able to handle it just fine.

Share this post


Link to post
Share on other sites
On 8/27/2020 at 10:25 PM, Venderwel said:

6 (or more) lm393 lightsensetive optical sensors for train detection.

From experience I can tell you that light sensors are not working (at least not good enough).
I use an arduino setup for many years now and have very good experience with reed sensors (needs a magnet underneath the train).
Since last year I also use RFID chips and detectors, but that is only necessary if you want to identify specific trains.

When I started with all of this, the following youtube channel was really helpful.

https://www.youtube.com/c/ArduinoLegoTrains/videos

If you need some info on my setup (which differs per exposition) just say so.

Share this post


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

and have very good experience with reed sensors (needs a magnet underneath the train).

Aren't the magnetic couplers sufficient?

 

9 hours ago, supertruper1988 said:

I know in the past that the old mindstorms system that were used to control various LEGO robotics and automate trains, the voltage was controlled using PWM and it put a lot of stress on the train motors and would wreck them. 

I killed a new 9v train motor that way in 2 days at a show.

 

8 hours ago, Daedalus304 said:

I don't know about the older motors, but, the Power Functions IR Receivers use PWM (This is responsible for the whining sound made when not at full power). So, Power Functions motors and probably PUp motors should be able to handle it just fine. 

I bet they have a capacitor or similar in them to smooth out the pulses. Trouble is, they don't do track power. But, burn out the 9v motor, retrofit with the motor some of the innards of a PF or PU motor and good to go, or turn a dead 9v into a PF power pickup using the 9v to PF plug on a connecting wire.

Share this post


Link to post
Share on other sites
2 hours ago, aawsum said:

When I started with all of this, the following youtube channel was really helpful.

https://www.youtube.com/c/ArduinoLegoTrains/videos

If you need some info on my setup (which differs per exposition) just say so.

That's where I got the idea for the lightsensors from...?

Thanx for the offer, I'll probably contact you soon, since I have no experience, so I need examples I can turn into my own. ☺️

Am going to use old 9v engines for the switches. Cheaper then pf or pu engines. And I can cut the wires in half and connect those to the L298. 

Okay so no 12v.....I'm going to find myself a 9v powersupply then. Maybe a Lego one!

 

Share this post


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

Aren't the magnetic couplers sufficient?

No they are too high above the sensor, plus a bigger magnet will help in stability of the readings.

30 minutes ago, Venderwel said:

That's where I got the idea for the lightsensors from...?

Me too. I used all his ideas to get a feeling of the arduino. The light sensor worked at home, but in a bigger room it was completely useless. I also use infrared sensors for detection and those work also very well. It depends a bit of the setup and the place where I need them.

To give an idea I have a small movie on my flickr page that shows parts of the setups. (click on the picture to get it working)
 48842086931_24e99c56fe_c.jpgsneak preview layout 2019 Legoworld by Aawsum MOCs Lego, on Flickr

Edited by aawsum

Share this post


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

Since last year I also use RFID chips and detectors, but that is only necessary if you want to identify specific trains.

Hi @aawsum ,

can you tell me which type of RFID reader you have used?

Share this post


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

Me too. I used all his ideas to get a feeling of the arduino. The light sensor worked at home, but in a bigger room it was completely useless. I also use infrared sensors for detection and those work also very well. It depends a bit of the setup and the place where I need them.

 

Well....I'll give it a go anyway, I have those now! And I'll probably learn something from it. But thanx for telling! Now I know that if it doesn't work, it doesn't havet to be me.... :pir-sweet:

Share this post


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

Hi @aawsum ,

can you tell me which type of RFID reader you have used?

I use the Grove - 125KHz RFID Reader, but I have created my own copperwire antenna for it to create a bigger detection area.

1 minute ago, Venderwel said:

Well....I'll give it a go anyway, I have those now! And I'll probably learn something from it. But thanx for telling! Now I know that if it doesn't work, it doesn't havet to be me.... :pir-sweet:

Maybe you can get it to work ;-)
I also learned a lot from it, so it is good to try.

Share this post


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

but I have created my own copperwire antenna for it to create a bigger detection area.

Can you give me a picture or a video?

Edited by GianCann

Share this post


Link to post
Share on other sites

50287149702_a4b847397f_c.jpgRFID antenna setup by Aawsum MOCs Lego, on Flickr

 

This will fit underneath a railway track or crossing. I used an online calculation method to calculate the number of cycles based on the width and length. Works really well, failure is below 1%.

Edited by aawsum

Share this post


Link to post
Share on other sites

So I somehow managed to merge the Leguino Lego Train PU sketch with ALT's (Arduino Lego Train) lightsensor sketch. And it's working!

Not perfect yet, looks like the lightsensor detection is not working as well as I hoped, already mentioned by @aawsum. But besides that the sketch does what I meant it to do. 

Edited by Venderwel

Share this post


Link to post
Share on other sites
2 hours ago, aawsum said:

This will fit underneath a railway track or crossing. I used an online calculation method to calculate the number of cycles based on the width and length. Works really well, failure is below 1%.

Even with a speeded train?

Share this post


Link to post
Share on other sites

Yes it wil also detect faster running trains, that is why I made the antenna larger. I have to say I never tested it with just a loc on full speed, but that has another reason (below).

On the video that I posted earlier there are 2 RFID detection points, 1 is underneath the switch in the bottom left corner. You can see the speed of the trains in that one. All trains except the blue passenger train will trigger the RFID detection and will then take the inner route t the rail yard.
Main reason why we are not running faster is that I also need time after triggering the detection to turn the switch. Out of experience a minimum of 5 rail pieces need to be in between (with the speed I am driving). If you will drive faster then you need more space as turning the switch will take some time.

10 hours ago, Venderwel said:

So I somehow managed to merge the Leguino Lego Train PU sketch with ALT's (Arduino Lego Train) lightsensor sketch. And it's working!

Not perfect yet, looks like the lightsensor detection is not working as well as I hoped, already mentioned by @aawsum. But besides that the sketch does what I meant it to do. 

Nice to hear, it is not a difficult sketch indeed but it is always satisfying to get your code to work. Light sensor is really nice but with all the shadows and diffuse lighting it is so unreliable. I tried multiple detection sensors, but so far only reed, rfid and IR work stable in my setup.

Edited by aawsum

Share this post


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

Nice to hear, it is not a difficult sketch indeed but it is always satisfying to get your code to work. Light sensor is really nice but with all the shadows and diffuse lighting it is so unreliable. I tried multiple detection sensors, but so far only reed, rfid and IR work stable in my setup.

Can we have a close look of the reed and IR solutions?

Share this post


Link to post
Share on other sites

IR is a tiny chip. Has a send on 1 send of the track and a receive on the other side. I have hidden them in these DBG objects. For best performance place them not exactly across each other, but at an angle. (this is to eliminate the gap between 2 wagons. And yes the picture shows them exactly opposite of each other, but this is before I learned the lesson :-)
31878774972_8c51cfb85d_c.jpg
Started mounting infrared sensors in Lego that are controlled by arduino. These will sense a train passing and signal 2 red lights at a train crossing. This all will go in a train layout that will hopefully be at Legoworld Utrecht this year. by Aawsum MOCs Lego, on Flickr
50289381271_4a7a421dd3_c.jpg
IR setup by Aawsum MOCs Lego, on Flickr


The reed setup is the following. Reed sensor is placed as high as possible. I created these square blocks that can be clicked in the rails I use. Another advantage is that these blocks 'protect' the reed sensor. As it is a glass shell it will break easily, however since I use these blocks I never broke one when travelling, only by my own stupidity ;-)
The picture shows how I setup the rail yard. Trick here is that not each train is as fast or will stop at the same place. During testing you can mitigate this to place the magnet at a different place in the train. This gives you flexibility instead of having to move the reed sensor.
50289530827_916eca880c_c.jpg
Reed sensor detail by Aawsum MOCs Lego, on Flickr
50289527882_8f0190f1ef_c.jpg
Reed sensor overview by Aawsum MOCs Lego, on Flickr

Edited by aawsum
Small text adjustments

Share this post


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

Is a very small IR sensor with a digital output (0 or 1) when an object is in a range 2-10 cm.

I am using this one as well - however with a little more electronics around it, so you can adjust the sensitivity:
https://eckstein-shop.de/TCRT5000-IR-Barrier-Line-Track-sensor-Infrared-Reflective-Photoelectric-Switch

Will post a little more on that later today or tomorrow. They fit nicely between two 9V/PF track sleepers.

Best
Thorsten 

Share this post


Link to post
Share on other sites
7 minutes ago, Toastie said:

however with a little more electronics around it, so you can adjust the sensitivity

I think a range of 10cm is an optimal solution to detect a train. I always prefer the smaller electronic solution ... it's my fixation: like that of using the ESP-03 instead of the more comfortable ESP-12F :laugh:

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.