This one took me ages to get it to work! I realised that my coding is far from expert. I played around with some of the LDR values and it now works great. I also had to swap around the polarity of my three-pin LDR (and add a resistor). Thank you :-)
so how do I add in a second sensor for station #2, so that it stops and starts at both, Ive been working on it for a week and cannot get it.. tried just about everything, but im not that great at it either. any help is appriciated.
Hello. I am Wil Wilkes from The Netherlands. I've watched movie on youtube and I also tried it at home and it works. thanks I have 2 lego trains crossing at an intersection, I want to protect the trains with Arduino that they can not crash each other. Do you have an idea how to make it? greetings Wil Wilkes
Arduino Lego Trains When train 1 ride across the intersection. Then train 2 and 3 stop. If train 2 ride across the intersection, then train 1 stop. But train 3 don`t have to stopIf train 3 ride across the intersection, then train 1 stop. But train 2 don`t have to stop
I'm not sure how you have three trains on one intersection. But to solve your problem you should use a Finite State Machine. How many tracks are you controlling with the arduino?
wim Wilkes Hi Wim. If you haven't seen it already, the Train Crossing tutorial is available here: ua-cam.com/video/YqTgpuXnWeI/v-deo.html That should help you get started with your train crossing scenario.
Hi! Where do you get your sensors? I've looked around a bit on places like element14 but I can't seem to find these kind of sensors. I dunno, maybe I'm looking in the wrong places. Where did you get yours? Cheers.
+Ryan Stickland I get them from my local electronics store here in Poland, but they're very common components. I don't know where in the world you are so I can't recommend a specific store, so try searching "arduino photoresistor sensor".
Hiya. With the arduino inside the train (for PF trains, mentioned in video #11). How would you get information from a track-based sensor to the train-based arduino? Alternatively, how would you move this to train-based?
If the sensors are at stations, then you can just run an IR led to the top of the station from your trackside arduino, with no need to add an Arduino to the locomotive. That's the basic principle shown in Tutorial 11. Even if you have Arduino on board (like Tutorial 12) the train still has its IR receiver, and can accept commands from any arduino/IR Led it has access to :). The next video removes the train's IR Receiver, so that solution will be a bit more complex.
I had been looking at removing the IR Receiver and replacing it with an sbrick anyway, so that's not an issue for me. At this point I think I may hold off planning anything until I've seen your next couple of videos. I'm also going to want more and more functionality as time goes on, so I will be following your videos eagerly. Is your code downloadable anywhere?
Sure! Visit arduinolegotrains.wordpress.com and check out the CODE tab at the top; you can copy code for each tutorial from there. Hopefully the next video will save you some money, as the S-brick is quite expensive and my solution is 1/10th of the price.
I built a Dutch NS train. For the perfect control I used the Arduino Uno rev 3 with a L298 motor controller and LM393 light sensor. The problem is that the train doesn’t stop when he passed the light sensor. The sensor detects the train as you can see in the pictures. imageshack.com/a/img923/9739/vmeSkM.jpg (sensor detects nothing) imageshack.com/a/img922/9409/wRazSO.jpg (sensor detects the train) imageshack.com/a/img924/2663/06S9nL.jpg (overview) imageshack.com/a/img922/8052/wFOJyT.jpg (overview) imageshack.com/a/img922/1108/gcyagN.jpg (code) Can you tell me what I do wrong?
+Niels Albrechts Hi! Your code looks identical to mine. Have you opened the Serial Monitor and confirmed that your sensor reads below 500 when the train is detected?
Niels Albrechts Something's not right there. Send this little sketch to your arduino: int LDR = 0; //analogue input pin int LDRValue = 0; void setup() { Serial.begin(9600); } void loop() { LDRValue = analogRead(LDR); Serial.println(LDRValue); delay(100); } Connect the light sensor, and make sure you have readings between 0 and 1023. If you only have 0, then you have not connected the light sensor correctly (i.e wrong analog input pin, wrong wires, no power etc).
+Arduino Lego Trains That tests works correctly. Normally the serial monitor gives a value between 27 and 31. When the sensor detect my finger the serial monitor gives a value of 1023.
Why does nobody care about the accident? With the CAT?! I wanted this cat so bad when I was a kid! So moral of this video: You need to spot your cat, use ultrasonic or so cause other times it's bad! :) Meow.
For infrared sensors you need two LEDs; an infrared LED and an infrared sensor (photoresistor). I used these in Tutorial 8 (ua-cam.com/video/JKjcNlPMSNc/v-deo.html), so check out the code there.
This one took me ages to get it to work! I realised that my coding is far from expert. I played around with some of the LDR values and it now works great. I also had to swap around the polarity of my three-pin LDR (and add a resistor). Thank you :-)
I think it's great that the train does not stop instantly. It is important for kids to know that a train can not stop easily.
I wanted this set so bad when I was a kid.
hello can you write the list of the components in this idea? .. thanks in advance
so how do I add in a second sensor for station #2, so that it stops and starts at both, Ive been working on it for a week and cannot get it.. tried just about everything, but im not that great at it either. any help is appriciated.
awesome.
Hello.
I am Wil Wilkes from The Netherlands. I've watched movie on youtube and I also tried it at home and it works. thanks
I have 2 lego trains crossing at an intersection, I want to protect the trains with Arduino that they can not crash each other.
Do you have an idea how to make it?
greetings Wil Wilkes
I do! If you subscribe, I will add a video on how to do this very soon - it will Video #6 in this series.
Arduino Lego Trains When train 1 ride across the intersection. Then train 2 and 3 stop. If train 2 ride across the intersection, then train 1 stop. But train 3 don`t have to stopIf train 3 ride across the intersection, then train 1 stop. But train 2 don`t have to stop
I'm not sure how you have three trains on one intersection. But to solve your problem you should use a Finite State Machine.
How many tracks are you controlling with the arduino?
wim Wilkes Hi Wim. If you haven't seen it already, the Train Crossing tutorial is available here: ua-cam.com/video/YqTgpuXnWeI/v-deo.html
That should help you get started with your train crossing scenario.
I always like to watch my lego tutorials for the blood and gore
How do you do it with power functions
Check out Tutorial 11 in this series to see how to control Power functions trains.
Arduino Lego Trains I mean can u still do the same light sensors and all that cool stuff you designed for 9v with power function
Hi, can you tell me the product no of optical sensor?
Zhengrong ZANG Sure, it's an LM393 Light Sensor Module.
1:00 No blood on the train though xD
Hi! Where do you get your sensors? I've looked around a bit on places like element14 but I can't seem to find these kind of sensors. I dunno, maybe I'm looking in the wrong places. Where did you get yours? Cheers.
+Ryan Stickland I get them from my local electronics store here in Poland, but they're very common components. I don't know where in the world you are so I can't recommend a specific store, so try searching "arduino photoresistor sensor".
+Ryan Stickland SparkFun & Adafruit are a couple of good places I'd recommend.
I get them by AliExpress, very sheep
try mindsenser.com
Cool!
Do you need add resisters along the wire to protect arduino? If so how many ohm?
Hiya. With the arduino inside the train (for PF trains, mentioned in video #11). How would you get information from a track-based sensor to the train-based arduino?
Alternatively, how would you move this to train-based?
All will be revealed in the next tutorial, which will be published this weekend! Big hint: 433Mhz wireless transmitters.
Looking forward to it, as I'm just about to begin my Lego Train journey. It's all PF-based, and stopping at stations is very important.
If the sensors are at stations, then you can just run an IR led to the top of the station from your trackside arduino, with no need to add an Arduino to the locomotive. That's the basic principle shown in Tutorial 11. Even if you have Arduino on board (like Tutorial 12) the train still has its IR receiver, and can accept commands from any arduino/IR Led it has access to :).
The next video removes the train's IR Receiver, so that solution will be a bit more complex.
I had been looking at removing the IR Receiver and replacing it with an sbrick anyway, so that's not an issue for me. At this point I think I may hold off planning anything until I've seen your next couple of videos.
I'm also going to want more and more functionality as time goes on, so I will be following your videos eagerly.
Is your code downloadable anywhere?
Sure! Visit arduinolegotrains.wordpress.com and check out the CODE tab at the top; you can copy code for each tutorial from there.
Hopefully the next video will save you some money, as the S-brick is quite expensive and my solution is 1/10th of the price.
so, is 1023 really bright and 0 really dark?
This is what confused me for a while... I had to reverse the polarity of my LDR (with resistor) to get the code to work properly. Hope this helps :-)
Ever tried integrating a raspberry pi?
Minifigology Guy I think that wouldn't be very much different ;)
can you use arduino for PF lego trains?
Yes
I built a Dutch NS train. For the perfect control I used the Arduino Uno rev 3 with a L298 motor controller and LM393 light sensor.
The problem is that the train doesn’t stop when he passed the light sensor. The sensor detects the train as you can see in the pictures.
imageshack.com/a/img923/9739/vmeSkM.jpg (sensor detects nothing)
imageshack.com/a/img922/9409/wRazSO.jpg (sensor detects the train)
imageshack.com/a/img924/2663/06S9nL.jpg (overview)
imageshack.com/a/img922/8052/wFOJyT.jpg (overview)
imageshack.com/a/img922/1108/gcyagN.jpg (code)
Can you tell me what I do wrong?
+Niels Albrechts Hi! Your code looks identical to mine. Have you opened the Serial Monitor and confirmed that your sensor reads below 500 when the train is detected?
Hi!
Yes I have opened the serial monitor and there are no data in the monitor but the green light in the sensor switches on and off correctly
Sorry, there is data in the serial monitor, but only 0.
Niels Albrechts
Something's not right there. Send this little sketch to your arduino:
int LDR = 0; //analogue input pin
int LDRValue = 0;
void setup() {
Serial.begin(9600); }
void loop() {
LDRValue = analogRead(LDR);
Serial.println(LDRValue);
delay(100); }
Connect the light sensor, and make sure you have readings between 0 and 1023. If you only have 0, then you have not connected the light sensor correctly (i.e wrong analog input pin, wrong wires, no power etc).
+Arduino Lego Trains
That tests works correctly. Normally the serial monitor gives a value between 27 and 31. When the sensor detect my finger the serial monitor gives a value of 1023.
Haha, gold!
Why does nobody care about the accident? With the CAT?! I wanted this cat so bad when I was a kid!
So moral of this video: You need to spot your cat, use ultrasonic or so cause other times it's bad! :) Meow.
Video start reminds me of: ua-cam.com/video/IJNR2EpS0jw/v-deo.html
any idea how could i use the light sensor as an anti collision?
Sure! Check out tutorial #6
I have trouble implementing the sensor infront of the train to make it stop when there is an obstacle.i need help:(using infared sensor
For infrared sensors you need two LEDs; an infrared LED and an infrared sensor (photoresistor). I used these in Tutorial 8 (ua-cam.com/video/JKjcNlPMSNc/v-deo.html), so check out the code there.